redis

package
v0.7.13 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrLockAcquire is returned when the lock cannot be acquired.
	ErrLockAcquire = errors.New("failed to acquire distributed lock")
)

Functions

func ParseURL

func ParseURL(url string) (*backend.Options, error)

ParseURL parses a redis connection string.

Types

type Locker

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

Locker implements ports.DistributedLocker using Redis.

func NewLocker

func NewLocker(client *backend.Client, prefix string) *Locker

NewLocker creates a new Redis locker.

func (*Locker) Lock

func (l *Locker) Lock(ctx context.Context, key string, ttl time.Duration) (ports.UnlockFunc, error)

Lock acquires a distributed lock for the given key using Redis SET NX PX.

type Option

type Option func(*Store)

func WithPrefix

func WithPrefix(prefix string) Option

WithPrefix sets the key prefix for sessions.

func WithTTL

func WithTTL(ttl time.Duration) Option

WithTTL sets the expiration for sessions.

type Store

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

Store implements ports.StateStore using Redis.

func New

func New(address, password string, db int, opts ...Option) *Store

New creates a new Redis store with options.

func NewFromClient

func NewFromClient(client *backend.Client, opts ...Option) *Store

NewFromClient creates a new Redis store from an existing client.

func (*Store) Client

func (s *Store) Client() *backend.Client

Client returns the underlying Redis client.

func (*Store) Close

func (s *Store) Close() error

Close closes the redis client.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, sessionID string) error

Delete removes the session.

func (*Store) List

func (s *Store) List(ctx context.Context) ([]string, error)

List returns active sessions by scanning keys. Updated to use ZSET lazy cleanup.

func (*Store) Load

func (s *Store) Load(ctx context.Context, sessionID string) (*domain.State, error)

Load retrieves the state from Redis.

func (*Store) Save

func (s *Store) Save(ctx context.Context, sessionID string, state *domain.State) error

Save persists the state to Redis.

Jump to

Keyboard shortcuts

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