Skip to content

Commit 92dd23a

Browse files
committed
fix inline comments + rename
1 parent adb1ed0 commit 92dd23a

8 files changed

+39
-38
lines changed

redis/asyncio/connection.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,9 +1059,7 @@ class ConnectionPool:
10591059

10601060
def cleanup(self, **options):
10611061
"""
1062-
Additional cleanup operations that the connection pool might
1063-
need to do after a SCAN ITER family command is executed.
1064-
1062+
Additional cleanup operations that the connection pool might need to do.
10651063
See SentinelManagedConnection for an example cleanup operation that
10661064
might need to be done.
10671065
"""

redis/asyncio/sentinel.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ class SentinelManagedConnection(Connection):
3737
def __init__(self, **kwargs):
3838
self.connection_pool = kwargs.pop("connection_pool")
3939
# To be set to True if we want to prevent
40-
# the sentinel managed connection to connect
41-
# to the most relevant sentinel in the pool and just
42-
# connect to the current self.host and self.port
43-
self._is_address_fixed = False
40+
# the connection to connect to the most relevant sentinel
41+
# in the pool and just connect to the current host and port
42+
self._is_address_set = False
4443
super().__init__(**kwargs)
4544

4645
def __repr__(self):
@@ -54,9 +53,13 @@ def __repr__(self):
5453
s += host_info
5554
return s + ")>"
5655

57-
def fix_address(self, address):
56+
def set_address(self, address):
57+
"""
58+
By setting the address, the connection will just connect
59+
to the current host and port the next time connect is called.
60+
"""
5861
self.host, self.port = address
59-
self._is_address_fixed = True
62+
self._is_address_set = True
6063

6164
async def connect_to(self, address):
6265
self.host, self.port = address
@@ -70,15 +73,13 @@ async def _connect_retry(self):
7073
if self._reader:
7174
return # already connected
7275
# If address is fixed, it means that the connection
73-
# is not rotating to the next slave (if the connection pool is in replica mode)
74-
if self._is_address_fixed:
76+
# just connect to the current host and port
77+
if self._is_address_set:
7578
await self.connect_to((self.host, self.port))
7679
return
7780
await self._connect_to_sentinel()
7881

7982
async def _connect_to_sentinel(self):
80-
# If same_server is False, connnect to master in master mode
81-
# and rotate to the next slave in slave mode
8283
if self.connection_pool.is_master:
8384
await self.connect_to(await self.connection_pool.get_master_address())
8485
else:
@@ -246,7 +247,7 @@ async def get_connection(
246247
host=server_host, port=server_port
247248
)
248249
# If not, make a new dummy connection object, and set its host and
249-
# port to the one that we want later in the call to ``connect_to_address``
250+
# port to the one that we want later in the call to ``set_address``
250251
if not connection:
251252
connection = self.make_connection()
252253
assert connection
@@ -261,7 +262,7 @@ async def get_connection(
261262
# connect to the previous replica.
262263
# This will connect to the host and port of the replica
263264
else:
264-
connection.fix_address((server_host, server_port))
265+
connection.set_address((server_host, server_port))
265266
await self.ensure_connection(connection)
266267
except BaseException:
267268
# Release the connection back to the pool so that we don't

redis/connection.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,9 +1106,7 @@ def __repr__(self) -> (str, str):
11061106

11071107
def cleanup(self, **options):
11081108
"""
1109-
Additional cleanup operations that the connection pool might
1110-
need to do after a SCAN ITER family command is executed.
1111-
1109+
Additional cleanup operations that the connection pool might need to do.
11121110
See SentinelManagedConnection for an example cleanup operation that
11131111
might need to be done.
11141112
"""

redis/sentinel.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, **kwargs):
2525
# the sentinel managed connection to connect
2626
# to the most relevant sentinel in the pool and just
2727
# connect to the current self.host and self.port
28-
self._is_address_fixed = False
28+
self._is_address_set = False
2929
super().__init__(**kwargs)
3030

3131
def __repr__(self):
@@ -39,9 +39,13 @@ def __repr__(self):
3939
s = s % host_info
4040
return s
4141

42-
def fix_address(self, address):
42+
def set_address(self, address):
43+
"""
44+
By setting the address, the connection will just connect
45+
to the current host and port the next time connect is called.
46+
"""
4347
self.host, self.port = address
44-
self._is_address_fixed = True
48+
self._is_address_set = True
4549

