Skip to content

Commit 312abe2

Browse files
authored
Merge branch 'master' into catch-close-aclose-deprecation-warning
2 parents d067747 + c6faa65 commit 312abe2

File tree

11 files changed

+170
-88
lines changed

11 files changed

+170
-88
lines changed

.github/workflows/integration.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ env:
2828
# this speeds up coverage with Python 3.12: https://github.com/nedbat/coveragepy/issues/1665
2929
COVERAGE_CORE: sysmon
3030
REDIS_IMAGE: redis:7.4-rc2
31-
REDIS_STACK_IMAGE: redis/redis-stack-server:7.4.0-rc2
31+
REDIS_STACK_IMAGE: redis/redis-stack-server:latest
3232

3333
jobs:
3434
dependency-audit:

dev_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ invoke==2.2.0
88
mock
99
packaging>=20.4
1010
pytest
11-
pytest-asyncio
11+
pytest-asyncio>=0.23.0,<0.24.0
1212
pytest-cov
1313
pytest-profiling
1414
pytest-timeout

pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ timeout = 30
1414
filterwarnings =
1515
always
1616
ignore:RedisGraph support is deprecated as of Redis Stack 7.2:DeprecationWarning
17+
# Ignore a coverage warning when COVERAGE_CORE=sysmon for Pythons < 3.12.
18+
ignore:sys.monitoring isn't available:coverage.exceptions.CoverageWarning

