{"id":"857eee01bca62f20","repo":"redis/redis-py","slug":"prefix-can-only-be-used-with-bcast","errorCode":null,"errorMessage":"Prefix can only be used with bcast","messagePattern":"Prefix can only be used with bcast","errorType":"validation","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/commands/core.py","lineNumber":1101,"sourceCode":"        ``optin``  when broadcasting is NOT active, normally don't track\n        keys in read only commands, unless they are called immediately\n        after a CLIENT CACHING yes command.\n\n        ``optout`` when broadcasting is NOT active, normally track keys in\n        read only commands, unless they are called immediately after a\n        CLIENT CACHING no command.\n\n        ``noloop`` don't send notifications about keys modified by this\n        connection itself.\n\n        ``prefix``  for broadcasting, register a given key prefix, so that\n        notifications will be provided only for keys starting with this string.\n\n        See https://redis.io/commands/client-tracking\n        \"\"\"\n\n        if len(prefix) != 0 and bcast is False:\n            raise DataError(\"Prefix can only be used with bcast\")\n\n        pieces = [\"ON\"] if on else [\"OFF\"]\n        if clientid is not None:\n            pieces.extend([\"REDIRECT\", clientid])\n        for p in prefix:\n            pieces.extend([\"PREFIX\", p])\n        if bcast:\n            pieces.append(\"BCAST\")\n        if optin:\n            pieces.append(\"OPTIN\")\n        if optout:\n            pieces.append(\"OPTOUT\")\n        if noloop:\n            pieces.append(\"NOLOOP\")\n\n        return self.execute_command(\"CLIENT TRACKING\", *pieces, **kwargs)\n\n    @overload","sourceCodeStart":1083,"sourceCodeEnd":1119,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/commands/core.py#L1083-L1119","documentation":"Raised by client_tracking when a prefix is supplied but bcast is False (default). Key-prefix filtering in server-assisted client-side caching only makes sense in broadcast mode, where the server sends invalidations for keys matching the prefix regardless of what the connection reads.","triggerScenarios":"Calling r.client_tracking(on=True, prefix=['user:'], bcast=False). Passing a non-empty prefix list without setting bcast=True. Conditionally setting prefix but forgetting to toggle bcast.","commonSituations":"Enabling client-side caching with per-prefix scoping but omitting the bcast flag. Copying a tracking config where bcast was implied elsewhere. Migrating from an optin/optout setup that used prefixes incorrectly.","solutions":["Set bcast=True whenever you supply prefix values.","If you don't want broadcast mode, remove the prefix argument entirely.","Verify that broadcast + prefix is the intended caching strategy (server pushes invalidations for those prefixes)."],"exampleFix":"# before\nr.client_tracking(on=True, prefix=['cache:'])\n# after\nr.client_tracking(on=True, prefix=['cache:'], bcast=True)","handlingStrategy":"validation","validationCode":"if prefix and not bcast:\n    raise ValueError('prefix requires bcast=True')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat prefix and bcast as a coupled pair: if you set one, set the other.","Review the client-side caching docs — prefix filtering is broadcast-only by design."],"tags":["client-side-caching","validation","dataerror"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}