apredis

package
v0.0.0-...-6d899f1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MutexIsErrNotObtained

func MutexIsErrNotObtained(err error) bool

func Ping

func Ping(ctx context.Context, c Client) bool

Types

type Client

type Client interface {
	v9.Cmdable
	WithTimeout(timeout time.Duration) *v9.Client
	Conn() *v9.Conn
	Do(ctx context.Context, args ...interface{}) *v9.Cmd
	Process(ctx context.Context, cmd v9.Cmder) error
	Options() *v9.Options
	PoolStats() *v9.PoolStats
	Pipelined(ctx context.Context, fn func(v9.Pipeliner) error) ([]v9.Cmder, error)
	Pipeline() v9.Pipeliner
	TxPipelined(ctx context.Context, fn func(v9.Pipeliner) error) ([]v9.Cmder, error)
	TxPipeline() v9.Pipeliner
	Subscribe(ctx context.Context, channels ...string) *v9.PubSub
	PSubscribe(ctx context.Context, channels ...string) *v9.PubSub
	SSubscribe(ctx context.Context, channels ...string) *v9.PubSub
	Watch(ctx context.Context, fn func(*v9.Tx) error, keys ...string) error

	AddHook(v9.Hook)
	Close() error
}

func MustApplyTestConfig

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

func MustApplyTestConfigWithServer

func MustApplyTestConfigWithServer(cfg config.C) (config.C, Client, *miniredis.Miniredis)

MustApplyTestConfigWithServer is like MustApplyTestConfig but also returns the underlying miniredis server, allowing tests to call FastForward to advance time for TTL expiry.

func NewForRoot

func NewForRoot(ctx context.Context, root *config.Root, opts ...Option) (Client, error)

NewForRoot creates a new redis client from the specified configuration. The type of the client returned will be determined by the configuration. Optional Options enable telemetry instrumentation; without them the returned client is a plain, uninstrumented redis.Client identical to the historic behaviour.

func NewMiniredis

func NewMiniredis(redisConfig *config.RedisMiniredis, opts ...Option) (Client, error)

NewMiniredis creates a new redis connection to a miniredis instance.

Parameters:

  • redisConfig: the configuration for the miniredis instance
  • opts: optional functional options (e.g. WithTelemetry) for instrumenting the client with OTel tracing and / or metrics

func NewRedis

func NewRedis(ctx context.Context, redisConfig *config.RedisReal, opts ...Option) (Client, error)

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

Parameters:

  • redisConfig: the configuration for the Redis instance
  • opts: optional functional options (e.g. WithTelemetry) for instrumenting the client with OTel tracing and / or metrics

type Mutex

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

func NewMutex

func NewMutex(r Client, key string, options ...MutexOption) Mutex

NewMutex creates a new mutex. Unless options are specified this mutex will not retry to obtain the lock. The default lock time is 1 minute.

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 Option

type Option func(*telemetryOpts)

Option configures redis client construction. WithTelemetry is currently the only option; the functional-options shape keeps the constructor signatures non-breaking for existing callers (e.g. test_config.go) that don't need telemetry.

func WithTelemetry

func WithTelemetry(providers *aptelemetry.Providers, cfg *sconfig.Telemetry) Option

WithTelemetry causes the constructed redis client to be instrumented with OTel spans + metrics via the redis/go-redis redisotel contrib. When providers is nil or in no-op mode, or when both trace and metric signals are off in cfg, this is silently inert and a plain client is returned.

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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