redis

package
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2023 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetKeyPrefix

func SetKeyPrefix(s Store, prefix string) error

SetKeyPrefix sets the key prefix in the redis database.

Types

type GobSerializer

type GobSerializer struct{}

GobSerializer uses gob package to encode the session map

func (GobSerializer) Deserialize

func (s GobSerializer) Deserialize(d []byte, ss *gsessions.Session) error

Deserialize back to map[interface{}]interface{}

func (GobSerializer) Serialize

func (s GobSerializer) Serialize(ss *gsessions.Session) ([]byte, error)

Serialize using gob

type JSONSerializer

type JSONSerializer struct{}

JSONSerializer encode the session map to JSON.

func (JSONSerializer) Deserialize

func (s JSONSerializer) Deserialize(d []byte, ss *gsessions.Session) error

Deserialize back to map[string]interface{}

func (JSONSerializer) Serialize

func (s JSONSerializer) Serialize(ss *gsessions.Session) ([]byte, error)

Serialize to JSON. Will err if there are unmarshalable key values

type RedisStore

type RedisStore struct {
	Client        *redis.Client
	Codecs        []securecookie.Codec
	Preferences   *gsessions.Options // default configuration
	DefaultMaxAge int                // default Redis TTL for a MaxAge == 0 session
	// contains filtered or unexported fields
}

RedisStore stores sessions in a redis backend.

func GetRedisStore

func GetRedisStore(s Store) (err error, redisStore *RedisStore)

GetRedisStore get the actual woking store.

func NewRedisStore

func NewRedisStore(client *redis.Client, keyPairs ...[]byte) (*RedisStore, error)

NewRedisStore instantiates a RedisStore with a *redis.Client passed in.

func (*RedisStore) Get

func (s *RedisStore) Get(r *http.Request, name string) (*gsessions.Session, error)

Get returns a session for the given name after adding it to the registry.

See gorilla/sessions FilesystemStore.Get().

func (*RedisStore) New

func (s *RedisStore) New(r *http.Request, name string) (*gsessions.Session, error)

New returns a session for the given name without adding it to the registry.

See gorilla/sessions FilesystemStore.New().

func (*RedisStore) Options

func (s *RedisStore) Options(options sessions.Options)

func (*RedisStore) Save

func (s *RedisStore) Save(r *http.Request, w http.ResponseWriter, session *gsessions.Session) error

Save adds a single session to the response.

func (*RedisStore) SetKeyPrefix

func (s *RedisStore) SetKeyPrefix(p string)

SetKeyPrefix set the prefix

func (*RedisStore) SetMaxAge

func (s *RedisStore) SetMaxAge(v int)

SetMaxAge restricts the maximum age, in seconds, of the session record both in database and a browser. This is to change session storage configuration. If you want just to remove session use your session `s` object and change it's `Options.MaxAge` to -1, as specified in

http://godoc.org/github.com/gorilla/sessions#Options

Default is the one provided by this package value - `sessionExpire`. Set it to 0 for no restriction. Because we use `MaxAge` also in SecureCookie crypting algorithm you should use this function to change `MaxAge` value.

func (*RedisStore) SetMaxLength

func (s *RedisStore) SetMaxLength(l int)

SetMaxLength sets RedisStore.maxLength if the `l` argument is greater or equal 0 maxLength restricts the maximum length of new sessions to l. If l is 0 there is no limit to the size of a session, use with caution. The default for a new RedisStore is 4096. Redis allows for max. value sizes of up to 512MB (http://redis.io/topics/data-types) Default: 4096,

func (*RedisStore) SetSerializer

func (s *RedisStore) SetSerializer(ss SessionSerializer)

SetSerializer sets the serializer

type SessionSerializer

type SessionSerializer interface {
	Deserialize(d []byte, ss *gsessions.Session) error
	Serialize(ss *gsessions.Session) ([]byte, error)
}

SessionSerializer provides an interface hook for alternative serializers

type Store

type Store interface {
	gsessions.Store
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL