{"record":{"id":"6d2ecc7a809fb11b","repo":"redis/redis-py","slug":"client-caching-is-only-supported-with-resp-version-6d2ecc","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/connection.py","lineNumber":3029,"sourceCode":"\n        if is_unix_domain_socket_connection or not supports_maint_notifications:\n            if (\n                maint_notifications_config\n                and maint_notifications_config.enabled is True\n            ):\n                raise RedisError(\n                    \"Maintenance notifications are not supported with \"\n                    f\"{connection_class}\"\n                )\n            maint_notifications_config = MaintNotificationsConfig(enabled=False)\n\n        self._event_dispatcher = self._connection_kwargs.get(\"event_dispatcher\", None)\n        if self._event_dispatcher is None:\n            self._event_dispatcher = EventDispatcher()\n\n        if connection_kwargs.get(\"cache_config\") or connection_kwargs.get(\"cache\"):\n            if not check_protocol_version(self._connection_kwargs.get(\"protocol\"), 3):\n                raise RedisError(\"Client caching is only supported with RESP version 3\")\n\n            cache = self._connection_kwargs.get(\"cache\")\n\n            if cache is not None:\n                if not isinstance(cache, CacheInterface):\n                    raise ValueError(\"Cache must implement CacheInterface\")\n\n                self.cache = cache\n            else:\n                if self._cache_factory is not None:\n                    self.cache = CacheProxy(self._cache_factory.get_cache())\n                else:\n                    self.cache = CacheFactory(\n                        self._connection_kwargs.get(\"cache_config\")\n                    ).get_cache()\n\n            init_csc_items()\n            register_csc_items_callback(","sourceCodeStart":3011,"sourceCodeEnd":3047,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/connection.py#L3011-L3047","documentation":"Raised as RedisError by ConnectionPool.__init__ when cache_config or cache is supplied but the protocol is not RESP3 (check_protocol_version returns False). Client-side caching (CSC) relies on RESP3 TRACKING-style invalidation push messages, so it cannot run over RESP2. protocol None/SENTINEL resolves to DEFAULT_RESP_VERSION before the check.","triggerScenarios":"Constructing a client with protocol=2 and cache_config={...} or cache=SomeCache(). Also passing protocol='2' or a non-numeric protocol string with caching enabled.","commonSituations":"Forcing RESP2 for legacy response shapes while trying to use client-side caching. Test matrices that pin protocol=2 globally. Copy-pasting a cache_config without setting protocol=3.","solutions":["Set protocol=3 (or omit it, since RESP3 is default) whenever cache_config or cache is provided.","If RESP2 is mandatory, remove cache_config/cache.","Validate check_protocol_version(protocol, 3) before building the pool when caching is desired."],"exampleFix":"# before\npool = ConnectionPool(protocol=2, cache_config={})\n# after\npool = ConnectionPool(protocol=3, cache_config={})","handlingStrategy":"validation","validationCode":"from redis.utils import check_protocol_version\n\nif (cache_config or cache) and not check_protocol_version(protocol, 3):\n    raise ValueError('Client-side caching requires RESP3 (protocol=3)')\n\npool = ConnectionPool(protocol=protocol, cache_config=cache_config, cache=cache)","typeGuard":"from redis.utils import check_protocol_version\n\ndef caching_compatible(protocol, cache_config, cache) -> bool:\n    wants_cache = bool(cache_config or cache)\n    return (not wants_cache) or check_protocol_version(protocol, 3)","tryCatchPattern":"from redis.exceptions import RedisError\ntry:\n    pool = ConnectionPool(protocol=protocol, cache_config=cache_config)\nexcept RedisError as e:\n    if 'only supported with RESP version 3' in str(e):\n        pool = ConnectionPool(protocol=3, cache_config=cache_config)\n    else:\n        raise","preventionTips":["Use protocol=3 (the default) whenever enabling cache_config/cache.","Validate protocol before constructing the pool.","Avoid global protocol=2 test pins when caching is in use."],"tags":["client-side-caching","resp3","configuration"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}