redis_utils

package
v0.0.0-...-86cb503 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 16 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const EnvTestClusterURL = "REDIS_TEST_CLUSTER_URL"

EnvTestClusterURL names the environment variable carrying the redis:// URL of a cluster-mode server. When it is set, the tests share that server instead, so a command whose keys span slots fails as it does on a cluster.

View Source
const EnvTestDatabaseURL = "REDIS_TEST_DATABASE_URL"

EnvTestDatabaseURL names the environment variable carrying the redis:// URL of the Redis server the tests share.

Variables

This section is empty.

Functions

func AllSameSlot

func AllSameSlot(keys ...string) bool

AllSameSlot reports whether all keys map to one cluster slot, as a multi-key command or a script's KEYS must.

func ClusterLane

func ClusterLane() bool

ClusterLane reports whether the tests share the server EnvTestClusterURL names.

func CreateKey

func CreateKey(keyParts ...string) string

CreateKey joins key parts with the standard Redis key separator.

func GetLockKey

func GetLockKey(key string) string

func HashSlot

func HashSlot(key string) uint16

HashSlot returns the cluster slot of key, as CLUSTER KEYSLOT does.

func HashTag

func HashTag(key string) string

HashTag returns the part of key Redis Cluster hashes: the text between the first "{" and the first "}" after it, or the whole key when that text is empty or missing.

func SameSlot

func SameSlot(key string) string

SameSlot wraps a key in curly braces to force Redis Cluster hash slot co-location. This is needed to use Lua scripts, MGET, and transactions across multiple keys.

func SetupContainerInstance

func SetupContainerInstance(t *testing.T) redis.UniversalClient

SetupContainerInstance starts a Redis container of the test's own, for tests whose commands SetupInstance cannot isolate.

func SetupInstance

func SetupInstance(t *testing.T) redis.UniversalClient

SetupInstance returns a client on the server the tests share whose keys are namespaced to the test, so parallel tests share the server without seeing each other's keys. The server is the one EnvTestClusterURL names when it is set, else the one EnvTestDatabaseURL names. The keys are removed and the client closed when the test ends.

Commands that carry no key are sent unchanged and are not isolated: SCAN, KEYS, FLUSHDB and pub/sub. A test that depends on them uses SetupContainerInstance.

Types

type Lock

type Lock interface {
	Release(ctx context.Context) error
}

Lock abstracts a held distributed lock.

type Locker

type Locker interface {
	Obtain(ctx context.Context, key string, ttl time.Duration, opts *redislock.Options) (Lock, error)
}

Locker abstracts distributed lock acquisition.

type NoopLock

type NoopLock struct{}

NoopLock is a lock that does nothing on release.

func (NoopLock) Release

func (NoopLock) Release(context.Context) error

type NoopLocker

type NoopLocker struct{}

NoopLocker always succeeds without acquiring any lock.

func (NoopLocker) Obtain

type RedisLocker

type RedisLocker struct {
	Client *redislock.Client
}

RedisLocker wraps redislock.Client.

func (*RedisLocker) Obtain

func (l *RedisLocker) Obtain(ctx context.Context, key string, ttl time.Duration, opts *redislock.Options) (Lock, error)

Jump to

Keyboard shortcuts

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