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

Method SetIFEQ

string_commands.go:656–674  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

654// NOTE SetIFEQ is still experimental
655// it's signature and behaviour may change
656func (c cmdable) SetIFEQ(ctx context.Context, key string, value interface{}, matchValue interface{}, expiration time.Duration) *StatusCmd {
657 args := []interface{}{"set", key, value}
658
659 if expiration > 0 {
660 if usePrecise(expiration) {
661 args = append(args, "px", formatMs(ctx, expiration))
662 } else {
663 args = append(args, "ex", formatSec(ctx, expiration))
664 }
665 } else if expiration == KeepTTL {
666 args = append(args, "keepttl")
667 }
668
669 args = append(args, "ifeq", matchValue)
670
671 cmd := NewStatusCmd(ctx, args...)
672 _ = c(ctx, cmd)
673 return cmd
674}
675
676// SetIFEQGet Redis `SET key value [expiration] IFEQ match-value GET` command.
677// Compare-and-set with GET: only sets the value if the current value equals matchValue,

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