(ctx context.Context, key string, value []byte, opts KVSetOptions)
| 613 | } |
| 614 | |
| 615 | func (c *Client) KVSet(ctx context.Context, key string, value []byte, opts KVSetOptions) (bool, error) { |
| 616 | cmd, errClient := c.commandClient() |
| 617 | if errClient != nil { |
| 618 | return false, errClient |
| 619 | } |
| 620 | args, errArgs := buildKVSetArgs(key, value, opts) |
| 621 | if errArgs != nil { |
| 622 | return false, errArgs |
| 623 | } |
| 624 | result, errSet := cmd.Do(ctx, append([]any{"SET"}, args...)...).Result() |
| 625 | if errors.Is(errSet, redis.Nil) { |
| 626 | return false, nil |
| 627 | } |
| 628 | if errSet != nil { |
| 629 | return false, errSet |
| 630 | } |
| 631 | if result == nil { |
| 632 | return false, nil |
| 633 | } |
| 634 | return true, nil |
| 635 | } |
| 636 | |
| 637 | func (c *Client) KVSetNX(ctx context.Context, key string, value []byte, ttl time.Duration) (bool, error) { |
| 638 | opts := KVSetOptions{NX: true} |
no test coverage detected