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

Method Set

string_commands.go:471–489  ·  view source on GitHub ↗

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 synt

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

Source from the content-addressed store, hash-verified

469// KeepTTL is a Redis KEEPTTL option to keep existing TTL, it requires your redis-server version >= 6.0,
470// otherwise you will receive an error: (error) ERR syntax error.
471func (c cmdable) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *StatusCmd {
472 args := make([]interface{}, 3, 5)
473 args[0] = "set"
474 args[1] = key
475 args[2] = value
476 if expiration > 0 {
477 if usePrecise(expiration) {
478 args = append(args, "px", formatMs(ctx, expiration))
479 } else {
480 args = append(args, "ex", formatSec(ctx, expiration))
481 }
482 } else if expiration == KeepTTL {
483 args = append(args, "keepttl")
484 }
485
486 cmd := NewStatusCmd(ctx, args...)
487 _ = c(ctx, cmd)
488 return cmd
489}
490
491// SetArgs provides arguments for the SetArgs function.
492type SetArgs struct {

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