redis/redis-py · error · RedisError
Hiredis is not installed
Error message
Hiredis is not installed
What it means
Raised by _HiredisParser.__init__() when redis.utils.HIREDIS_AVAILABLE is False - i.e. the optional hiredis-py package is not importable. The parser is only constructed when the connection is configured to use the hiredis parser; without the C extension the parser cannot be created. Plain RedisError, error_type=SERVER.
Source
Thrown at redis/_parsers/hiredis.py:112
return bool(revents & closed_flags)
except OSError:
# The socket is errored (POLLERR/POLLNVAL); nothing left to read.
return True
class _HiredisReaderArgs(TypedDict, total=False):
protocolError: Callable[[str], Exception]
replyError: Callable[[str], Exception]
encoding: Optional[str]
errors: Optional[str]
class _HiredisParser(BaseParser, PushNotificationsParser):
"Parser class for connections using Hiredis"
def __init__(self, socket_read_size):
if not HIREDIS_AVAILABLE:
raise RedisError("Hiredis is not installed")
self.socket_read_size = socket_read_size
self._buffer = bytearray(socket_read_size)
self.pubsub_push_handler_func = self.handle_pubsub_push_response
self.node_moving_push_handler_func = None
self.maintenance_push_handler_func = None
self.oss_cluster_maint_push_handler_func = None
self.invalidation_push_handler_func = None
self._hiredis_PushNotificationType = None
def __del__(self):
try:
self.on_disconnect()
except Exception:
pass
def handle_pubsub_push_response(self, response):
logger = getLogger("push_response")
logger.debug("Push response: %s", response)View on GitHub (pinned to da03cdc7e8)
Solutions
- Install hiredis: pip install hiredis (or pip install redis[hiredis]).
- Verify the install imports: python -c 'import hiredis; print(hiredis.__version__)'.
- If you cannot install hiredis, drop the parser_class override so the pure-Python parser is used.
- Rebuild hiredis against the running Python ABI after a Python version bump.
Example fix
// before r = redis.Redis(..., parser_class=redis.parsers.HiredisParser) # RedisError: Hiredis is not installed // after # option A: install it # pip install hiredis # option B: fall back to the pure-Python parser r = redis.Redis(...) # do not set parser_class
Defensive patterns
Strategy: validation
Validate before calling
# Verify hiredis is importable before constructing a client that needs it
import importlib.util, redis.utils
if not importlib.util.find_spec("hiredis"):
raise RuntimeError("install 'hiredis' or drop the parser_class override")
assert redis.utils.HIREDIS_AVAILABLE Try / catch
try:
r = redis.Redis(..., parser_class=redis.parsers.HiredisParser)
except redis.exceptions.RedisError as e:
if "Hiredis is not installed" in str(e):
# fall back to the pure-Python parser
r = redis.Redis(...) Prevention
- Install via the extra: pip install redis[hiredis].
- Verify in CI: python -c 'import hiredis'.
- Do not hard-code parser_class unless hiredis is a declared dependency.
- Rebuild hiredis after any Python ABI change.
When it happens
Trigger: Setting parser_class=_HiredisParser (or via a client config that selects it) in an environment where hiredis is not installed; the installed hiredis is older than 3.2.0 (HIREDIS_AVAILABLE checks importability/version); broken hiredis build that fails to import.
Common situations: Deploying without the 'hiredis' extra (pip install redis[hiredis]); using a slim Docker image lacking build tools; mixed Python versions in a venv where hiredis was compiled for a different ABI; pinning redis-py but forgetting the optional C extension.
Related errors
- Connection closed by server.
- Maintenance notifications are only supported with hiredis an
- {cmd_name.upper()} command doesn't exist in Redis commands
- Subcommand {subcommand_name} not found in command {command_n
- Command {command_name} not found in commands
AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04).
Data as JSON: /data/errors/5067ab8df9750e27.json.
Report an issue: GitHub.