Skip to content

Commit 5073285

Browse files
committed
[GROW-2938] style fix
1 parent bc3192f commit 5073285

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

redis/cluster.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ def __init__(
592592
kwargs.update({"retry": self.retry})
593593
else:
594594
self.retry = Retry(default_backoff(), 0)
595-
kwargs['retry'] = self.retry
595+
kwargs["retry"] = self.retry
596596

597597
self.encoder = Encoder(
598598
kwargs.get("encoding", "utf-8"),
@@ -1095,7 +1095,9 @@ def execute_command(self, *args, **kwargs):
10951095
# Try again with the new cluster setup.
10961096
retry_attempts -= 1
10971097
if self.retry and isinstance(e, self.retry._supported_errors):
1098-
backoff = self.retry._backoff.compute(self.cluster_error_retry_attempts - retry_attempts)
1098+
backoff = self.retry._backoff.compute(
1099+
self.cluster_error_retry_attempts - retry_attempts
1100+
)
10991101
if backoff > 0:
11001102
time.sleep(backoff)
11011103
continue
@@ -1955,7 +1957,7 @@ def send_cluster_commands(
19551957
stack,
19561958
raise_on_error=raise_on_error,
19571959
allow_redirections=allow_redirections,
1958-
attempts_count=self.cluster_error_retry_attempts - retry_attempts
1960+
attempts_count=self.cluster_error_retry_attempts - retry_attempts,
19591961
)
19601962
except (ClusterDownError, ConnectionError, TimeoutError) as e:
19611963
if retry_attempts > 0:

tests/test_cluster.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
import pytest
1414

1515
from redis import Redis
16-
from redis.backoff import ExponentialBackoff, NoBackoff, default_backoff, ConstantBackoff
16+
from redis.backoff import (
17+
ExponentialBackoff,
18+
NoBackoff,
19+
default_backoff,
20+
ConstantBackoff,
21+
)
1722
from redis.cluster import (
1823
PRIMARY,
1924
REDIS_CLUSTER_HASH_SLOTS,
@@ -36,7 +41,8 @@
3641
RedisClusterException,
3742
RedisError,
3843
ResponseError,
39-
TimeoutError, SlotNotCoveredError,
44+
TimeoutError,
45+
SlotNotCoveredError,
4046
)
4147
from redis.retry import Retry
4248
from redis.utils import str_if_bytes
@@ -901,29 +907,33 @@ def address_remap(address):
901907
n_used = sum((1 if p.n_connections else 0) for p in proxies)
902908
assert n_used > 1
903909

904-
@pytest.mark.parametrize('error', [ConnectionError, TimeoutError])
910+
@pytest.mark.parametrize("error", [ConnectionError, TimeoutError])
905911
def test_additional_backoff_redis_cluster(self, error):
906912
with patch.object(ConstantBackoff, "compute") as compute:
913+
907914
def _compute(target_node, *args, **kwargs):
908915
return 1
909916

910917
compute.side_effect = _compute
911918
with patch.object(RedisCluster, "_execute_command") as execute_command:
919+
912920
def raise_error(target_node, *args, **kwargs):
913921
execute_command.failed_calls += 1
914922
raise error("mocked error")
915923

916924
execute_command.side_effect = raise_error
917925

918926
rc = get_mocked_redis_client(
919-
host=default_host, port=default_port, retry=Retry(ConstantBackoff(1), 3)
927+
host=default_host,
928+
port=default_port,
929+
retry=Retry(ConstantBackoff(1), 3),
920930
)
921931

922932
with pytest.raises(error):
923933
rc.get("bar")
924934
assert compute.call_count == rc.cluster_error_retry_attempts
925935

926-
@pytest.mark.parametrize('reinitialize_steps', [2, 10, 99])
936+
@pytest.mark.parametrize("reinitialize_steps", [2, 10, 99])
927937
def test_recover_slot_not_covered_error(self, request, reinitialize_steps):
928938
rc = _get_client(RedisCluster, request, reinitialize_steps=reinitialize_steps)
929939
key = uuid.uuid4().hex

0 commit comments

Comments
 (0)