Documentation
¶
Index ¶
- func MutexIsErrNotObtained(err error) bool
- func Ping(ctx context.Context, c Client) bool
- type Client
- func MustApplyTestConfig(cfg config.C) (config.C, Client)
- func MustApplyTestConfigWithServer(cfg config.C) (config.C, Client, *miniredis.Miniredis)
- func NewForRoot(ctx context.Context, root *config.Root, opts ...Option) (Client, error)
- func NewMiniredis(redisConfig *config.RedisMiniredis, opts ...Option) (Client, error)
- func NewRedis(ctx context.Context, redisConfig *config.RedisReal, opts ...Option) (Client, error)
- type Mutex
- type MutexOption
- func MutexOptionDetailedLockMetadata() MutexOption
- func MutexOptionLockFor(d time.Duration) MutexOption
- func MutexOptionLockMetadata(metadata string) MutexOption
- func MutexOptionLockToken(token string) MutexOption
- func MutexOptionNoRetry() MutexOption
- func MutexOptionRetryExponentialBackoff(min, max time.Duration) MutexOption
- func MutexOptionRetryFor(d time.Duration) MutexOption
- func MutexOptionRetryForExponentialBackoff(tries int, min, max time.Duration) MutexOption
- func MutexOptionRetryForLinearBackoff(tries int, backoff time.Duration) MutexOption
- func MutexOptionRetryLinearBackoff(backoff time.Duration) MutexOption
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MutexIsErrNotObtained ¶
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 MustApplyTestConfigWithServer ¶
MustApplyTestConfigWithServer is like MustApplyTestConfig but also returns the underlying miniredis server, allowing tests to call FastForward to advance time for TTL expiry.
func NewForRoot ¶
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
type Mutex ¶
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.