{"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":3014,"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":2996,"sourceCodeEnd":3032,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/connection.py#L2996-L3032","documentation":"Raised as a RedisError by ConnectionPool.__init__ (connection.py:3012-3014) when cache_config or cache is set but the protocol is not RESP3 (check_protocol_version returns False). Client-side caching (CSC) relies on RESP3 invalidation push messages, so it is fundamentally unavailable over RESP2.","triggerScenarios":"Constructing a client with cache_config=... or cache=... while protocol=2. As with maintenance notifications, protocol=None/SENTINEL defaults to RESP3 (DEFAULT_RESP_VERSION=3), so this requires explicitly opting into RESP2.","commonSituations":"Forcing protocol=2 for legacy server compatibility while also configuring client-side caching; copying a CSC-enabled config into a deployment pinned to RESP2; testing CSC against an older Redis that only does RESP2.","solutions":["Set protocol=3 (or omit it for the RESP3 default) when enabling client-side caching.","If RESP2 is required, remove cache_config/cache — client-side caching is not supported.","Ensure the Redis server is >= 6 for RESP3 and tracking support."],"exampleFix":"# before\nclient = redis.Redis(protocol=2, cache_config=CacheConfig())\n\n# after\nclient = redis.Redis(protocol=3, cache_config=CacheConfig())","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 protocol=3\")\n\nclient = redis.Redis(protocol=protocol, cache_config=cache_config, cache=cache)","typeGuard":"def csc_compatible(protocol) -> bool:\n    from redis.utils import check_protocol_version\n    return check_protocol_version(protocol, 3)","tryCatchPattern":"from redis.exceptions import RedisError\ntry:\n    client = redis.Redis(protocol=protocol, cache_config=cfg)\nexcept RedisError as e:\n    if \"only supported with RESP version 3\" in str(e):\n        client = redis.Redis(protocol=3, cache_config=cfg)\n    else:\n        raise","preventionTips":["Always pair client-side caching config with protocol=3.","Confirm the Redis server supports RESP3 and tracking.","Centralize protocol selection so CSC and notifications get RESP3 consistently."],"tags":["client-side-caching","resp3","configuration","validation"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}