redis/redis-py · error · ConnectionError

Cannot retrieve information about server version

Error message

Cannot retrieve information about server version

What it means

Raised as a ConnectionError in CacheProxyConnection.connect when the HELLO handshake metadata lacks 'server' or 'version' fields. Client-side caching (CacheProxyConnection) relies on HELLO to identify the server type and version, so missing metadata prevents the version gate. This typically means RESP3/HELLO did not run or the server did not return version info.

Source

Thrown at redis/connection.py:1718

        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 da03cdc7e8)

Solutions

  1. Ensure protocol=3 so the HELLO handshake runs and populates server/version metadata.
  2. Connect to a genuine Redis server that returns full HELLO metadata.
  3. Avoid client-side caching against servers/proxies that omit HELLO fields.

Example fix

// before
r = redis.Redis(host=h, protocol=2, cache=cache_config)
r.ping()
// after
r = redis.Redis(host=h, protocol=3, cache=cache_config)
r.ping()
Defensive patterns

Strategy: validation

Validate before calling

# ensure protocol=3 so HELLO populates handshake metadata before enabling CSC
if protocol not in (3, '3'):
    raise ValueError('Client-side caching requires protocol=3 to obtain HELLO metadata')

Try / catch

try:
    r = redis.Redis(host=h, protocol=3, cache=cache_config)
    r.ping()
except redis.exceptions.ConnectionError as e:
    if 'server version' in str(e):
        r = redis.Redis(host=h, protocol=3)  # disable cache
        r.ping()

Prevention

When it happens

Trigger: Using a client configured with client-side caching (CacheProxyConnection wrapping the underlying connection) where on_connect did not populate handshake_metadata with server/version. Happens if protocol is not 3 (so HELLO is skipped) or the server omits these fields, or the connection is not actually going through the HELLO path.

Common situations: Enabling client-side caching with protocol=2 (no HELLO, so no handshake metadata); connecting to a proxy/server that strips HELLO metadata; a misconfigured CacheProxyConnection used without a real HELLO exchange.

Related errors


AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04). Data as JSON: /data/errors/402a0f2a55aa50b2.json. Report an issue: GitHub.