4650
def connect_to(self, address):
4751
self.host, self.port = address
@@ -54,16 +58,14 @@ def connect_to(self, address):
5458
def _connect_retry(self):
5559
if self._sock:
5660
return # already connected
57-
# If address is fixed, it means that the connection
58-
# is not rotating to the next slave (if the connection pool is not master)
59-
if self._is_address_fixed:
61+
# If address is set, it means that the connection
62+
# will just connect to the current host and port.
63+
if self._is_address_set:
6064
self.connect_to((self.host, self.port))
6165
return
6266
self._connect_to_sentinel()
6367

6468
def _connect_to_sentinel(self):
65-
# If same_server is False, connnect to master in master mode
66-
# and rotate to the next slave in slave mode
6769
if self.connection_pool.is_master:
6870
self.connect_to(self.connection_pool.get_master_address())
6971
else:
@@ -317,7 +319,7 @@ def get_connection(
317319
host=server_host, port=server_port
318320
)
319321
# If not, make a new dummy connection object, and set its host and port
320-
# to the one that we want later in the call to ``fix_address``
322+
# to the one that we want later in the call to ``set_address``
321323
if not connection:
322324
connection = self.make_connection()
323325
assert connection
@@ -332,7 +334,7 @@ def get_connection(
332334
# connect to the previous replica.
333335
# This will connect to the host and port of the replica
334336
else:
335-
connection.fix_address((server_host, server_port))
337+
connection.set_address((server_host, server_port))
336338
self.ensure_connection(connection)
337339
except BaseException:
338340
# Release the connection back to the pool so that we don't

tests/test_asyncio/test_commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,7 @@ async def test_zscan_iter(self, r: redis.Redis):
14021402
pairs = [k async for k in r.zscan_iter("a", match="a")]
14031403
assert set(pairs) == {(b"a", 1)}
14041404

1405-
async def test_scan_iter_family_executes_commands_with_sameiter_req_id(self):
1405+
async def test_scan_iter_family_executes_commands_with_same_iter_req_id(self):
14061406
"""Assert that all calls to execute_command receives the iter_req_id kwarg"""
14071407
import uuid
14081408

tests/test_asyncio/test_sentinel_managed_connection.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ class SentinelManagedConnectionMock(SentinelManagedConnection):
4747
async def _connect_to_sentinel(self) -> None:
4848
"""
4949
This simulates the behavior of _connect_to_sentinel when
50-
:py:class:`~redis.SentinelConnectionPool`
51-
is in replica mode.
52-
It'll call rotate_slaves and connect to the next replica.
50+
:py:class:`~redis.asyncio.sentinel.SentinelConnectionPool`.
51+
In master mode, it'll connect to the master.
52+
In non-master mode, it'll call rotate_slaves and connect to the next replica.
5353
"""
5454
if self.connection_pool.is_master:
5555
self.host, self.port = ("master", 1)
@@ -62,7 +62,8 @@ async def _connect_to_sentinel(self) -> None:
6262

6363
async def connect_to(self, address: Tuple[str, int]) -> None:
6464
"""
65-
Do nothing, just mock.
65+
Do nothing, just mock so it won't try to make a connection to the
66+
dummy address.
6667
"""
6768

6869

tests/test_commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2235,7 +2235,7 @@ def test_zscan_iter(self, r):
22352235
pairs = list(r.zscan_iter("a", match="a"))
22362236
assert set(pairs) == {(b"a", 1)}
22372237

2238-
def test_scan_iter_family_executes_commands_with_sameiter_req_id(self):
2238+
def test_scan_iter_family_executes_commands_with_same_iter_req_id(self):
22392239
"""Assert that all calls to execute_command receives the iter_req_id kwarg"""
22402240
import uuid
22412241

tests/test_sentinel_managed_connection.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ class SentinelManagedConnectionMock(SentinelManagedConnection):
1313
def _connect_to_sentinel(self) -> None:
1414
"""
1515
This simulates the behavior of _connect_to_sentinel when
16-
:py:class:`~redis.SentinelConnectionPool`
17-
is in replica mode.
18-
It'll call rotate_slaves and connect to the next replica.
16+
:py:class:`~redis.SentinelConnectionPool`.
17+
In master mode, it'll connect to the master.
18+
In non-master mode, it'll call rotate_slaves and connect to the next replica.
1919
"""
2020
if self.connection_pool.is_master:
2121
self.host, self.port = ("master", 1)
@@ -28,7 +28,8 @@ def _connect_to_sentinel(self) -> None:
2828

2929
def connect_to(self, address: Tuple[str, int]) -> None:
3030
"""
31-
Do nothing, this is just to mock.
31+
Do nothing, just mock so it won't try to make a connection to the
32+
dummy address.
3233
"""
3334
pass
3435

0 commit comments

Comments
 (0)