redis/redis-py · error · RedisError

Hiredis is not installed

Error message

Hiredis is not installed

What it means

Raised in _HiredisParser.__init__() (redis/_parsers/hiredis.py:112) when the sync hiredis parser is constructed but hiredis-py is not importable (HIREDIS_AVAILABLE is False). The hiredis parser is the C-accelerated RESP parser used when the 'hiredis' extra is installed; without the package it cannot be created.

Solutions

  1. Install hiredis: 'pip install hiredis' or 'pip install redis[hiredis]' (pin hiredis>=3.2.0 for full feature support).
  2. If you don't need hiredis, don't request it — let the client use the pure-Python parser (the default).
  3. Verify the install with: python -c 'import hiredis; print(hiredis.__version__)'.
  4. For custom code, gate the parser selection on redis.utils.HIREDIS_AVAILABLE.

Example fix

# before
# parser selected as hiredis but package missing -> RedisError('Hiredis is not installed')

# after
# pip install hiredis
r = redis.Redis(...)  # hiredis auto-used when present, no explicit parser needed
Defensive patterns

Strategy: validation

Validate before calling

from redis.utils import HIREDIS_AVAILABLE
if not HIREDIS_AVAILABLE:
    raise RuntimeError("install hiredis: pip install redis[hiredis]")
# now safe to use the hiredis parser

Try / catch

try:
    from redis._parsers.hiredis import _HiredisParser
    parser = _HiredisParser(socket_read_size=65536)
except redis.RedisError as e:
    if "Hiredis is not installed" in str(e):
        # fall back to the pure-Python parser instead of failing
        ...

Prevention

When it happens

Trigger: A connection is explicitly configured to use the hiredis parser (or code constructs _HiredisParser directly) while hiredis-py is not installed in the environment.

Common situations: Deploying without 'pip install redis[hiredis]' (or 'pip install hiredis'); CI/container image missing the extra; a platform where the hiredis wheel isn't available; importing the parser unconditionally in custom code.

Related errors


AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10). Data as JSON: /api/errors/5067ab8df9750e27. Report an issue: GitHub.

Appendix: 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 6a6b581b48)