This is an automated email from the ASF dual-hosted git repository.

damccorm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 543056a7898 split redis into extra (#36772)
543056a7898 is described below

commit 543056a7898872654c5731e26165310070507ae5
Author: Danny McCormick <[email protected]>
AuthorDate: Tue Nov 25 09:37:08 2025 -0500

    split redis into extra (#36772)
    
    * split redis into extra
    
    * guard missing imports
    
    * yapf
    
    * Get coverage tasks
---
 sdks/python/apache_beam/io/requestresponse.py | 11 ++++++++++-
 sdks/python/setup.py                          |  2 +-
 sdks/python/tox.ini                           |  6 +++---
 3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/sdks/python/apache_beam/io/requestresponse.py 
b/sdks/python/apache_beam/io/requestresponse.py
index 213a1a3fc7e..e53fa07471a 100644
--- a/sdks/python/apache_beam/io/requestresponse.py
+++ b/sdks/python/apache_beam/io/requestresponse.py
@@ -35,7 +35,6 @@ from typing import Tuple
 from typing import TypeVar
 from typing import Union
 
-import redis
 from google.api_core.exceptions import TooManyRequests
 
 import apache_beam as beam
@@ -46,6 +45,11 @@ from apache_beam.metrics import Metrics
 from apache_beam.transforms.util import BatchElements
 from apache_beam.utils import retry
 
+try:
+  import redis
+except ImportError:
+  redis = None
+
 RequestT = TypeVar('RequestT')
 ResponseT = TypeVar('ResponseT')
 
@@ -689,6 +693,11 @@ class RedisCache(Cache):
     self._kwargs = kwargs if kwargs else {}
     self._source_caller = None
 
+    if redis is None:
+      raise ImportError(
+          'Failed to import redis. You can ensure it is '
+          'installed by installing the redis beam extra')
+
   def get_read(self):
     """get_read returns a PTransform for reading from the cache."""
     ensure_coders_exist(self._request_coder)
diff --git a/sdks/python/setup.py b/sdks/python/setup.py
index 074d64ae892..289433f9ea5 100644
--- a/sdks/python/setup.py
+++ b/sdks/python/setup.py
@@ -402,7 +402,6 @@ if __name__ == '__main__':
           
'protobuf>=3.20.3,<7.0.0.dev0,!=4.0.*,!=4.21.*,!=4.22.0,!=4.23.*,!=4.24.*',  # 
pylint: disable=line-too-long
           'python-dateutil>=2.8.0,<3',
           'pytz>=2018.3',
-          'redis>=5.0.0,<6',
           'requests>=2.32.4,<3.0.0',
           'sortedcontainers>=2.4.0',
           'typing-extensions>=3.7.0',
@@ -588,6 +587,7 @@ if __name__ == '__main__':
               'torch==2.8.0+cpu',
               'transformers>=4.28.0,<4.56.0'
           ],
+          'redis': ['redis>=5.0.0,<6'],
           'tft': [
               'tensorflow_transform>=1.14.0,<1.15.0'
               # tensorflow-transform requires dill, but doesn't set dill as a
diff --git a/sdks/python/tox.ini b/sdks/python/tox.ini
index 7d84ca7a2c6..da0932728b2 100644
--- a/sdks/python/tox.ini
+++ b/sdks/python/tox.ini
@@ -33,7 +33,7 @@ pip_pre = True
 # allow apps that support color to use it.
 passenv=TERM,CLOUDSDK_CONFIG,DOCKER_*,TESTCONTAINERS_*,TC_*,ALLOYDB_PASSWORD
 # Set [] options for pip installation of apache-beam tarball.
-extras = test,dataframe,tfrecord,yaml
+extras = test,dataframe,redis,tfrecord,yaml
 # Don't warn that these commands aren't installed.
 allowlist_externals =
   false
@@ -97,7 +97,7 @@ install_command = {envbindir}/python.exe {envbindir}/pip.exe 
install --retries 1
 list_dependencies_command = {envbindir}/python.exe {envbindir}/pip.exe freeze
 
 [testenv:py{310,311,312,313}-cloud]
-; extras = test,gcp,interactive,dataframe,aws,azure
+; extras = test,gcp,interactive,dataframe,aws,azure,redis
 extras = test,gcp,interactive,dataframe,aws,azure
 commands =
   python apache_beam/examples/complete/autocomplete_test.py
@@ -173,7 +173,7 @@ setenv =
   TC_SLEEP_TIME = {env:TC_SLEEP_TIME:1}
 
 # NOTE: we could add ml_test to increase the collected code coverage metrics, 
but it would make the suite slower.
-extras = test,gcp,interactive,dataframe,aws
+extras = test,gcp,interactive,dataframe,aws,redis
 commands =
   bash {toxinidir}/scripts/run_pytest.sh {envname} "{posargs}" 
"--cov-report=xml --cov=. --cov-append"
 

Reply via email to