redis/redis-py · error · ConnectionError
Error setting client name
Error message
Error setting client name
What it means
Raised as a generic ConnectionError during on_connect() when CLIENT SETNAME <self.client_name> returns anything other than 'OK'. The library only sets the name if client_name was configured; a non-OK reply typically means an ACL restriction or a server that rejected the name. The handshake aborts and the connection is not usable.
Solutions
- Grant the ACL user +client permission (or use a user with +@all).
- Remove or simplify the client_name to confirm it is the cause, then re-add a sanitized value.
- Upgrade the Redis server to >= 2.6.9.
- If the name is only for diagnostics, move identification to LIB-NAME via driver_info instead.
Example fix
// before r = redis.asyncio.Redis(host=h, client_name='my app name') // after r = redis.asyncio.Redis(host=h, client_name='my-app-name')
Defensive patterns
Strategy: validation
Validate before calling
import redis.asyncio as aioredis
async def supports_client_setname(url: str, name: str) -> bool:
r = aioredis.from_url(url)
try:
await r.execute_command('CLIENT', 'SETNAME', name)
return True
except Exception:
return False
finally:
await r.aclose() Type guard
from redis.exceptions import ConnectionError
def is_client_name_error(exc: BaseException) -> bool:
return isinstance(exc, ConnectionError) and 'client name' in str(exc).lower() Try / catch
from redis.exceptions import ConnectionError
try:
client = redis.asyncio.Redis(host=h, client_name=name)
await client.ping()
except ConnectionError as e:
if 'client name' in str(e).lower():
client = redis.asyncio.Redis(host=h) # drop client_name
else:
raise Prevention
- Confirm the ACL user has +client (or +@all) before relying on client_name.
- Keep client_name short, alphanumeric, no spaces.
- If unsure the server supports CLIENT SETNAME, set client_name only after a capability check.
When it happens
Trigger: Constructing redis.asyncio.Redis(client_name='my-app') (or setting client_name_class / pool client name) and connecting to a server whose ACL user lacks permission to run CLIENT SETNAME, or rejects the name value (e.g. contains invalid bytes).
Common situations: ACL user scoped with -client or renamed_commands blocking CLIENT; very old Redis server (< 2.6.9 where CLIENT SETNAME was introduced); a client_name containing spaces or newlines that the server rejects.
Related errors
- Invalid Database
- Invalid Username or Password
- Bad response from PING health check
- Buffer is closed.
- Cannot enable maintenance notifications for connection…
AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10).
Data as JSON: /api/errors/d4e51ea90cb9fee2.
Report an issue: GitHub.
Appendix: source
Thrown at redis/asyncio/connection.py:1025
# raise ConnectionError("Invalid RESP version")
# Activate maintenance notifications for this connection
# if enabled in the configuration
# This is a no-op if maintenance notifications are not enabled
await self.activate_maint_notifications_handling_if_enabled(
check_health=check_health
)
# if a client_name is given, set it
if self.client_name:
await self.send_command(
"CLIENT",
"SETNAME",
self.client_name,
check_health=check_health,
)
if str_if_bytes(await self.read_response()) != "OK":
raise ConnectionError("Error setting client name")
# Set the library name and version from driver_info, pipeline for lower startup latency
lib_name_sent = False
lib_version_sent = False
if self.driver_info and self.driver_info.formatted_name:
await self.send_command(
"CLIENT",
"SETINFO",
"LIB-NAME",
self.driver_info.formatted_name,
check_health=check_health,
)
lib_name_sent = True
if self.driver_info and self.driver_info.lib_version:
await self.send_command(
"CLIENT",View on GitHub (pinned to 6a6b581b48)