MCPcopy
hub / github.com/redis/go-redis / SetIFDNE

Method SetIFDNE

string_commands.go:854–872  ·  view source on GitHub ↗

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.Ni

(ctx context.Context, key string, value interface{}, matchDigest uint64, expiration time.Duration)

Source from the content-addressed store, hash-verified

852// NOTE SetIFDNE is still experimental
853// it's signature and behaviour may change
854func (c cmdable) SetIFDNE(ctx context.Context, key string, value interface{}, matchDigest uint64, expiration time.Duration) *StatusCmd {
855 args := []interface{}{"set", key, value}
856
857 if expiration > 0 {
858 if usePrecise(expiration) {
859 args = append(args, "px", formatMs(ctx, expiration))
860 } else {
861 args = append(args, "ex", formatSec(ctx, expiration))
862 }
863 } else if expiration == KeepTTL {
864 args = append(args, "keepttl")
865 }
866
867 args = append(args, "ifdne", fmt.Sprintf("%016x", matchDigest))
868
869 cmd := NewStatusCmd(ctx, args...)
870 _ = c(ctx, cmd)
871 return cmd
872}
873
874// SetIFDNEGet sets the value only if the current value's digest does NOT equal matchDigest,
875// and returns the previous value.

Callers

nothing calls this directly

Calls 4

usePreciseFunction · 0.85
formatMsFunction · 0.85
formatSecFunction · 0.85
NewStatusCmdFunction · 0.85

Tested by

no test coverage detected