JSONSetWithArgs sets the JSON value at the given path in the given key with optional arguments for setting mode (NX/XX) and the FPHA (Floating-Point Homogeneous Array) type used for storing FP arrays. The value must be something that can be marshaled to JSON (using encoding/JSON) unless the argument
(ctx context.Context, key, path string, value interface{}, options *JSONSetArgsOptions)
| 613 | // the argument is a string or []byte when we assume that it can be passed directly as JSON. |
| 614 | // For more information, see https://redis.io/commands/json.set |
| 615 | func (c cmdable) JSONSetWithArgs(ctx context.Context, key, path string, value interface{}, options *JSONSetArgsOptions) *StatusCmd { |
| 616 | var bytes []byte |
| 617 | var err error |
| 618 | switch v := value.(type) { |
| 619 | case string: |
| 620 | bytes = []byte(v) |
| 621 | case []byte: |
| 622 | bytes = v |
| 623 | default: |
| 624 | bytes, err = json.Marshal(v) |
| 625 | } |
| 626 | args := []interface{}{"JSON.SET", key, path, util.BytesToString(bytes)} |
| 627 | if options != nil { |
| 628 | if options.Mode != "" { |
| 629 | switch strings.ToUpper(options.Mode) { |
| 630 | case "XX", "NX": |
| 631 | args = append(args, strings.ToUpper(options.Mode)) |
| 632 | default: |
| 633 | panic("redis: JSON.SET mode must be NX or XX") |
| 634 | } |
| 635 | } |
| 636 | if options.FPHA != "" { |
| 637 | args = append(args, "FPHA", string(options.FPHA)) |
| 638 | } |
| 639 | } |
| 640 | cmd := NewStatusCmd(ctx, args...) |
| 641 | if err != nil { |
| 642 | cmd.SetErr(err) |
| 643 | } else { |
| 644 | _ = c(ctx, cmd) |
| 645 | } |
| 646 | return cmd |
| 647 | } |
| 648 | |
| 649 | // JSONStrAppend appends the JSON-string values to the string at the specified path. |
| 650 | // For more information, see https://redis.io/commands/json.strappend |
no test coverage detected