diff --git a/clients/python/pyproject.toml b/clients/python/pyproject.toml index f8a84ff3..5965c62d 100644 --- a/clients/python/pyproject.toml +++ b/clients/python/pyproject.toml @@ -15,7 +15,6 @@ dependencies = [ "orjson>=3.10.10", "protobuf>=5.28.3", "redis>=3.4.1", - "redis-py-cluster>=2.1.0", "zstandard>=0.18.0", ] @@ -34,6 +33,11 @@ dev = [ "types-protobuf>=5.27.0.20240626,<6.0.0", ] [project.optional-dependencies] +# redis<4 does not bundle cluster support; pull in redis-py-cluster (EOL) for it. +# Not needed on redis>=4.1, which provides redis.RedisCluster natively. +cluster = [ + "redis-py-cluster>=2.1.0", +] examples = [ "click>=8.3", "setuptools>=80.0", diff --git a/clients/python/src/taskbroker_client/scheduler/storage.py b/clients/python/src/taskbroker_client/scheduler/storage.py index 70ebb442..92fca58a 100644 --- a/clients/python/src/taskbroker_client/scheduler/storage.py +++ b/clients/python/src/taskbroker_client/scheduler/storage.py @@ -2,10 +2,16 @@ from collections.abc import Mapping from datetime import UTC, datetime -from typing import Protocol +from typing import TYPE_CHECKING, Protocol from redis.client import StrictRedis -from rediscluster import RedisCluster + +if TYPE_CHECKING: + try: + # redis>=4.1 ships cluster support natively + from redis import RedisCluster + except ImportError: # pragma: no cover - redis<4 fallback via the `cluster` extra + from rediscluster import RedisCluster from taskbroker_client.metrics import MetricsBackend @@ -105,9 +111,7 @@ class RunStorage(RunStorageProtocol): Redis backed scheduler storage """ - def __init__( - self, metrics: MetricsBackend, redis: RedisCluster[str] | StrictRedis[str] - ) -> None: + def __init__(self, metrics: MetricsBackend, redis: RedisCluster | StrictRedis) -> None: self._redis = redis self._metrics = metrics