redis

package
v0.0.0-...-7d40f8e Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MutexIsErrNotObtained

func MutexIsErrNotObtained(err error) bool

Types

type Mutex

type Mutex interface {
	Lock(context.Context) error
	Extend(context.Context, time.Duration) error
	Unlock(context.Context) error
}

type MutexOption

type MutexOption func(m *mutex)

func MutexOptionDetailedLockMetadata

func MutexOptionDetailedLockMetadata() MutexOption

MutexOptionDetailedLockMetadata applies json metadata to the lock about the host, process, etc that acquired the lock

func MutexOptionLockFor

func MutexOptionLockFor(d time.Duration) MutexOption

MutexOptionLockFor sets the initial lock duration for the mutex. If unspecified, the default initial lock duration is one minute. This duration can be extended by calling Extend(...) on the mutex once it's acquired.

func MutexOptionLockMetadata

func MutexOptionLockMetadata(metadata string) MutexOption

MutexOptionLockMetadata appends additional data to the value used to obtain the lock in redis for debugging purposes.

func MutexOptionLockToken

func MutexOptionLockToken(token string) MutexOption

MutexOptionLockToken sets the token value used with the key when obtaining the lock in Redis. Setting this value explicitly allows you to control how the lock is inspectable in the redis data. By default, a random value is used. If you set this value, you need to be careful that you understand how you expect the lock to behave across processes and within the same process. For debugging, setting metadata as an appended value on the lock value may be a better option.

func MutexOptionNoRetry

func MutexOptionNoRetry() MutexOption

func MutexOptionRetryExponentialBackoff

func MutexOptionRetryExponentialBackoff(min, max time.Duration) MutexOption

func MutexOptionRetryFor

func MutexOptionRetryFor(d time.Duration) MutexOption

MutexOptionRetryFor sets how long the mutex will attempt to retry for a lock. This must be combined with a retry strategy or the default MutexOptionNoRetry() will prevent retries.

func MutexOptionRetryForExponentialBackoff

func MutexOptionRetryForExponentialBackoff(tries int, min, max time.Duration) MutexOption

func MutexOptionRetryForLinearBackoff

func MutexOptionRetryForLinearBackoff(tries int, backoff time.Duration) MutexOption

func MutexOptionRetryLinearBackoff

func MutexOptionRetryLinearBackoff(backoff time.Duration) MutexOption

type R

type R interface {
	Ping(ctx context.Context) bool
	Close() error
	Client() *redis.Client
	NewMutex(key string, options ...MutexOption) Mutex
}

func MustApplyTestConfig

func MustApplyTestConfig(cfg config.C) (config.C, R)

func New

func New(ctx context.Context, c config.C, logger *slog.Logger) (R, error)

New creates a new database connection from the specified configuration. The type of the database returned will be determined by the configuration.

func NewForRoot

func NewForRoot(ctx context.Context, root *config.Root, logger *slog.Logger) (R, error)

NewForRoot creates a new database connection from the specified configuration. The type of the database returned will be determined by the configuration. Same as NewConnection.

func NewMiniredis

func NewMiniredis(redisConfig *config.RedisMiniredis, secretKey config.KeyData, logger *slog.Logger) (R, error)

NewMiniredis creates a new database connection to a SQLite database.

Parameters: - redisConfig: the configuration for the SQLite database - secretKey: the AES key used to secure cursors

func NewRedis

func NewRedis(ctx context.Context, redisConfig *config.RedisReal, secretKey config.KeyData, logger *slog.Logger) (R, error)

NewRedis creates a new redis connection to a real redis instance.

Parameters: - redisConfig: the configuration for the Redis instance - secretKey: the AES key used to secure cursors

Jump to

Keyboard shortcuts

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