redis

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lock

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

Lock implements DistributedLock using Redis SETNX with TTL. It uses a unique owner ID to prevent accidental release by other instances.

func NewLock

func NewLock(client *redis.Client) *Lock

NewLock creates a new Redis-backed distributed lock. The owner ID is automatically generated to uniquely identify this instance.

func (*Lock) Acquire

func (l *Lock) Acquire(ctx context.Context, name string, ttl time.Duration) (bool, error)

Acquire attempts to acquire a named lock with the given TTL. Uses Redis SETNX (SET if Not eXists) for atomic lock acquisition. Returns true if acquired, false if already held by another instance.

func (*Lock) Extend

func (l *Lock) Extend(ctx context.Context, name string, ttl time.Duration) error

Extend extends the TTL of a currently held lock. Returns error if the lock is not held by this instance.

func (*Lock) OwnerID

func (l *Lock) OwnerID() string

OwnerID returns the unique identifier for this lock instance. Useful for debugging and logging.

func (*Lock) Ping

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

Ping checks if the Redis backend is healthy.

func (*Lock) Release

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

Release releases a named lock if held by this instance. Uses a Lua script to atomically check ownership and delete. Safe to call even if the lock is not held or has expired.

type SessionStore

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

SessionStore implements driven.SessionStore using Redis Sessions use Redis TTL for automatic expiration

func NewSessionStore

func NewSessionStore(client *redis.Client) *SessionStore

NewSessionStore creates a new Redis-backed SessionStore

func (*SessionStore) Delete

func (s *SessionStore) Delete(ctx context.Context, id string) error

Delete deletes a session

func (*SessionStore) DeleteByToken

func (s *SessionStore) DeleteByToken(ctx context.Context, token string) error

DeleteByToken deletes a session by token

func (*SessionStore) DeleteByUser

func (s *SessionStore) DeleteByUser(ctx context.Context, userID string) error

DeleteByUser deletes all sessions for a user (logout everywhere)

func (*SessionStore) Get

func (s *SessionStore) Get(ctx context.Context, id string) (*domain.Session, error)

Get retrieves a session by ID

func (*SessionStore) GetByRefreshToken

func (s *SessionStore) GetByRefreshToken(ctx context.Context, refreshToken string) (*domain.Session, error)

GetByRefreshToken retrieves a session by refresh token value

func (*SessionStore) GetByToken

func (s *SessionStore) GetByToken(ctx context.Context, token string) (*domain.Session, error)

GetByToken retrieves a session by token value

func (*SessionStore) ListByUser

func (s *SessionStore) ListByUser(ctx context.Context, userID string) ([]*domain.Session, error)

ListByUser lists all active sessions for a user

func (*SessionStore) Save

func (s *SessionStore) Save(ctx context.Context, session *domain.Session) error

Save stores a session with TTL based on ExpiresAt

Jump to

Keyboard shortcuts

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