{"record":{"id":"20d93646bbd4b6a8","repo":"apache/beam","slug":"failed-to-import-redis-you-can-ensure-it-is-installed-by","errorCode":null,"errorMessage":"Failed to import redis. You can ensure it is installed by installing the redis beam extra","messagePattern":"Failed to import redis\\. You can ensure it is installed by installing the redis beam extra","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/requestresponse.py","lineNumber":695,"sourceCode":"      time_to_live: `(Union[int, timedelta])` The time-to-live (TTL) for\n        records stored in Redis. Provide an integer (in seconds) or a\n        `datetime.timedelta` object.\n      request_coder: (Optional[`coders.Coder`]) coder for encoding requests.\n      response_coder: (Optional[`coders.Coder`]) coder for decoding responses\n        received from Redis.\n      kwargs: Optional additional keyword arguments that\n        are required to connect to your redis server. Same as `redis.Redis()`.\n    \"\"\"\n    self._host = host\n    self._port = port\n    self._time_to_live = time_to_live\n    self._request_coder = request_coder\n    self._response_coder = response_coder\n    self._kwargs = kwargs if kwargs else {}\n    self._source_caller = None\n\n    if redis is None:\n      raise ImportError(\n          'Failed to import redis. You can ensure it is '\n          'installed by installing the redis beam extra')\n\n  def get_read(self):\n    \"\"\"get_read returns a PTransform for reading from the cache.\"\"\"\n    ensure_coders_exist(self._request_coder)\n    return _ReadFromRedis(\n        self._host,\n        self._port,\n        time_to_live=self._time_to_live,\n        kwargs=self._kwargs,\n        request_coder=self._request_coder,\n        response_coder=self._response_coder,\n        source_caller=self._source_caller)\n\n  def get_write(self):\n    \"\"\"returns a PTransform for writing to the cache.\"\"\"\n    ensure_coders_exist(self._request_coder)","sourceCodeStart":677,"sourceCodeEnd":713,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/requestresponse.py#L677-L713","documentation":"RedisCache.__init__ checks whether the `redis` Python package was importable; if not, it raises ImportError telling the user to install the redis extra for Beam. Redis-backed caching cannot be constructed without the dependency.","triggerScenarios":"Instantiating RedisCache (or using Cache with redis backend) in an environment where `import redis` failed — the package is not installed in the worker/driver environment.","commonSituations":"Running Beam pipelines on Dataflow/runners where the redis package was not added to requirements; dev machine missing the extra; dependency conflicts where redis failed to import.","solutions":["Install the dependency: pip install apache-beam[redis] (or pip install redis).","Add 'redis' (or apache-beam[redis]) to your requirements_file/setup.py so workers also install it.","Verify the import works in the same environment the pipeline executes in (workers, containers), not just locally.","If Redis is unavailable, switch to a different Cache implementation that does not need redis."],"exampleFix":"# before\npip install apache-beam\n# after\npip install 'apache-beam[redis]'","handlingStrategy":"validation","validationCode":"try:\n  import redis\nexcept ImportError:\n  raise ImportError(\"install with: pip install 'apache-beam[redis]'\")","typeGuard":null,"tryCatchPattern":"try:\n  cache = RedisCache(client, prefix, request_coder=rc)\nexcept ImportError:\n  cache = None  # run without caching or fail fast in setup","preventionTips":["Install apache-beam[redis] in every environment the pipeline runs in (driver and workers)","Pin the redis package in requirements/setup.py","Smoke-test imports in worker containers before deploying"],"tags":["python","apache-beam","redis","missing-dependency"],"backgroundTag":"missing-dependency","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}