redistore.v1: Index | Examples | Files

package redistore

import ""

Package redistore is a session store backend for gorilla/sessions



Package Files

doc.go redistore.go

type GobSerializer Uses

type GobSerializer struct{}

GobSerializer uses gob package to encode the session map

func (GobSerializer) Deserialize Uses

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

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

func (GobSerializer) Serialize Uses

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

Serialize using gob

type JSONSerializer Uses

type JSONSerializer struct{}

JSONSerializer encode the session map to JSON.

func (JSONSerializer) Deserialize Uses

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

Deserialize back to map[string]interface{}

func (JSONSerializer) Serialize Uses

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

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

type RediStore Uses

type RediStore struct {
    Pool          *redis.Pool
    Codecs        []securecookie.Codec
    Options       *sessions.Options // default configuration
    DefaultMaxAge int               // default Redis TTL for a MaxAge == 0 session
    // contains filtered or unexported fields

RediStore stores sessions in a redis backend.


// RedisStore
store, err := NewRediStore(10, "tcp", ":6379", "", []byte("secret-key"))
if err != nil {
defer store.Close()

func NewRediStore Uses

func NewRediStore(size int, network, address, password string, keyPairs ...[]byte) (*RediStore, error)

NewRediStore returns a new RediStore. size: maximum number of idle connections.

func NewRediStoreWithDB Uses

func NewRediStoreWithDB(size int, network, address, password, DB string, keyPairs ...[]byte) (*RediStore, error)

NewRediStoreWithDB - like NewRedisStore but accepts `DB` parameter to select redis DB instead of using the default one ("0")

func NewRediStoreWithPool Uses

func NewRediStoreWithPool(pool *redis.Pool, keyPairs ...[]byte) (*RediStore, error)

NewRediStoreWithPool instantiates a RediStore with a *redis.Pool passed in.

func (*RediStore) Close Uses

func (s *RediStore) Close() error

Close closes the underlying *redis.Pool

func (*RediStore) Delete Uses

func (s *RediStore) Delete(r *http.Request, w http.ResponseWriter, session *sessions.Session) error

Delete removes the session from redis, and sets the cookie to expire.

WARNING: This method should be considered deprecated since it is not exposed via the gorilla/sessions interface. Set session.Options.MaxAge = -1 and call Save instead. - July 18th, 2013

func (*RediStore) Get Uses

func (s *RediStore) Get(r *http.Request, name string) (*sessions.Session, error)

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

See gorilla/sessions FilesystemStore.Get().

func (*RediStore) New Uses

func (s *RediStore) New(r *http.Request, name string) (*sessions.Session, error)

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

See gorilla/sessions FilesystemStore.New().

func (*RediStore) Save Uses

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

Save adds a single session to the response.

func (*RediStore) SetKeyPrefix Uses

func (s *RediStore) SetKeyPrefix(p string)

SetKeyPrefix set the prefix

func (*RediStore) SetMaxAge Uses

func (s *RediStore) 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

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 (*RediStore) SetMaxLength Uses

func (s *RediStore) SetMaxLength(l int)

SetMaxLength sets RediStore.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 RediStore is 4096. Redis allows for max. value sizes of up to 512MB ( Default: 4096,

func (*RediStore) SetSerializer Uses

func (s *RediStore) SetSerializer(ss SessionSerializer)

SetSerializer sets the serializer

type SessionSerializer Uses

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

SessionSerializer provides an interface hook for alternative serializers

Package redistore imports 12 packages (graph) and is imported by 21 packages. Updated 2019-07-28. Refresh now. Tools for package owners.