Documentation
¶
Index ¶
- Constants
- func AllSameSlot(keys ...string) bool
- func ClusterLane() bool
- func CreateKey(keyParts ...string) string
- func GetLockKey(key string) string
- func HashSlot(key string) uint16
- func HashTag(key string) string
- func SameSlot(key string) string
- func SetupContainerInstance(t *testing.T) redis.UniversalClient
- func SetupInstance(t *testing.T) redis.UniversalClient
- type Lock
- type Locker
- type NoopLock
- type NoopLocker
- type RedisLocker
Constants ¶
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.
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 ¶
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 GetLockKey ¶
func HashTag ¶
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 ¶
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 Locker ¶
type Locker interface {
Obtain(ctx context.Context, key string, ttl time.Duration, opts *redislock.Options) (Lock, error)
}
Locker abstracts distributed lock acquisition.