{"id":"6c1e728f31adca6d","repo":"redis/redis-py","slug":"client-caching-is-only-supported-with-resp-version","errorCode":null,"errorMessage":"Client caching is only supported with RESP version 3","messagePattern":"Client caching is only supported with RESP version 3","errorType":"exception","errorClass":"RedisError","httpStatus":null,"severity":"error","filePath":"redis/client.py","lineNumber":527,"sourceCode":"                AfterPooledConnectionsInstantiationEvent(\n                    [connection_pool], ClientType.SYNC, credential_provider\n                )\n            )\n            self.auto_close_connection_pool = True\n        else:\n            self.auto_close_connection_pool = False\n            self._event_dispatcher.dispatch(\n                AfterPooledConnectionsInstantiationEvent(\n                    [connection_pool], ClientType.SYNC, credential_provider\n                )\n            )\n\n        self.connection_pool = connection_pool\n\n        if (cache_config or cache) and not check_protocol_version(\n            self.connection_pool.get_protocol(), 3\n        ):\n            raise RedisError(\"Client caching is only supported with RESP version 3\")\n\n        self.single_connection_lock = threading.RLock()\n        self.connection = None\n        self._single_connection_client = single_connection_client\n        if self._single_connection_client:\n            self.connection = self.connection_pool.get_connection()\n            self._event_dispatcher.dispatch(\n                AfterSingleConnectionInstantiationEvent(\n                    self.connection, ClientType.SYNC, self.single_connection_lock\n                )\n            )\n\n        connection_kwargs = self.connection_pool.connection_kwargs\n        self.response_callbacks = CaseInsensitiveDict(\n            get_response_callbacks(\n                user_protocol=connection_kwargs.get(\"protocol\"),\n                legacy_responses=connection_kwargs.get(\"legacy_responses\", True),\n            )","sourceCodeStart":509,"sourceCodeEnd":545,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/client.py#L509-L545","documentation":"Raised as RedisError in Redis.__init__ (redis/client.py:527) when a cache_config or cache object is provided but the connection pool's negotiated protocol is not RESP3. Client-side caching in redis-py depends on RESP3 push notifications to invalidate cache entries, so RESP2 is rejected.","triggerScenarios":"Constructing Redis(cache_config=CacheConfig(), protocol=2) (or protocol omitted against a RESP2-only server); providing a pre-built cache object while the pool protocol resolves to <3.","commonSituations":"Defaulting protocol while enabling client caching; connecting to a Redis <7.0 that cannot do RESP3; config template enabling cache without bumping protocol.","solutions":["Set protocol=3 when enabling client-side caching (cache_config or cache).","Upgrade the Redis server to a RESP3-capable version (>=7.0).","Remove cache_config/cache if you must stay on RESP2."],"exampleFix":"# before\nr = Redis(host='localhost', cache_config=CacheConfig())  # protocol defaults to RESP3 but server negotiates RESP2 -> RedisError\n# after\nr = Redis(host='localhost', protocol=3, cache_config=CacheConfig())","handlingStrategy":"validation","validationCode":"from redis._parsers.helpers import check_protocol_version\nif (cache_config or cache) and not check_protocol_version(protocol, 3):\n    raise ConfigError('Client-side caching requires protocol=3')","typeGuard":"def resp3_enabled(protocol) -> bool:\n    from redis._parsers.helpers import check_protocol_version\n    return check_protocol_version(protocol, 3)","tryCatchPattern":"try:\n    r = Redis(protocol=protocol, cache_config=cache_config)\nexcept RedisError as e:\n    logger.error('need RESP3 for client caching: %s', e)\n    raise","preventionTips":["Set protocol=3 when enabling cache_config or passing a cache.","Use a Redis >=7.0 server for client-side caching."],"tags":["config","caching","resp3"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}