redis/go-redis · error
redis: JSON.SET mode must be NX or XX
Error message
redis: JSON.SET mode must be NX or XX
What it means
Error "redis: JSON.SET mode must be NX or XX" thrown in redis/go-redis.
Source
Thrown at json.go:648
func (c cmdable) JSONSetWithArgs(ctx context.Context, key, path string, value interface{}, options *JSONSetArgsOptions) *StatusCmd {
var bytes []byte
var err error
switch v := value.(type) {
case string:
bytes = []byte(v)
case []byte:
bytes = v
default:
bytes, err = json.Marshal(v)
}
args := []interface{}{"JSON.SET", key, path, util.BytesToString(bytes)}
if options != nil {
if options.Mode != "" {
switch strings.ToUpper(options.Mode) {
case "XX", "NX":
args = append(args, strings.ToUpper(options.Mode))
default:
panic("redis: JSON.SET mode must be NX or XX")
}
}
if options.FPHA != "" {
args = append(args, "FPHA", string(options.FPHA))
}
}
cmd := NewStatusCmd(ctx, args...)
if err != nil {
cmd.SetErr(err)
} else {
_ = c(ctx, cmd)
}
return cmd
}
// JSONStrAppend appends the JSON-string values to the string at the specified path.
// For more information, see https://redis.io/commands/json.strappend
func (c cmdable) JSONStrAppend(ctx context.Context, key, path, value string) *IntPointerSliceCmd {View on GitHub (pinned to c5cad058c7)
When it happens
Trigger: Thrown at json.go:648 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of redis/go-redis@c5cad058c7 (2026-09-01).
Data as JSON: /api/errors/442c429cb87cc8d2.
Report an issue: GitHub.