Skip to content

Commit 6657339

Browse files
committed
lints
1 parent 10089c0 commit 6657339

File tree

5 files changed

+34
-27
lines changed

5 files changed

+34
-27
lines changed

redis/asyncio/sentinel.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ async def _connect_retry(self, same_address: bool = False):
6060
if self._reader:
6161
return # already connected
6262
# If same_server is True, it means that the connection
63-
# is not rotating to the next slave (if the connection pool is not master)
63+
# is not rotating to the next slave (if the connection pool is in replica mode)
6464
if same_address:
6565
self.connect_to(self.host, self.port)
6666
return
67-
# If same_server is False, connnect to master in master mode
67+
# If same_server is False, connnect to master in master mode
6868
# and rotate to the next slave in slave mode
6969
if self.connection_pool.is_master:
7070
await self.connect_to(await self.connection_pool.get_master_address())
@@ -84,7 +84,7 @@ async def connect(self):
8484

8585
async def connect_to_same_address(self):
8686
"""
87-
Similar to connect, but instead of rotating to the next slave (if not in master mode),
87+
Similar to connect, but instead of rotating to the next slave (in replica mode),
8888
it just connects to the same address of the connection object.
8989
"""
9090
return await self.retry.call_with_retry(
@@ -94,7 +94,7 @@ async def connect_to_same_address(self):
9494

9595
async def connect_to_address(self, address):
9696
"""
97-
Similar to connect, but instead of rotating to the next slave (if not in master mode),
97+
Similar to connect, but instead of rotating to the next slave (in replica mode),
9898
it just connects to the same address of the connection object.
9999
"""
100100
self.host, self.port = address
@@ -202,13 +202,15 @@ async def rotate_slaves(self) -> AsyncIterator:
202202
pass
203203
raise SlaveNotFoundError(f"No slave found for {self.service_name!r}")
204204

205-
async def ensure_connection_connected_to_address(self, connection: SentinelManagedConnection):
205+
async def ensure_connection_connected_to_address(
206+
self, connection: SentinelManagedConnection
207+
):
206208
"""
207209
Ensure the connection is already connected to the server that this connection
208210
object wants to connect to
209211
210212
Similar to self.ensure_connection, but calling connection.connect()
211-
in SentinelManagedConnection (replica mode) will cause the
213+
in SentinelManagedConnection (replica mode) will cause the
212214
connection object to connect to the next replica in rotation,
213215
and we don't wnat behavior. Look at get_connection inline docs for details.
214216
@@ -217,7 +219,10 @@ async def ensure_connection_connected_to_address(self, connection: SentinelManag
217219
"""
218220
await connection.connect_to_same_address()
219221
try:
220-
if await connection.can_read_destructive() and connection.client_cache is None:
222+
if (
223+
await connection.can_read_destructive()
224+
and connection.client_cache is None
225+
):
221226
raise ConnectionError("Connection has data")
222227
except (ConnectionError, OSError):
223228
await connection.disconnect()
@@ -273,7 +278,7 @@ async def get_connection(
273278
host=server_host, port=server_port
274279
)
275280
# If not, make a new dummy connection object, and set its host and
276-
# port to the one that we want later in the call to ``connect_to_same_address``
281+
# port to the one that we want later in the call to ``connect_to_address``
277282
if not connection:
278283
connection = self.make_connection()
279284
assert connection

redis/client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,6 @@ def reset(self) -> None:
763763
self.patterns = {}
764764
self.pending_unsubscribe_patterns = set()
765765
self.subscribed_event.clear()
766-
self.connection_pool.cleanup(iter_req_id=options.get("_iter_req_id", None))
767766

768767
def close(self) -> None:
769768
self.reset()

redis/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,10 +737,10 @@ def _host_error(self):
737737

738738
class ConnectionsIndexer(Iterable):
739739
"""
740-
Data structure that simulates a list of available connections.
740+
Data structure that simulates a list of available connections.
741741
Instead of list, we keep 2 additional DS to support O(1) operations
742742
on all of the class' methods.
743-
The first DS is indexed on the connection object's ID.
743+
The first DS is indexed on the connection object's ID.
744744
The second DS is indexed on the address (ip and port) of the connection.
745745
"""
746746

redis/sentinel.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def _connect_retry(self, same_address: bool = False):
4949
if same_address:
5050
self.connect_to((self.host, self.port))
5151
return
52-
# If same_server is False, connnect to master in master mode
52+
# If same_server is False, connnect to master in master mode
5353
# and rotate to the next slave in slave mode
5454
if self.connection_pool.is_master:
5555
self.connect_to(self.connection_pool.get_master_address())
@@ -62,11 +62,14 @@ def _connect_retry(self, same_address: bool = False):
6262
raise SlaveNotFoundError # Never be here
6363

6464
def connect(self):
65-
return self.retry.call_with_retry(lambda: self._connect_retry(), lambda error: None)
65+
return self.retry.call_with_retry(
66+
lambda: self._connect_retry(),
67+
lambda error: None
68+
)
6669

6770
def connect_to_same_address(self):
6871
"""
69-
Similar to connect, but instead of rotating to the next slave (if not in master mode),
72+
Similar to connect, but instead of rotating to the next slave (in replica mode),
7073
it just connects to the same address of the connection object.
7174
"""
7275
return self.retry.call_with_retry(
@@ -76,14 +79,17 @@ def connect_to_same_address(self):
7679

7780
def connect_to_address(self, address):
7881
"""
79-
Similar to connect, but instead of rotating to the next slave (if not in master mode),
82+
Similar to connect, but instead of rotating to the next slave (in replica mode),
8083
it just connects to the address supplied.
8184
"""
8285
self.host, self.port = address
8386
return self.connect_to_same_address()
8487

8588
def can_read_same_address(self, timeout=0):
86-
"""Similar to can_read_same_address, but calls connect_to_same_address instead of connect"""
89+
"""
90+
Similar to can_read_same_address, but calls
91+
connect_to_same_address instead of connect
92+
"""
8793
sock = self._sock
8894
if not sock:
8995
self.connect_to_same_address()
@@ -234,13 +240,15 @@ def rotate_slaves(self):
234240
"Round-robin slave balancer"
235241
return self.proxy.rotate_slaves()
236242

237-
def ensure_connection_connected_to_address(self, connection: SentinelManagedConnection):
243+
def ensure_connection_connected_to_address(
244+
self, connection: SentinelManagedConnection
245+
):
238246
"""
239247
Ensure the connection is already connected to the server that this connection
240-
object wants to connect to
248+
object wants to connect to.
241249
242250
Similar to self.ensure_connection, but calling connection.connect()
243-
in SentinelManagedConnection (replica mode) will cause the
251+
in SentinelManagedConnection (replica mode) will cause the
244252
connection object to connect to the next replica in rotation,
245253
and we don't wnat behavior. Look at get_connection inline docs for details.
246254

tests/test_sentinel_managed_connection.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
from unittest import mock
33

44
import pytest
5-
from redis.sentinel import (
6-
Sentinel,
7-
SentinelConnectionPool,
8-
SentinelManagedConnection,
9-
)
5+
from redis import Redis
6+
from redis.sentinel import Sentinel, SentinelConnectionPool, SentinelManagedConnection
7+
108

119
class SentinelManagedConnectionMock(SentinelManagedConnection):
1210
def connect_to_same_address(self) -> None:
@@ -211,8 +209,6 @@ def test_scan_iter_in_redis_cleans_up(
211209
connection_pool_replica_mock: SentinelConnectionPool,
212210
):
213211
"""Test that connection pool is correctly cleaned up"""
214-
from redis import Redis
215-
216212
r = Redis(connection_pool=connection_pool_replica_mock)
217213
# Patch the actual sending and parsing response from the Connection object
218214
# but still let the connection pool does all the necessary work
@@ -221,4 +217,3 @@ def test_scan_iter_in_redis_cleans_up(
221217
# Test that the iter_req_id for the scan command is cleared at the
222218
# end of the SCAN ITER command
223219
assert not connection_pool_replica_mock._iter_req_id_to_replica_address
224-

0 commit comments

Comments
 (0)