redis/redis-py · error · ConnectionError
Cannot retrieve information about server version
Error message
Cannot retrieve information about server version
What it means
Raised in CacheProxyConnection.connect (connection.py:1727-1734) when the underlying connection's handshake_metadata lacks a 'server' or 'version' field. Client-side caching (CacheProxyConnection) needs to know the server software and version to decide compatibility, and that metadata comes from the RESP3 HELLO response. Without HELLO (e.g. protocol=2, or a server/proxy that doesn't populate handshake metadata) the version cannot be determined and the cache proxy refuses to connect.
Solutions
- Use protocol=3 (RESP3) so HELLO populates handshake_metadata with server/version.
- Ensure no proxy strips the HELLO response fields.
- Upgrade Redis to a version that reports server name and version in HELLO.
- Disable client-side caching if you cannot use RESP3.
Example fix
# before r = redis.Redis(host=h, port=p, protocol=2, cache=my_cache) # after r = redis.Redis(host=h, port=p, protocol=3, cache=my_cache)
Defensive patterns
Strategy: validation
Validate before calling
# Client-side caching requires RESP3 (HELLO) to populate handshake metadata
assert int(protocol or 3) == 3, 'client-side caching needs protocol=3'
r = redis.Redis(host=h, port=p, protocol=3, cache=my_cache)
# verify metadata is populated:
with r.connection_pool.get_connection('HELLO') as c:
assert c.handshake_metadata.get(b'version') or c.handshake_metadata.get('version') Type guard
null
Try / catch
from redis.exceptions import ConnectionError
try:
r = redis.Redis(host=h, port=p, protocol=3, cache=my_cache)
r.ping()
except ConnectionError as e:
if 'Cannot retrieve information about server version' in str(e):
# strip the cache; keep the client working
r = redis.Redis(host=h, port=p, protocol=3)
else:
raise Prevention
- Always pair client-side caching with protocol=3.
- Remove any proxy that strips HELLO response fields.
- Smoke-test HELLO output: redis-cli -3 HELLO should show server+version.
When it happens
Trigger: Enabling client-side caching (cache=...) while using protocol=2, or against a server/intermediary that does not return server & version in HELLO. handshake_metadata is only populated by the HELLO handshake (RESP3).
Common situations: Turning on the client-side cache without switching to RESP3; proxy in front that strips HELLO metadata; OSS Redis older than the version reporting fields.
Related errors
- Client caching is only supported with RESP version 3
- Client caching is only supported with RESP version 3
- Cache must implement CacheInterface
- Client caching is only supported with RESP version 3
- Eviction policy should be associated with valid cache.
AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10).
Data as JSON: /api/errors/402a0f2a55aa50b2.
Report an issue: GitHub.
Appendix: source
Thrown at redis/connection.py:1734
if isinstance(self._conn, MaintNotificationsAbstractConnection):
self._conn.set_maint_notifications_cluster_handler_for_connection(
oss_cluster_maint_notifications_handler
)
def get_protocol(self):
return self._conn.get_protocol()
def connect(self):
self._conn.connect()
server_name = self._conn.handshake_metadata.get(b"server", None)
if server_name is None:
server_name = self._conn.handshake_metadata.get("server", None)
server_ver = self._conn.handshake_metadata.get(b"version", None)
if server_ver is None:
server_ver = self._conn.handshake_metadata.get("version", None)
if server_ver is None or server_name is None:
raise ConnectionError("Cannot retrieve information about server version")
server_ver = ensure_string(server_ver)
server_name = ensure_string(server_name)
if (
server_name != self.DEFAULT_SERVER_NAME
or compare_versions(server_ver, self.MIN_ALLOWED_VERSION) == 1
):
raise ConnectionError(
"To maximize compatibility with all Redis products, client-side caching is supported by Redis 7.4 or later" # noqa: E501
)
def on_connect(self):
self._conn.on_connect()
def disconnect(self, *args, **kwargs):
with self._cache_lock:
self._cache.flush()View on GitHub (pinned to 6a6b581b48)