redis

package
v7.0.0-...-1c7ecba Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const LockSuffix = "lock"

Variables

This section is empty.

Functions

func NewLock

func NewLock(client redis.Cmdable, key string) sessions.Lock

NewLock instantiate a new lock instance. This will not yet apply a lock on Redis side. For that you have to call Obtain(ctx context.Context, expiration time.Duration)

func NewRedisSessionStore

func NewRedisSessionStore(opts *options.SessionOptions, cookieOpts *options.Cookie) (sessions.SessionStore, error)

NewRedisSessionStore initialises a new instance of the SessionStore and wraps it in a persistence.Manager

Types

type Client

type Client interface {
	Get(ctx context.Context, key string) ([]byte, error)
	Lock(key string) sessions.Lock
	Set(ctx context.Context, key string, value []byte, expiration time.Duration) error
	Del(ctx context.Context, key string) error
	Ping(ctx context.Context) error
}

Client is wrapper interface for redis.Client and redis.ClusterClient.

func NewRedisClient

func NewRedisClient(opts options.RedisStoreOptions) (Client, error)

NewRedisClient makes a redis.Client (either standalone, sentinel aware, or redis cluster)

type Lock

type Lock struct {
	// contains filtered or unexported fields
}

func (*Lock) Obtain

func (l *Lock) Obtain(ctx context.Context, expiration time.Duration) error

Obtain obtains a distributed lock on Redis for the configured key.

func (*Lock) Peek

func (l *Lock) Peek(ctx context.Context) (bool, error)

Peek returns true, if the lock is still applied.

func (*Lock) Refresh

func (l *Lock) Refresh(ctx context.Context, expiration time.Duration) error

Refresh refreshes an already existing lock.

func (*Lock) Release

func (l *Lock) Release(ctx context.Context) error

Release releases the lock on Redis side.

type SessionStore

type SessionStore struct {
	Client Client
}

SessionStore is an implementation of the persistence.Store interface that stores sessions in redis

func (*SessionStore) Clear

func (store *SessionStore) Clear(ctx context.Context, key string) error

Clear clears any saved session information for a given persistence cookie from redis, and then clears the session

func (*SessionStore) Load

func (store *SessionStore) Load(ctx context.Context, key string) ([]byte, error)

Load reads sessions.SessionState information from a persistence cookie within the HTTP request object

func (*SessionStore) Lock

func (store *SessionStore) Lock(key string) sessions.Lock

Lock creates a lock object for sessions.SessionState

func (*SessionStore) Save

func (store *SessionStore) Save(ctx context.Context, key string, value []byte, exp time.Duration) error

Save takes a sessions.SessionState and stores the information from it to redis, and adds a new persistence cookie on the HTTP response writer

func (*SessionStore) VerifyConnection

func (store *SessionStore) VerifyConnection(ctx context.Context) error

VerifyConnection verifies the redis connection is valid and the server is responsive

Jump to

Keyboard shortcuts

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