redis/_parsers/helpers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,11 @@ def parse_cluster_info(response, **options):
445445
def _parse_node_line(line):
446446
line_items = line.split(" ")
447447
node_id, addr, flags, master_id, ping, pong, epoch, connected = line.split(" ")[:8]
448-
addr = addr.split("@")[0]
448+
ip = addr.split("@")[0]
449+
hostname = addr.split("@")[1].split(",")[1] if "@" in addr and "," in addr else ""
449450
node_dict = {
450451
"node_id": node_id,
452+
"hostname": hostname,
451453
"flags": flags,
452454
"master_id": master_id,
453455
"last_ping_sent": ping,
@@ -460,7 +462,7 @@ def _parse_node_line(line):
460462
if len(line_items) >= 9:
461463
slots, migrations = _parse_slots(line_items[8:])
462464
node_dict["slots"], node_dict["migrations"] = slots, migrations
463-
return addr, node_dict
465+
return ip, node_dict
464466

465467

466468
def _parse_slots(slot_ranges):

redis/asyncio/client.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,10 +579,12 @@ async def aclose(self, close_connection_pool: Optional[bool] = None) -> None:
579579
"""
580580
Closes Redis client connection
581581
582-
:param close_connection_pool: decides whether to close the connection pool used
583-
by this Redis client, overriding Redis.auto_close_connection_pool. By default,
584-
let Redis.auto_close_connection_pool decide whether to close the connection
585-
pool.
582+
Args:
583+
close_connection_pool:
584+
decides whether to close the connection pool used by this Redis client,
585+
overriding Redis.auto_close_connection_pool.
586+
By default, let Redis.auto_close_connection_pool decide
587+
whether to close the connection pool.
586588
"""
587589
conn = self.connection
588590
if conn:

redis/commands/core.py

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
from .helpers import list_or_args
4747

4848
if TYPE_CHECKING:
49-
from redis.asyncio.client import Redis as AsyncRedis
50-
from redis.client import Redis
49+
import redis.asyncio.client
50+
import redis.client
5151

5252

5353
class ACLCommands(CommandsProtocol):
@@ -731,16 +731,19 @@ def client_pause(self, timeout: int, all: bool = True, **kwargs) -> ResponseT:
731731
732732
For more information see https://redis.io/commands/client-pause
733733
734-
:param timeout: milliseconds to pause clients
735-
:param all: If true (default) all client commands are blocked.
736-
otherwise, clients are only blocked if they attempt to execute
737-
a write command.
734+
Args:
735+
timeout: milliseconds to pause clients
736+
all: If true (default) all client commands are blocked.
737+
otherwise, clients are only blocked if they attempt to execute
738+
a write command.
739+
738740
For the WRITE mode, some commands have special behavior:
739-
EVAL/EVALSHA: Will block client for all scripts.
740-
PUBLISH: Will block client.
741-
PFCOUNT: Will block client.
742-
WAIT: Acknowledgments will be delayed, so this command will
743-
appear blocked.
741+
742+
* EVAL/EVALSHA: Will block client for all scripts.
743+
* PUBLISH: Will block client.
744+
* PFCOUNT: Will block client.
745+
* WAIT: Acknowledgments will be delayed, so this command will
746+
appear blocked.
744747
"""
745748
args = ["CLIENT PAUSE", str(timeout)]
746749
if not isinstance(timeout, int):
@@ -1439,7 +1442,7 @@ class BitFieldOperation:
14391442

14401443
def __init__(
14411444
self,
1442-
client: Union["Redis", "AsyncRedis"],
1445+
client: Union["redis.client.Redis", "redis.asyncio.client.Redis"],
14431446
key: str,
14441447
default_overflow: Union[str, None] = None,
14451448
):
@@ -1583,7 +1586,7 @@ def bitcount(
15831586
return self.execute_command("BITCOUNT", *params, keys=[key])
15841587

15851588
def bitfield(
1586-
self: Union["Redis", "AsyncRedis"],
1589+
self: Union["redis.client.Redis", "redis.asyncio.client.Redis"],
15871590
key: KeyT,
15881591
default_overflow: Union[str, None] = None,
15891592
) -> BitFieldOperation:
@@ -1596,7 +1599,7 @@ def bitfield(
15961599
return BitFieldOperation(self, key, default_overflow=default_overflow)
15971600

15981601
def bitfield_ro(
1599-
self: Union["Redis", "AsyncRedis"],
1602+
self: Union["redis.client.Redis", "redis.asyncio.client.Redis"],
16001603
key: KeyT,
16011604
encoding: str,
16021605
offset: BitfieldOffsetT,
@@ -5464,7 +5467,7 @@ class Script:
54645467
An executable Lua script object returned by ``register_script``
54655468
"""
54665469

5467-
def __init__(self, registered_client: "Redis", script: ScriptTextT):
5470+
def __init__(self, registered_client: "redis.client.Redis", script: ScriptTextT):
54685471
self.registered_client = registered_client
54695472
self.script = script
54705473
# Precalculate and store the SHA1 hex digest of the script.
@@ -5484,7 +5487,7 @@ def __call__(
54845487
self,
54855488
keys: Union[Sequence[KeyT], None] = None,
54865489
args: Union[Iterable[EncodableT], None] = None,
5487-
client: Union["Redis", None] = None,
5490+
client: Union["redis.client.Redis", None] = None,
54885491
):
54895492
"""Execute the script, passing any required ``args``"""
54905493
keys = keys or []
@@ -5513,7 +5516,11 @@ class AsyncScript:
55135516
An executable Lua script object returned by ``register_script``
55145517
"""
55155518

5516-
def __init__(self, registered_client: "AsyncRedis", script: ScriptTextT):
5519+
def __init__(
5520+
self,
5521+
registered_client: "redis.asyncio.client.Redis",
5522+
script: ScriptTextT,
5523+
):
55175524
self.registered_client = registered_client
55185525
self.script = script
55195526
# Precalculate and store the SHA1 hex digest of the script.
@@ -5533,7 +5540,7 @@ async def __call__(
55335540
self,
55345541
keys: Union[Sequence[KeyT], None] = None,
55355542
args: Union[Iterable[EncodableT], None] = None,
5536-
client: Union["AsyncRedis", None] = None,
5543+
client: Union["redis.asyncio.client.Redis", None] = None,
55375544
):
55385545
"""Execute the script, passing any required ``args``"""
55395546
keys = keys or []
@@ -5758,7 +5765,7 @@ def script_load(self, script: ScriptTextT) -> ResponseT:
57585765
"""
57595766
return self.execute_command("SCRIPT LOAD", script)
57605767

5761-
def register_script(self: "Redis", script: ScriptTextT) -> Script:
5768+
def register_script(self: "redis.client.Redis", script: ScriptTextT) -> Script:
57625769
"""
57635770
Register a Lua ``script`` specifying the ``keys`` it will touch.
57645771
Returns a Script object that is callable and hides the complexity of
@@ -5772,7 +5779,10 @@ class AsyncScriptCommands(ScriptCommands):
57725779
async def script_debug(self, *args) -> None:
57735780
return super().script_debug()
57745781

5775-
def register_script(self: "AsyncRedis", script: ScriptTextT) -> AsyncScript:
5782+
def register_script(
5783+
self: "redis.asyncio.client.Redis",
5784+
script: ScriptTextT,
5785+
) -> AsyncScript:
57765786
"""
57775787
Register a Lua ``script`` specifying the ``keys`` it will touch.
57785788
Returns a Script object that is callable and hides the complexity of
@@ -6415,9 +6425,12 @@ def function_list(
64156425
) -> Union[Awaitable[List], List]:
64166426
"""
64176427
Return information about the functions and libraries.
6418-
:param library: pecify a pattern for matching library names
6419-
:param withcode: cause the server to include the libraries source
6420-
implementation in the reply
6428+
6429+
Args:
6430+
6431+
library: specify a pattern for matching library names
6432+
withcode: cause the server to include the libraries source implementation
6433+
in the reply
64216434
"""
64226435
args = ["LIBRARYNAME", library]
64236436
if withcode:

redis/commands/search/aggregation.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def __init__(self, query: str = "*") -> None:
111111
self._verbatim = False
112112
self._cursor = []
113113
self._dialect = None
114+
self._add_scores = False
114115

115116
def load(self, *fields: List[str]) -> "AggregateRequest":
116117
"""
@@ -292,6 +293,13 @@ def with_schema(self) -> "AggregateRequest":
292293
self._with_schema = True
293294
return self
294295

296+
def add_scores(self) -> "AggregateRequest":
297+
"""
298+
If set, includes the score as an ordinary field of the row.
299+
"""
300+
self._add_scores = True
301+
return self
302+
295303
def verbatim(self) -> "AggregateRequest":
296304
self._verbatim = True
297305
return self
@@ -315,6 +323,9 @@ def build_args(self) -> List[str]:
315323
if self._verbatim:
316324
ret.append("VERBATIM")
317325

326+
if self._add_scores:
327+
ret.append("ADDSCORES")
328+
318329
if self._cursor:
319330
ret += self._cursor
320331

redis/commands/timeseries/commands.py

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ def create(
6060
duplicate_policy:
6161
Policy for handling multiple samples with identical timestamps. Can be
6262
one of:
63-
- 'block': An error will occur and the new value will be ignored.
64-
- 'first': Ignore the new value.
65-
- 'last': Override with the latest value.
66-
- 'min': Only override if the value is lower than the existing
67-
value.
68-
- 'max': Only override if the value is higher than the existing
69-
value.
70-
- 'sum': If a previous sample exists, add the new sample to it so
71-
that the updated value is equal to (previous + new). If no
72-
previous sample exists, set the updated value equal to the new
73-
value.
63+
64+
- 'block': An error will occur and the new value will be ignored.
65+
- 'first': Ignore the new value.
66+
- 'last': Override with the latest value.
67+
- 'min': Only override if the value is lower than the existing value.
68+
- 'max': Only override if the value is higher than the existing value.
69+
- 'sum': If a previous sample exists, add the new sample to it so
70+
that the updated value is equal to (previous + new). If no
71+
previous sample exists, set the updated value equal to the new
72+
value.
73+
7474
ignore_max_time_diff:
7575
A non-negative integer value, in milliseconds, that sets an ignore
7676
threshold for added timestamps. If the difference between the last
@@ -130,17 +130,17 @@ def alter(
130130
duplicate_policy:
131131
Policy for handling multiple samples with identical timestamps. Can be
132132
one of:
133-
- 'block': An error will occur and the new value will be ignored.
134-
- 'first': Ignore the new value.
135-
- 'last': Override with the latest value.
136-
- 'min': Only override if the value is lower than the existing
137-
value.
138-
- 'max': Only override if the value is higher than the existing
139-
value.
140-
- 'sum': If a previous sample exists, add the new sample to it so
141-
that the updated value is equal to (previous + new). If no
142-
previous sample exists, set the updated value equal to the new
143-
value.
133+
134+
- 'block': An error will occur and the new value will be ignored.
135+
- 'first': Ignore the new value.
136+
- 'last': Override with the latest value.
137+
- 'min': Only override if the value is lower than the existing value.
138+
- 'max': Only override if the value is higher than the existing value.
139+
- 'sum': If a previous sample exists, add the new sample to it so
140+
that the updated value is equal to (previous + new). If no
141+
previous sample exists, set the updated value equal to the new
142+
value.
143+
144144
ignore_max_time_diff:
145145
A non-negative integer value, in milliseconds, that sets an ignore
146146
threshold for added timestamps. If the difference between the last
@@ -210,17 +210,17 @@ def add(
210210
duplicate_policy:
211211
Policy for handling multiple samples with identical timestamps. Can be
212212
one of:
213-
- 'block': An error will occur and the new value will be ignored.
214-
- 'first': Ignore the new value.
215-
- 'last': Override with the latest value.
216-
- 'min': Only override if the value is lower than the existing
217-
value.
218-
- 'max': Only override if the value is higher than the existing
219-
value.
220-
- 'sum': If a previous sample exists, add the new sample to it so
221-
that the updated value is equal to (previous + new). If no
222-
previous sample exists, set the updated value equal to the new
223-
value.
213+
214+
- 'block': An error will occur and the new value will be ignored.
215+
- 'first': Ignore the new value.
216+
- 'last': Override with the latest value.
217+
- 'min': Only override if the value is lower than the existing value.
218+
- 'max': Only override if the value is higher than the existing value.
219+
- 'sum': If a previous sample exists, add the new sample to it so
220+
that the updated value is equal to (previous + new). If no
221+
previous sample exists, set the updated value equal to the new
222+
value.
223+
224224
ignore_max_time_diff:
225225
A non-negative integer value, in milliseconds, that sets an ignore
226226
threshold for added timestamps. If the difference between the last
@@ -331,17 +331,17 @@ def incrby(
331331
duplicate_policy:
332332
Policy for handling multiple samples with identical timestamps. Can be
333333
one of:
334-
- 'block': An error will occur and the new value will be ignored.
335-
- 'first': Ignore the new value.
336-
- 'last': Override with the latest value.
337-
- 'min': Only override if the value is lower than the existing
338-
value.
339-
- 'max': Only override if the value is higher than the existing
340-
value.
341-
- 'sum': If a previous sample exists, add the new sample to it so
342-
that the updated value is equal to (previous + new). If no
343-
previous sample exists, set the updated value equal to the new
344-
value.
334+
335+
- 'block': An error will occur and the new value will be ignored.
336+
- 'first': Ignore the new value.
337+
- 'last': Override with the latest value.
338+
- 'min': Only override if the value is lower than the existing value.
339+
- 'max': Only override if the value is higher than the existing value.
340+
- 'sum': If a previous sample exists, add the new sample to it so
341+
that the updated value is equal to (previous + new). If no
342+
previous sample exists, set the updated value equal to the new
343+
value.
344+
345345
ignore_max_time_diff:
346346
A non-negative integer value, in milliseconds, that sets an ignore
347347
threshold for added timestamps. If the difference between the last
@@ -423,17 +423,17 @@ def decrby(
423423
duplicate_policy:
424424
Policy for handling multiple samples with identical timestamps. Can be
425425
one of:
426-
- 'block': An error will occur and the new value will be ignored.
427-
- 'first': Ignore the new value.
428-
- 'last': Override with the latest value.
429-
- 'min': Only override if the value is lower than the existing
430-
value.
431-
- 'max': Only override if the value is higher than the existing
432-
value.
433-
- 'sum': If a previous sample exists, add the new sample to it so
434-
that the updated value is equal to (previous + new). If no
435-
previous sample exists, set the updated value equal to the new
436-
value.
426+
427+
- 'block': An error will occur and the new value will be ignored.
428+
- 'first': Ignore the new value.
429+
- 'last': Override with the latest value.
430+
- 'min': Only override if the value is lower than the existing value.
431+
- 'max': Only override if the value is higher than the existing value.
432+
- 'sum': If a previous sample exists, add the new sample to it so
433+
that the updated value is equal to (previous + new). If no
434+
previous sample exists, set the updated value equal to the new
435+
value.
436+
437437
ignore_max_time_diff:
438438
A non-negative integer value, in milliseconds, that sets an ignore
439439
threshold for added timestamps. If the difference between the last

0 commit comments

Comments
 (0)