{"record":{"id":"f75181679336dbdd","repo":"redis/go-redis","slug":"redis-client-tracking-optin-and-optout-are-mutual","errorCode":null,"errorMessage":"redis: CLIENT TRACKING OPTIN and OPTOUT are mutually exclusive","messagePattern":"redis: CLIENT TRACKING OPTIN and OPTOUT are mutually exclusive","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands.go","lineNumber":628,"sourceCode":"\t\t}\n\t\targs = appendClientTrackingOptions(args, opt)\n\t}\n\tcmd := NewStatusCmd(ctx, args...)\n\t_ = c(ctx, cmd)\n\treturn cmd\n}\n\n// ClientTrackingOff disables tracking on the serving connection. See\n// ClientTracking for the pooled-client and built-in-CSC caveats.\nfunc (c cmdable) ClientTrackingOff(ctx context.Context) *StatusCmd {\n\tcmd := NewStatusCmd(ctx, \"client\", \"tracking\", \"off\")\n\t_ = c(ctx, cmd)\n\treturn cmd\n}\n\nfunc validateClientTrackingOptions(opt *ClientTrackingOptions) error {\n\tif opt.OptIn && opt.OptOut {\n\t\treturn errors.New(\"redis: CLIENT TRACKING OPTIN and OPTOUT are mutually exclusive\")\n\t}\n\tif opt.Bcast && (opt.OptIn || opt.OptOut) {\n\t\treturn errors.New(\"redis: CLIENT TRACKING BCAST cannot be combined with OPTIN or OPTOUT\")\n\t}\n\tif len(opt.Prefixes) > 0 && !opt.Bcast {\n\t\treturn errors.New(\"redis: CLIENT TRACKING PREFIX requires BCAST\")\n\t}\n\treturn nil\n}\n\nfunc appendClientTrackingOptions(args []interface{}, opt *ClientTrackingOptions) []interface{} {\n\tif opt.Redirect != 0 {\n\t\targs = append(args, \"redirect\", opt.Redirect)\n\t}\n\tif opt.Bcast {\n\t\targs = append(args, \"bcast\")\n\t}\n\tfor _, p := range opt.Prefixes {","sourceCodeStart":610,"sourceCodeEnd":646,"githubUrl":"https://github.com/redis/go-redis/blob/c5cad058c72f58370553b48566302303cf8a2e89/commands.go#L610-L646","documentation":"validateClientTrackingOptions rejects CLIENT TRACKING options where both OptIn and OptOut are true. The two modes are mutually exclusive on the Redis protocol side, so the client refuses the combination locally.","triggerScenarios":"Calling ClientTracking with ClientTrackingOptions{OptIn: true, OptOut: true}.","commonSituations":"Merging two option structs (one OPTIN, one OPTOUT) and passing the union; config files where both opt keys were set to true.","solutions":["Set only one of OptIn or OptOut to true.","If intent was opt-in mode, set OptIn: true and leave OptOut as the zero value.","Validate the options struct before calling ClientTracking."],"exampleFix":"// before\nrdb.ClientTracking(ctx, &redis.ClientTrackingOptions{OptIn: true, OptOut: true})\n// after\nrdb.ClientTracking(ctx, &redis.ClientTrackingOptions{OptIn: true})","handlingStrategy":"validation","validationCode":"func validTracking(o *redis.ClientTrackingOptions) bool {\n    return o != nil && !(o.OptIn && o.OptOut)\n}","typeGuard":null,"tryCatchPattern":"if err := rdb.ClientTracking(ctx, opt).Err(); err != nil {\n    if strings.Contains(err.Error(), \"OPTIN and OPTOUT are mutually exclusive\") {\n        // fix options and retry\n    }\n}","preventionTips":["Centralize ClientTrackingOptions construction in one helper.","Never set both OptIn and OptOut in config; validate flags at load time."],"tags":["client-tracking","validation","options"],"backgroundTag":"client-tracking-options-invalid","analyzedSha":"c5cad058c72f58370553b48566302303cf8a2e89","analyzedAt":"2026-09-01T06:50:53.388Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}