{"record":{"id":"47162a9d15b06624","repo":"redis/redis-py","slug":"hiredis-is-not-available","errorCode":null,"errorMessage":"Hiredis is not available.","messagePattern":"Hiredis is not available\\.","errorType":"exception","errorClass":"RedisError","httpStatus":null,"severity":"error","filePath":"redis/_parsers/hiredis.py","lineNumber":276,"sourceCode":"            )\n\n        elif (\n            isinstance(response, list)\n            and response\n            and isinstance(response[0], ConnectionError)\n        ):\n            raise response[0]\n        return response\n\n\nclass _AsyncHiredisParser(AsyncBaseParser, AsyncPushNotificationsParser):\n    \"\"\"Async implementation of parser class for connections using Hiredis\"\"\"\n\n    __slots__ = (\"_reader\",)\n\n    def __init__(self, socket_read_size: int):\n        if not HIREDIS_AVAILABLE:\n            raise RedisError(\"Hiredis is not available.\")\n        super().__init__(socket_read_size=socket_read_size)\n        self._reader = None\n        self.pubsub_push_handler_func = self.handle_pubsub_push_response\n        self.invalidation_push_handler_func = None\n        self._hiredis_PushNotificationType = None\n\n    async def handle_pubsub_push_response(self, response):\n        logger = getLogger(\"push_response\")\n        logger.debug(\"Push response: %s\", response)\n        return response\n\n    def on_connect(self, connection):\n        import hiredis\n\n        self._stream = connection._reader\n        kwargs: _HiredisReaderArgs = {\n            \"protocolError\": InvalidResponse,\n            \"replyError\": self.parse_error,","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/_parsers/hiredis.py#L258-L294","documentation":"Raised by _AsyncHiredisParser.__init__ when redis.utils.HIREDIS_AVAILABLE is False: the optional hiredis C extension is either not installed or older than 3.2.0 (the minimum this library will use, per utils.py). The parser cannot operate without it, so construction fails fast with redis.exceptions.RedisError before any connection is attempted.","triggerScenarios":"Passing parser_class=_AsyncHiredisParser (or otherwise forcing the hiredis parser) without the dependency; deploying where 'pip install redis[hiredis]' was skipped or the hiredis wheel failed to build/import; downgrading hiredis below 3.2.0; a platform without a hiredis wheel (some archs/PyPy) and no build toolchain.","commonSituations":"Slender Docker image that pip-installed 'redis' but not 'redis[hiredis]'; Alpine/musl without gcc to build hiredis; Python 3.13 with an old pinned hiredis that lacks a wheel; a CI matrix pining hiredis<3.2.","solutions":["Install/upgrade the optional dependency: pip install -U 'hiredis>=3.2.0' (or 'redis[hiredis]').","Don't force parser_class - omit it and let the library auto-select hiredis when available, else the pure-Python parser.","Verify the import actually works: python -c 'import hiredis; print(hiredis.__version__)'.","On platforms lacking a wheel, install a build toolchain (gcc / python3-dev) or drop the forced hiredis parser."],"exampleFix":"# before\nimport redis.asyncio as redis\nfrom redis._parsers.hiredis import _AsyncHiredisParser\nr = redis.Redis(parser_class=_AsyncHiredisParser)  # -> RedisError: Hiredis is not available.\n\n# after - install the extra and let the library choose\n#   pip install 'redis[hiredis]'\nr = redis.Redis()  # uses hiredis if present, pure-Python otherwise","handlingStrategy":"validation","validationCode":"import redis.utils\nfrom redis._parsers.hiredis import _AsyncHiredisParser\nif not redis.utils.HIREDIS_AVAILABLE:\n    raise SystemExit('install: pip install \"redis[hiredis]\"')\nr = redis.Redis(parser_class=_AsyncHiredisParser)","typeGuard":"from redis.exceptions import RedisError\n\ndef is_missing_dep_error(e: BaseException) -> bool:\n    return isinstance(e, RedisError) and 'not available' in str(e).lower()","tryCatchPattern":"import redis.utils\nparser = _AsyncHiredisParser if redis.utils.HIREDIS_AVAILABLE else None\nr = redis.Redis(parser_class=parser) if parser else redis.Redis()","preventionTips":["Pin 'hiredis>=3.2.0' in your requirements if you force the hiredis parser.","Install via the extra - 'pip install redis[hiredis]' - not bare 'pip install hiredis'.","Don't hard-set parser_class in code that runs in heterogeneous environments; let it auto-select."],"tags":["hiredis","dependency","config","async","init"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}