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)
| 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. |
| 471 | func (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. |
| 492 | type SetArgs struct { |
nothing calls this directly
no test coverage detected