Documentation ¶
Index ¶
- Constants
- Variables
- type ClusterOptions
- type Config
- type Database
- func (db *Database) Acquire(sid string, expires time.Duration) sessions.LifeTime
- func (db *Database) Clear(sid string) error
- func (db *Database) Close() error
- func (db *Database) Decode(sid, key string, outPtr interface{}) error
- func (db *Database) Delete(sid string, key string) (deleted bool)
- func (db *Database) Get(sid string, key string) (value interface{})
- func (db *Database) Len(sid string) int
- func (db *Database) OnUpdateExpiration(sid string, newExpires time.Duration) error
- func (db *Database) Release(sid string) error
- func (db *Database) Set(sid string, key string, value interface{}, _ time.Duration, _ bool) error
- func (db *Database) SetLogger(logger *golog.Logger)
- func (db *Database) Visit(sid string, cb func(key string, value interface{})) error
- type Driver
- type GoRedisClient
- type GoRedisDriver
- func (r *GoRedisDriver) CloseConnection() error
- func (r *GoRedisDriver) Connect(c Config) error
- func (r *GoRedisDriver) Delete(sid, key string) error
- func (r *GoRedisDriver) Exists(sid string) bool
- func (r *GoRedisDriver) Get(sid, key string) (interface{}, error)
- func (r *GoRedisDriver) GetAll(sid string) (map[string]string, error)
- func (r *GoRedisDriver) GetKeys(sid string) ([]string, error)
- func (r *GoRedisDriver) Len(sid string) int
- func (r *GoRedisDriver) PingPong() (bool, error)
- func (r *GoRedisDriver) Set(sid, key string, value interface{}) error
- func (r *GoRedisDriver) SetClient(goRedisClient GoRedisClient) *GoRedisDriver
- func (r *GoRedisDriver) TTL(sid string) time.Duration
- func (r *GoRedisDriver) UpdateTTL(sid string, newLifetime time.Duration) error
- type Options
Constants ¶
const ( // DefaultRedisNetwork the redis network option, "tcp". DefaultRedisNetwork = "tcp" // DefaultRedisAddr the redis address option, "127.0.0.1:6379". DefaultRedisAddr = "127.0.0.1:6379" // DefaultRedisTimeout the redis idle timeout option, time.Duration(30) * time.Second. DefaultRedisTimeout = time.Duration(30) * time.Second )
const SessionIDKey = "session_id"
SessionIDKey the session ID stored to the redis session itself.
Variables ¶
var ( // ErrRedisClosed an error with message 'redis: already closed' ErrRedisClosed = errors.New("redis: already closed") // ErrKeyNotFound a type of error of non-existing redis keys. // The producers(the library) of this error will dynamically wrap this error(fmt.Errorf) with the key name. // Usage: // if err != nil && errors.Is(err, ErrKeyNotFound) { // [...] // } ErrKeyNotFound = errors.New("key not found") )
Functions ¶
This section is empty.
Types ¶
type ClusterOptions ¶ added in v12.2.0
type ClusterOptions = redis.ClusterOptions
ClusterOptions is just a type alias for the go-redis Cluster Client Options.
type Config ¶
type Config struct { // Network protocol. Defaults to "tcp". Network string // Addr of a single redis server instance. // See "Clusters" field for clusters support. // Defaults to "127.0.0.1:6379". Addr string // Clusters a list of network addresses for clusters. // If not empty "Addr" is ignored and Redis clusters feature is used instead. // Note that this field is ignored when setgging a custom `GoRedisClient`. Clusters []string // Use the specified Username to authenticate the current connection // with one of the connections defined in the ACL list when connecting // to a Redis 6.0 instance, or greater, that is using the Redis ACL system. Username string // Optional password. Must match the password specified in the // requirepass server configuration option (if connecting to a Redis 5.0 instance, or lower), // or the User Password when connecting to a Redis 6.0 instance, or greater, // that is using the Redis ACL system. Password string // If Database is empty "" then no 'SELECT'. Defaults to "". Database string // Maximum number of socket connections. // Default is 10 connections per every CPU as reported by runtime.NumCPU. MaxActive int // Timeout for connect, write and read, defaults to 30 seconds, 0 means no timeout. Timeout time.Duration // Prefix "myprefix-for-this-website". Defaults to "". Prefix string // TLSConfig will cause Dial to perform a TLS handshake using the provided // config. If is nil then no TLS is used. // See https://golang.org/pkg/crypto/tls/#Config TLSConfig *tls.Config // A Driver should support be a go client for redis communication. // It can be set to a custom one or a mock one (for testing). // // Defaults to `GoRedis()`. Driver Driver }
Config the redis configuration used inside sessions
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the default configuration for Redis service.
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database the redis back-end session database for the sessions.
func (*Database) Acquire ¶
Acquire receives a session's lifetime from the database, if the return value is LifeTime{} then the session manager sets the life time based on the expiration duration lives in configuration.
func (*Database) Decode ¶ added in v12.2.0
Decode binds the "outPtr" to the value associated to the provided "key".
func (*Database) OnUpdateExpiration ¶
OnUpdateExpiration will re-set the database's session's entry ttl. https://redis.io/commands/expire#refreshing-expires
func (*Database) Release ¶
Release destroys the session, it clears and removes the session entry, session manager will create a new session ID on the next request after this call.
type Driver ¶
type Driver interface { Connect(c Config) error PingPong() (bool, error) CloseConnection() error Set(sid, key string, value interface{}) error Get(sid, key string) (interface{}, error) Exists(sid string) bool TTL(sid string) time.Duration UpdateTTL(sid string, newLifetime time.Duration) error GetAll(sid string) (map[string]string, error) GetKeys(sid string) ([]string, error) Len(sid string) int Delete(sid, key string) error }
Driver is the interface which each supported redis client should support in order to be used in the redis session database.
type GoRedisClient ¶ added in v12.2.0
GoRedisClient is the interface which both go-redis's Client and Cluster Client implements.
type GoRedisDriver ¶ added in v12.2.0
type GoRedisDriver struct { // Both Client and ClusterClient implements this interface. // Custom one can be directly passed but if so, the // Connect method does nothing (so all connection and client settings are ignored). Client GoRedisClient // Customize any go-redis fields manually // before Connect. ClientOptions Options ClusterOptions ClusterOptions }
GoRedisDriver implements the Sessions Database Driver for the go-redis redis driver. See driver.go file.
func GoRedis ¶ added in v12.2.0
func GoRedis() *GoRedisDriver
GoRedis returns the default Driver for the redis sessions database It's the go-redis client. Learn more at: https://github.com/go-redis/redis.
func (*GoRedisDriver) CloseConnection ¶ added in v12.2.0
func (r *GoRedisDriver) CloseConnection() error
CloseConnection terminates the underline redis connection.
func (*GoRedisDriver) Connect ¶ added in v12.2.0
func (r *GoRedisDriver) Connect(c Config) error
Connect initializes the redis client.
func (*GoRedisDriver) Delete ¶ added in v12.2.0
func (r *GoRedisDriver) Delete(sid, key string) error
Delete removes a value from the redis store.
func (*GoRedisDriver) Exists ¶ added in v12.2.0
func (r *GoRedisDriver) Exists(sid string) bool
Exists reports whether a session exists or not.
func (*GoRedisDriver) Get ¶ added in v12.2.0
func (r *GoRedisDriver) Get(sid, key string) (interface{}, error)
Get returns the associated value of the session's given "key".
func (*GoRedisDriver) GetAll ¶ added in v12.2.0
func (r *GoRedisDriver) GetAll(sid string) (map[string]string, error)
GetAll returns all the key values under the session.
func (*GoRedisDriver) GetKeys ¶ added in v12.2.0
func (r *GoRedisDriver) GetKeys(sid string) ([]string, error)
GetKeys returns all keys under the session.
func (*GoRedisDriver) Len ¶ added in v12.2.0
func (r *GoRedisDriver) Len(sid string) int
Len returns the total length of key-values of the session.
func (*GoRedisDriver) PingPong ¶ added in v12.2.0
func (r *GoRedisDriver) PingPong() (bool, error)
PingPong sends a ping message and reports whether the PONG message received successfully.
func (*GoRedisDriver) Set ¶ added in v12.2.0
func (r *GoRedisDriver) Set(sid, key string, value interface{}) error
Set stores a "value" based on the session's "key". The value should be type of []byte, so unmarshal can happen.
func (*GoRedisDriver) SetClient ¶ added in v12.2.0
func (r *GoRedisDriver) SetClient(goRedisClient GoRedisClient) *GoRedisDriver
SetClient sets an existing go redis client to the sessions redis driver.
Returns itself.