redistore
packagemoduleThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
README¶
redistore
A session store backendforgorilla/sessions -src.
The redistore project is a fork ofredistore.The purpose of this fork is to replace theredigowithgo-redis as the driver of redis store.
Requirements
Depends on thego-redis Redis library.
Installation
go get -u github.com/no-src/redistoreDocumentation
Available onpkg.go.dev.
Seehttps://github.com/gorilla/sessions for full documentation on underlying interface.
Example
// Fetch new store.store, err := NewRediStore(10, "tcp", ":6379", "", []byte("secret-key"))if err != nil {panic(err)}defer store.Close()// Get a session.session, err = store.Get(req, "session-key")if err != nil {log.Error(err.Error())}// Add a value.session.Values["foo"] = "bar"// Save.if err = sessions.Save(req, rsp); err != nil {t.Fatalf("Error saving session: %v", err)}// Delete session.session.Options.MaxAge = -1if err = sessions.Save(req, rsp); err != nil {t.Fatalf("Error saving session: %v", err)}// Change session storage configuration for MaxAge = 10 days.store.SetMaxAge(10 * 24 * 3600)
Documentation¶
Index¶
- type GobSerializer
- type JSONSerializer
- type RediStore
- func NewRediStore(poolSize int, network, address, password string, keyPairs ...[]byte) (*RediStore, error)
- func NewRediStoreWithClient(client *redis.Client, keyPairs ...[]byte) (*RediStore, error)
- func NewRediStoreWithDB(poolSize int, network, address, password string, db int, keyPairs ...[]byte) (*RediStore, error)
- func (s *RediStore) Close() error
- func (s *RediStore) Delete(r *http.Request, w http.ResponseWriter, session *sessions.Session) error
- func (s *RediStore) Get(r *http.Request, name string) (*sessions.Session, error)
- func (s *RediStore) New(r *http.Request, name string) (*sessions.Session, error)
- func (s *RediStore) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error
- func (s *RediStore) SetKeyPrefix(p string)
- func (s *RediStore) SetMaxAge(v int)
- func (s *RediStore) SetMaxLength(l int)
- func (s *RediStore) SetSerializer(ss SessionSerializer)
- type SessionSerializer
Examples¶
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
This section is empty.
Types¶
typeGobSerializer¶
type GobSerializer struct{}GobSerializer uses gob package to encode the session map
func (GobSerializer)Deserialize¶
func (sGobSerializer) Deserialize(d []byte, ss *sessions.Session)error
Deserialize back to map[interface{}]interface{}
typeJSONSerializer¶
type JSONSerializer struct{}JSONSerializer encode the session map to JSON.
func (JSONSerializer)Deserialize¶
func (sJSONSerializer) Deserialize(d []byte, ss *sessions.Session)error
Deserialize back to map[string]interface{}
typeRediStore¶
type RediStore struct {Client *redis.ClientCodecs []securecookie.CodecOptions *sessions.Options// default configurationDefaultMaxAgeint// default Redis TTL for a MaxAge == 0 session// contains filtered or unexported fields}RediStore stores sessions in a redis backend.
Example¶
// RedisStorestore, err := NewRediStore(10, "tcp", ":6379", "", []byte("secret-key"))if err != nil {panic(err)}defer store.Close()funcNewRediStore¶
func NewRediStore(poolSizeint, network, address, passwordstring, keyPairs ...[]byte) (*RediStore,error)
NewRediStore returns a new RediStore.size: maximum number of idle connections.
funcNewRediStoreWithClient¶
NewRediStoreWithClient instantiates a RediStore with a *redis.Client passed in.
funcNewRediStoreWithDB¶
func NewRediStoreWithDB(poolSizeint, network, address, passwordstring, dbint, keyPairs ...[]byte) (*RediStore,error)
NewRediStoreWithDB - like NewRedisStore but accepts `db` parameter to selectredis DB instead of using the default one (0)
func (*RediStore)Delete¶
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¶
Get returns a session for the given name after adding it to the registry.
See gorilla/sessions FilesystemStore.Get().
func (*RediStore)New¶
New returns a session for the given name without adding it to the registry.
See gorilla/sessions FilesystemStore.New().
func (*RediStore)SetMaxAge¶
SetMaxAge restricts the maximum age, in seconds, of the session recordboth 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
https://pkg.go.dev/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 shoulduse this function to change `MaxAge` value.
func (*RediStore)SetMaxLength¶
SetMaxLength sets RediStore.maxLength if the `l` argument is greater or equal 0maxLength 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 (http://redis.io/topics/data-types)Default: 4096,
func (*RediStore)SetSerializer¶
func (s *RediStore) SetSerializer(ssSessionSerializer)
SetSerializer sets the serializer