package redisimport ()typeStringCmdableinterface {Append(ctx context.Context, key, value string) *IntCmdDecr(ctx context.Context, key string) *IntCmdDecrBy(ctx context.Context, key string, decrement int64) *IntCmdDelExArgs(ctx context.Context, key string, a DelExArgs) *IntCmdDigest(ctx context.Context, key string) *DigestCmdGet(ctx context.Context, key string) *StringCmdGetRange(ctx context.Context, key string, start, end int64) *StringCmdGetSet(ctx context.Context, key string, value interface{}) *StringCmdGetEx(ctx context.Context, key string, expiration time.Duration) *StringCmdGetDel(ctx context.Context, key string) *StringCmdGetToBuffer(ctx context.Context, key string, buf []byte) *ZeroCopyStringCmdIncr(ctx context.Context, key string) *IntCmdIncrBy(ctx context.Context, key string, value int64) *IntCmdIncrByFloat(ctx context.Context, key string, value float64) *FloatCmdIncrEXInt(ctx context.Context, key string, args IncrEXIntArgs) *IncrEXIntCmdIncrEXFloat(ctx context.Context, key string, args IncrEXFloatArgs) *IncrEXFloatCmdLCS(ctx context.Context, q *LCSQuery) *LCSCmdMGet(ctx context.Context, keys ...string) *SliceCmdMSet(ctx context.Context, values ...interface{}) *StatusCmdMSetNX(ctx context.Context, values ...interface{}) *BoolCmdMSetEX(ctx context.Context, args MSetEXArgs, values ...interface{}) *IntCmdSet(ctx context.Context, key string, value interface{}, expiration time.Duration) *StatusCmdSetArgs(ctx context.Context, key string, value interface{}, a SetArgs) *StatusCmdSetEx(ctx context.Context, key string, value interface{}, expiration time.Duration) *StatusCmdSetFromBuffer(ctx context.Context, key string, buf []byte) *StatusCmdSetIFEQ(ctx context.Context, key string, value interface{}, matchValue interface{}, expiration time.Duration) *StatusCmdSetIFEQGet(ctx context.Context, key string, value interface{}, matchValue interface{}, expiration time.Duration) *StringCmdSetIFNE(ctx context.Context, key string, value interface{}, matchValue interface{}, expiration time.Duration) *StatusCmdSetIFNEGet(ctx context.Context, key string, value interface{}, matchValue interface{}, expiration time.Duration) *StringCmdSetIFDEQ(ctx context.Context, key string, value interface{}, matchDigest uint64, expiration time.Duration) *StatusCmdSetIFDEQGet(ctx context.Context, key string, value interface{}, matchDigest uint64, expiration time.Duration) *StringCmdSetIFDNE(ctx context.Context, key string, value interface{}, matchDigest uint64, expiration time.Duration) *StatusCmdSetIFDNEGet(ctx context.Context, key string, value interface{}, matchDigest uint64, expiration time.Duration) *StringCmdSetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *BoolCmdSetXX(ctx context.Context, key string, value interface{}, expiration time.Duration) *BoolCmdSetRange(ctx context.Context, key string, offset int64, value string) *IntCmdStrLen(ctx context.Context, key string) *IntCmd}func ( cmdable) ( context.Context, , string) *IntCmd { := NewIntCmd(, "append", , ) _ = (, )return}func ( cmdable) ( context.Context, string) *IntCmd { := NewIntCmd(, "decr", ) _ = (, )return}func ( cmdable) ( context.Context, string, int64) *IntCmd { := NewIntCmd(, "decrby", , ) _ = (, )return}// DelExArgs provides arguments for the DelExArgs function.typeDelExArgsstruct {// Mode can be `IFEQ`, `IFNE`, `IFDEQ`, or `IFDNE`. Mode string// MatchValue is used with IFEQ/IFNE modes for compare-and-delete operations. // - IFEQ: only delete if current value equals MatchValue // - IFNE: only delete if current value does not equal MatchValue MatchValue interface{}// MatchDigest is used with IFDEQ/IFDNE modes for digest-based compare-and-delete. // - IFDEQ: only delete if current value's digest equals MatchDigest // - IFDNE: only delete if current value's digest does not equal MatchDigest // // The digest is a uint64 xxh3 hash value. // // For examples of client-side digest generation, see: // example/digest-optimistic-locking/ MatchDigest uint64}// DelExArgs Redis `DELEX key [IFEQ|IFNE|IFDEQ|IFDNE] match-value` command.// Compare-and-delete with flexible conditions.//// Returns the number of keys that were removed (0 or 1).//// NOTE DelExArgs is still experimental// it's signature and behaviour may changefunc ( cmdable) ( context.Context, string, DelExArgs) *IntCmd { := []interface{}{"delex", }if .Mode != "" { = append(, .Mode)// Add match value/digest based on modeswitch .Mode {case"ifeq", "IFEQ", "ifne", "IFNE":if .MatchValue != nil { = append(, .MatchValue) }case"ifdeq", "IFDEQ", "ifdne", "IFDNE":if .MatchDigest != 0 { = append(, fmt.Sprintf("%016x", .MatchDigest)) } } } := NewIntCmd(, ...) _ = (, )return}// Digest returns the xxh3 hash (uint64) of the specified key's value.//// The digest is a 64-bit xxh3 hash that can be used for optimistic locking// with SetIFDEQ, SetIFDNE, and DelExArgs commands.//// For examples of client-side digest generation and usage patterns, see:// example/digest-optimistic-locking///// Redis 8.4+. See https://redis.io/commands/digest///// NOTE Digest is still experimental// it's signature and behaviour may changefunc ( cmdable) ( context.Context, string) *DigestCmd { := NewDigestCmd(, "digest", ) _ = (, )return}// Get Redis `GET key` command. It returns redis.Nil error when key does not exist.func ( cmdable) ( context.Context, string) *StringCmd { := NewStringCmd(, "get", ) _ = (, )return}func ( cmdable) ( context.Context, string, , int64) *StringCmd { := NewStringCmd(, "getrange", , , ) _ = (, )return}// GetSet returns the old value stored at key and sets it to the new value.//// Deprecated: Use SetArgs with Get option instead as of Redis 6.2.0.func ( cmdable) ( context.Context, string, interface{}) *StringCmd { := NewStringCmd(, "getset", , ) _ = (, )return}// GetEx An expiration of zero removes the TTL associated with the key (i.e. GETEX key persist).// Requires Redis >= 6.2.0.func ( cmdable) ( context.Context, string, time.Duration) *StringCmd { := make([]interface{}, 0, 4) = append(, "getex", )if > 0 {ifusePrecise() { = append(, "px", formatMs(, )) } else { = append(, "ex", formatSec(, )) } } elseif == 0 { = append(, "persist") } := NewStringCmd(, ...) _ = (, )return}// GetDel redis-server version >= 6.2.0.func ( cmdable) ( context.Context, string) *StringCmd { := NewStringCmd(, "getdel", ) _ = (, )return}// GetToBuffer executes GET and reads the reply directly into buf, avoiding// the intermediate string allocation that *StringCmd would produce. For values// larger than the connection's read buffer, the payload is read straight from// the socket into buf — effectively zero-copy on the receive path.//// The returned *ZeroCopyStringCmd reports the number of bytes read via Val(),// the populated slice via Bytes() (which is buf[:Val()]), and any error// (including redis.Nil when the key does not exist) via Err(). If buf is too// small to hold the value, Err() returns a "buffer too small" error.//// Nothing is ever written past len(buf). When len(buf) >= value length + 2,// the read takes a fast path that pulls the payload and the protocol's// trailing CRLF in a single socket read, using the two bytes after the// payload as scratch — size buffers with 2 spare bytes to opt in (see// example/zerocopy-buffer).//// This command opts out of automatic retries because partial data from a// failed attempt would already be sitting in the caller's buffer.func ( cmdable) ( context.Context, string, []byte) *ZeroCopyStringCmd { := NewZeroCopyStringCmd(, , "get", ) _ = (, )return}func ( cmdable) ( context.Context, string) *IntCmd { := NewIntCmd(, "incr", ) _ = (, )return}func ( cmdable) ( context.Context, string, int64) *IntCmd { := NewIntCmd(, "incrby", , ) _ = (, )return}func ( cmdable) ( context.Context, string, float64) *FloatCmd { := NewFloatCmd(, "incrbyfloat", , ) _ = (, )return}// IncrEXIntArgs are the arguments to IncrEXInt (the BYINT variant of INCREX).//// If By is zero and HasBy is false, the server increments by 1.// HasLBound/HasUBound gate the optional LBOUND/UBOUND clauses so that 0 is a// valid bound. Expiration is shared with the SET command via ExpirationOption.typeIncrEXIntArgsstruct { By int64 HasBy bool LBound, UBound int64 HasLBound, HasUBound bool// Saturate clamps the result to LBOUND/UBOUND (or LLONG_MAX/MIN when no // explicit bound is given) when the increment would exceed it. Without // this flag, out-of-bounds operations are rejected: the key and TTL are // left unchanged and the reply is [current_value, 0]. Saturate bool// Expiration sets the TTL semantics: EX, PX, EXAT, PXAT, or PERSIST. Expiration *ExpirationOption// ENX applies the expiration only when the key does not already have an // expiration. Requires Expiration to set one of EX/PX/EXAT/PXAT. ENX bool}// IncrEXFloatArgs are the arguments to IncrEXFloat (the BYFLOAT variant of// INCREX). BYFLOAT is always sent — even when By is zero — to keep the// operation in float mode on the server side; omitting BYFLOAT would cause// the server to treat the call as an integer increment by 1.// HasLBound/HasUBound gate the optional LBOUND/UBOUND clauses so that 0 is// a valid bound.typeIncrEXFloatArgsstruct { By float64 LBound, UBound float64 HasLBound, HasUBound bool// Saturate clamps the result to LBOUND/UBOUND (or ±LDBL_MAX when no // explicit bound is given) when the increment would exceed it. Without // this flag, out-of-bounds operations are rejected: the key and TTL are // left unchanged and the reply is [current_value, 0]. Saturate bool Expiration *ExpirationOption ENX bool}// IncrEXInt Redis `INCREX key [BYINT amount] [LBOUND value] [UBOUND value]// [SATURATE] [EX seconds | PX ms | EXAT ts | PXAT ts | PERSIST] [ENX]`// command.//// Atomically increments the integer value stored at key, optionally// constraining the result to a range and applying expiration semantics.// Returns the new value and the increment that was actually applied. When// the increment would exceed LBOUND/UBOUND and SATURATE is not set, the key// and TTL are left unchanged and the reply is [current_value, 0].//// Available since Redis 8.8.// For more information, see https://redis.io/commands/increxfunc ( cmdable) ( context.Context, string, IncrEXIntArgs) *IncrEXIntCmd { := make([]interface{}, 0, 14) = append(, "increx", )if .HasBy { = append(, "byint", .By) }if .HasLBound { = append(, "lbound", .LBound) }if .HasUBound { = append(, "ubound", .UBound) }if .Saturate { = append(, "saturate") } = appendIncrEXTail(, .Expiration, .ENX) := NewIncrEXIntCmd(, ...) _ = (, )return}// IncrEXFloat Redis `INCREX key [BYFLOAT amount] [LBOUND value] [UBOUND value]// [SATURATE] [EX seconds | PX ms | EXAT ts | PXAT ts | PERSIST] [ENX]`// command.//// Available since Redis 8.8.// For more information, see https://redis.io/commands/increxfunc ( cmdable) ( context.Context, string, IncrEXFloatArgs) *IncrEXFloatCmd { := make([]interface{}, 0, 14) = append(, "increx", , "byfloat", .By)if .HasLBound { = append(, "lbound", .LBound) }if .HasUBound { = append(, "ubound", .UBound) }if .Saturate { = append(, "saturate") } = appendIncrEXTail(, .Expiration, .ENX) := NewIncrEXFloatCmd(, ...) _ = (, )return}func appendIncrEXTail( []interface{}, *ExpirationOption, bool) []interface{} {if != nil {switch .Mode {caseEX, PX, EXAT, PXAT: = append(, strings.ToLower(string(.Mode)), .Value)casePERSIST: = append(, "persist") } }if { = append(, "enx") }return}typeSetConditionstringconst (// NX only set the keys and their expiration if none existNXSetCondition = "NX"// XX only set the keys and their expiration if all already existXXSetCondition = "XX")typeExpirationModestringconst (// EX sets expiration in secondsEXExpirationMode = "EX"// PX sets expiration in millisecondsPXExpirationMode = "PX"// EXAT sets expiration as Unix timestamp in secondsEXATExpirationMode = "EXAT"// PXAT sets expiration as Unix timestamp in millisecondsPXATExpirationMode = "PXAT"// KEEPTTL keeps the existing TTLKEEPTTLExpirationMode = "KEEPTTL"// PERSIST removes the existing TTL. Used by INCREX.PERSISTExpirationMode = "PERSIST")typeExpirationOptionstruct { Mode ExpirationMode Value int64}func ( cmdable) ( context.Context, *LCSQuery) *LCSCmd { := NewLCSCmd(, ) _ = (, )return}func ( cmdable) ( context.Context, ...string) *SliceCmd { := make([]interface{}, 1+len()) [0] = "mget"for , := range { [1+] = } := NewSliceCmd(, ...) _ = (, )return}// MSet is like Set but accepts multiple values:// - MSet("key1", "value1", "key2", "value2")// - MSet([]string{"key1", "value1", "key2", "value2"})// - MSet(map[string]interface{}{"key1": "value1", "key2": "value2"})// - MSet(struct), For struct types, see HSet description.func ( cmdable) ( context.Context, ...interface{}) *StatusCmd { := make([]interface{}, 1, 1+len()) [0] = "mset" = appendArgs(, ) := NewStatusCmd(, ...) _ = (, )return}// MSetNX is like SetNX but accepts multiple values:// - MSetNX("key1", "value1", "key2", "value2")// - MSetNX([]string{"key1", "value1", "key2", "value2"})// - MSetNX(map[string]interface{}{"key1": "value1", "key2": "value2"})// - MSetNX(struct), For struct types, see HSet description.func ( cmdable) ( context.Context, ...interface{}) *BoolCmd { := make([]interface{}, 1, 1+len()) [0] = "msetnx" = appendArgs(, ) := NewBoolCmd(, ...) _ = (, )return}typeMSetEXArgsstruct { Condition SetCondition Expiration *ExpirationOption}// MSetEX sets the given keys to their respective values.// This command is an extension of the MSETNX that adds expiration and XX options.// Available since Redis 8.4// Important: When this method is used with Cluster clients, all keys// must be in the same hash slot, otherwise CROSSSLOT error will be returned.// For more information, see https://redis.io/commands/msetexfunc ( cmdable) ( context.Context, MSetEXArgs, ...interface{}) *IntCmd { := appendArgs([]interface{}{}, ) := len() / 2 := make([]interface{}, 0, 2+len()+3) = append(, "msetex", ) = append(, ...)if .Condition != "" { = append(, string(.Condition)) }if .Expiration != nil {switch .Expiration.Mode {caseEX: = append(, "ex", .Expiration.Value)casePX: = append(, "px", .Expiration.Value)caseEXAT: = append(, "exat", .Expiration.Value)casePXAT: = append(, "pxat", .Expiration.Value)caseKEEPTTL: = append(, "keepttl") } } := NewIntCmd(, ...) .SetFirstKeyPos(2) _ = (, )return}// Set Redis `SET key value [expiration]` command.// Use expiration for `SETEx`-like behavior.//// Zero expiration means the key has no expiration time.// KeepTTL is a Redis KEEPTTL option to keep existing TTL, it requires your redis-server version >= 6.0,// otherwise you will receive an error: (error) ERR syntax error.func ( cmdable) ( context.Context, string, interface{}, time.Duration) *StatusCmd { := make([]interface{}, 3, 5) [0] = "set" [1] = [2] = if > 0 {ifusePrecise() { = append(, "px", formatMs(, )) } else { = append(, "ex", formatSec(, )) } } elseif == KeepTTL { = append(, "keepttl") } := NewStatusCmd(, ...) _ = (, )return}// SetArgs provides arguments for the SetArgs function.typeSetArgsstruct {// Mode can be `NX`, `XX`, `IFEQ`, `IFNE`, `IFDEQ`, `IFDNE` or empty. Mode string// MatchValue is used with IFEQ/IFNE modes for compare-and-set operations. // - IFEQ: only set if current value equals MatchValue // - IFNE: only set if current value does not equal MatchValue MatchValue interface{}// MatchDigest is used with IFDEQ/IFDNE modes for digest-based compare-and-set. // - IFDEQ: only set if current value's digest equals MatchDigest // - IFDNE: only set if current value's digest does not equal MatchDigest // // The digest is a uint64 xxh3 hash value. // // For examples of client-side digest generation, see: // example/digest-optimistic-locking/ MatchDigest uint64// Zero `TTL` or `Expiration` means that the key has no expiration time. TTL time.Duration// ExpireAt is sent as EXAT, or as PXAT when it has millisecond precision. ExpireAt time.Time// When Get is true, the command returns the old value stored at key, or nil when key did not exist. Get bool// KeepTTL is a Redis KEEPTTL option to keep existing TTL, it requires your redis-server version >= 6.0, // otherwise you will receive an error: (error) ERR syntax error. KeepTTL bool}// SetArgs supports all the options that the SET command supports.// It is the alternative to the Set function when you want// to have more control over the options.func ( cmdable) ( context.Context, string, interface{}, SetArgs) *StatusCmd { := []interface{}{"set", , }if .KeepTTL { = append(, "keepttl") }if !.ExpireAt.IsZero() {if .ExpireAt.Nanosecond() >= int(time.Millisecond) { = append(, "pxat", .ExpireAt.UnixMilli()) } else { = append(, "exat", .ExpireAt.Unix()) } }if .TTL > 0 {ifusePrecise(.TTL) { = append(, "px", formatMs(, .TTL)) } else { = append(, "ex", formatSec(, .TTL)) } }if .Mode != "" { = append(, .Mode)// Add match value/digest for CAS modesswitch .Mode {case"ifeq", "IFEQ", "ifne", "IFNE":if .MatchValue != nil { = append(, .MatchValue) }case"ifdeq", "IFDEQ", "ifdne", "IFDNE":if .MatchDigest != 0 { = append(, fmt.Sprintf("%016x", .MatchDigest)) } } }if .Get { = append(, "get") } := NewStatusCmd(, ...) _ = (, )return}// SetEx sets the value and expiration of a key.//// Deprecated: Use Set with expiration instead as of Redis 2.6.12.func ( cmdable) ( context.Context, string, interface{}, time.Duration) *StatusCmd { := NewStatusCmd(, "setex", , formatSec(, ), ) _ = (, )return}// SetFromBuffer executes SET writing the value directly from buf. For values// larger than the connection's write buffer, bufio.Writer.Write flushes its// internal buffer (containing the RESP header) and then writes buf straight// to the socket — effectively zero-copy on the send path.//// Expiration is not supported; use Expire separately if a TTL is required.//// Note: SetFromBuffer is exposed for API symmetry with GetToBuffer and is// functionally equivalent to Set(ctx, key, buf, 0) — both dispatch to the// same []byte case in the RESP writer and produce identical bytes on the// wire. The zero-copy property on the send path comes from// bufio.Writer.Write bypassing its internal buffer for large payloads,// which Set([]byte) gets automatically. Prefer SetFromBuffer in code that// also uses GetToBuffer so the buffer-based pattern reads coherently;// otherwise Set(ctx, key, buf, 0) is equally efficient.func ( cmdable) ( context.Context, string, []byte) *StatusCmd { := NewStatusCmd(, "set", , ) _ = (, )return}// SetNX sets the value of a key only if the key does not exist.//// Zero expiration means the key has no expiration time.// KeepTTL is a Redis KEEPTTL option to keep existing TTL, it requires your redis-server version >= 6.0,// otherwise you will receive an error: (error) ERR syntax error.func ( cmdable) ( context.Context, string, interface{}, time.Duration) *BoolCmd {var *BoolCmdswitch {case0: = NewBoolCmd(, "set", , , "nx")caseKeepTTL: = NewBoolCmd(, "set", , , "keepttl", "nx")default:ifusePrecise() { = NewBoolCmd(, "set", , , "px", formatMs(, ), "nx") } else { = NewBoolCmd(, "set", , , "ex", formatSec(, ), "nx") } } _ = (, )return}// SetXX Redis `SET key value [expiration] XX` command.//// Zero expiration means the key has no expiration time.// KeepTTL is a Redis KEEPTTL option to keep existing TTL, it requires your redis-server version >= 6.0,// otherwise you will receive an error: (error) ERR syntax error.func ( cmdable) ( context.Context, string, interface{}, time.Duration) *BoolCmd {var *BoolCmdswitch {case0: = NewBoolCmd(, "set", , , "xx")caseKeepTTL: = NewBoolCmd(, "set", , , "keepttl", "xx")default:ifusePrecise() { = NewBoolCmd(, "set", , , "px", formatMs(, ), "xx") } else { = NewBoolCmd(, "set", , , "ex", formatSec(, ), "xx") } } _ = (, )return}// SetIFEQ Redis `SET key value [expiration] IFEQ match-value` command.// Compare-and-set: only sets the value if the current value equals matchValue.//// Returns "OK" on success.// Returns nil if the operation was aborted due to condition not matching.// Zero expiration means the key has no expiration time.//// NOTE SetIFEQ is still experimental// it's signature and behaviour may changefunc ( cmdable) ( context.Context, string, interface{}, interface{}, time.Duration) *StatusCmd { := []interface{}{"set", , }if > 0 {ifusePrecise() { = append(, "px", formatMs(, )) } else { = append(, "ex", formatSec(, )) } } elseif == KeepTTL { = append(, "keepttl") } = append(, "ifeq", ) := NewStatusCmd(, ...) _ = (, )return}// SetIFEQGet Redis `SET key value [expiration] IFEQ match-value GET` command.// Compare-and-set with GET: only sets the value if the current value equals matchValue,// and returns the previous value.//// Returns the previous value on success.// Returns nil if the operation was aborted due to condition not matching.// Zero expiration means the key has no expiration time.//// NOTE SetIFEQGet is still experimental// it's signature and behaviour may changefunc ( cmdable) ( context.Context, string, interface{}, interface{}, time.Duration) *StringCmd { := []interface{}{"set", , }if > 0 {ifusePrecise() { = append(, "px", formatMs(, )) } else { = append(, "ex", formatSec(, )) } } elseif == KeepTTL { = append(, "keepttl") } = append(, "ifeq", , "get") := NewStringCmd(, ...) _ = (, )return}// SetIFNE Redis `SET key value [expiration] IFNE match-value` command.// Compare-and-set: only sets the value if the current value does not equal matchValue.//// Returns "OK" on success.// Returns nil if the operation was aborted due to condition not matching.// Zero expiration means the key has no expiration time.//// NOTE SetIFNE is still experimental// it's signature and behaviour may changefunc ( cmdable) ( context.Context, string, interface{}, interface{}, time.Duration) *StatusCmd { := []interface{}{"set", , }if > 0 {ifusePrecise() { = append(, "px", formatMs(, )) } else { = append(, "ex", formatSec(, )) } } elseif == KeepTTL { = append(, "keepttl") } = append(, "ifne", ) := NewStatusCmd(, ...) _ = (, )return}// SetIFNEGet Redis `SET key value [expiration] IFNE match-value GET` command.// Compare-and-set with GET: only sets the value if the current value does not equal matchValue,// and returns the previous value.//// Returns the previous value on success.// Returns nil if the operation was aborted due to condition not matching.// Zero expiration means the key has no expiration time.//// NOTE SetIFNEGet is still experimental// it's signature and behaviour may changefunc ( cmdable) ( context.Context, string, interface{}, interface{}, time.Duration) *StringCmd { := []interface{}{"set", , }if > 0 {ifusePrecise() { = append(, "px", formatMs(, )) } else { = append(, "ex", formatSec(, )) } } elseif == KeepTTL { = append(, "keepttl") } = append(, "ifne", , "get") := NewStringCmd(, ...) _ = (, )return}// SetIFDEQ sets the value only if the current value's digest equals matchDigest.//// This is a compare-and-set operation using xxh3 digest for optimistic locking.// The matchDigest parameter is a uint64 xxh3 hash value.//// Returns "OK" on success.// Returns redis.Nil if the digest doesn't match (value was modified).// Zero expiration means the key has no expiration time.//// For examples of client-side digest generation and usage patterns, see:// example/digest-optimistic-locking///// Redis 8.4+. See https://redis.io/commands/set///// NOTE SetIFNEQ is still experimental// it's signature and behaviour may changefunc ( cmdable) ( context.Context, string, interface{}, uint64, time.Duration) *StatusCmd { := []interface{}{"set", , }if > 0 {ifusePrecise() { = append(, "px", formatMs(, )) } else { = append(, "ex", formatSec(, )) } } elseif == KeepTTL { = append(, "keepttl") } = append(, "ifdeq", fmt.Sprintf("%016x", )) := NewStatusCmd(, ...) _ = (, )return}// SetIFDEQGet sets the value only if the current value's digest equals matchDigest,// and returns the previous value.//// This is a compare-and-set operation using xxh3 digest for optimistic locking.// The matchDigest parameter is a uint64 xxh3 hash value.//// Returns the previous value on success.// Returns redis.Nil if the digest doesn't match (value was modified).// Zero expiration means the key has no expiration time.//// For examples of client-side digest generation and usage patterns, see:// example/digest-optimistic-locking///// Redis 8.4+. See https://redis.io/commands/set///// NOTE SetIFNEQGet is still experimental// it's signature and behaviour may changefunc ( cmdable) ( context.Context, string, interface{}, uint64, time.Duration) *StringCmd { := []interface{}{"set", , }if > 0 {ifusePrecise() { = append(, "px", formatMs(, )) } else { = append(, "ex", formatSec(, )) } } elseif == KeepTTL { = append(, "keepttl") } = append(, "ifdeq", fmt.Sprintf("%016x", ), "get") := NewStringCmd(, ...) _ = (, )return}// SetIFDNE sets the value only if the current value's digest does NOT equal matchDigest.//// This is a compare-and-set operation using xxh3 digest for optimistic locking.// The matchDigest parameter is a uint64 xxh3 hash value.//// Returns "OK" on success (digest didn't match, value was set).// Returns redis.Nil if the digest matches (value was not modified).// Zero expiration means the key has no expiration time.//// For examples of client-side digest generation and usage patterns, see:// example/digest-optimistic-locking///// Redis 8.4+. See https://redis.io/commands/set///// NOTE SetIFDNE is still experimental// it's signature and behaviour may changefunc ( cmdable) ( context.Context, string, interface{}, uint64, time.Duration) *StatusCmd { := []interface{}{"set", , }if > 0 {ifusePrecise() { = append(, "px", formatMs(, )) } else { = append(, "ex", formatSec(, )) } } elseif == KeepTTL { = append(, "keepttl") } = append(, "ifdne", fmt.Sprintf("%016x", )) := NewStatusCmd(, ...) _ = (, )return}// SetIFDNEGet sets the value only if the current value's digest does NOT equal matchDigest,// and returns the previous value.//// This is a compare-and-set operation using xxh3 digest for optimistic locking.// The matchDigest parameter is a uint64 xxh3 hash value.//// Returns the previous value on success (digest didn't match, value was set).// Returns redis.Nil if the digest matches (value was not modified).// Zero expiration means the key has no expiration time.//// For examples of client-side digest generation and usage patterns, see:// example/digest-optimistic-locking///// Redis 8.4+. See https://redis.io/commands/set///// NOTE SetIFDNEGet is still experimental// it's signature and behaviour may changefunc ( cmdable) ( context.Context, string, interface{}, uint64, time.Duration) *StringCmd { := []interface{}{"set", , }if > 0 {ifusePrecise() { = append(, "px", formatMs(, )) } else { = append(, "ex", formatSec(, )) } } elseif == KeepTTL { = append(, "keepttl") } = append(, "ifdne", fmt.Sprintf("%016x", ), "get") := NewStringCmd(, ...) _ = (, )return}func ( cmdable) ( context.Context, string, int64, string) *IntCmd { := NewIntCmd(, "setrange", , , ) _ = (, )return}func ( cmdable) ( context.Context, string) *IntCmd { := NewIntCmd(, "strlen", ) _ = (, )return}
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.