Skip to content

Commit cbabe8a

Browse files
authored
Merge branch 'master' into async_cluster_typing
2 parents ca09cb9 + 84418d6 commit cbabe8a

File tree

5 files changed

+55
-69
lines changed

5 files changed

+55
-69
lines changed

redis/asyncio/cluster.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,8 @@ def __init__(
748748
server_type: Optional[str] = None,
749749
max_connections: int = 2 ** 31,
750750
connection_class: Type[Connection] = Connection,
751-
**connection_kwargs: Any,
751+
response_callbacks: Dict = RedisCluster.RESPONSE_CALLBACKS,
752+
**connection_kwargs,
752753
) -> None:
753754
if host == "localhost":
754755
host = socket.gethostbyname(host)

redis/commands/bf/commands.py

Lines changed: 40 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
CF_INSERT = "CF.INSERT"
1919
CF_INSERTNX = "CF.INSERTNX"
2020
CF_EXISTS = "CF.EXISTS"
21+
CF_MEXISTS = "CF.MEXISTS"
2122
CF_DEL = "CF.DEL"
2223
CF_COUNT = "CF.COUNT"
2324
CF_SCANDUMP = "CF.SCANDUMP"
@@ -59,7 +60,7 @@ def create(self, key, errorRate, capacity, expansion=None, noScale=None):
5960
Create a new Bloom Filter `key` with desired probability of false positives
6061
`errorRate` expected entries to be inserted as `capacity`.
6162
Default expansion value is 2. By default, filter is auto-scaling.
62-
For more information see `BF.RESERVE <https://oss.redis.com/redisbloom/master/Bloom_Commands/#bfreserve>`_.
63+
For more information see `BF.RESERVE <https://redis.io/commands/bf.reserve>`_.
6364
""" # noqa
6465
params = [key, errorRate, capacity]
6566
self.append_expansion(params, expansion)
@@ -69,19 +70,16 @@ def create(self, key, errorRate, capacity, expansion=None, noScale=None):
6970
def add(self, key, item):
7071
"""
7172
Add to a Bloom Filter `key` an `item`.
72-
For more information see `BF.ADD <https://oss.redis.com/redisbloom/master/Bloom_Commands/#bfadd>`_.
73+
For more information see `BF.ADD <https://redis.io/commands/bf.add>`_.
7374
""" # noqa
74-
params = [key, item]
75-
return self.execute_command(BF_ADD, *params)
75+
return self.execute_command(BF_ADD, key, item)
7676

7777
def madd(self, key, *items):
7878
"""
7979
Add to a Bloom Filter `key` multiple `items`.
80-
For more information see `BF.MADD <https://oss.redis.com/redisbloom/master/Bloom_Commands/#bfmadd>`_.
80+
For more information see `BF.MADD <https://redis.io/commands/bf.madd>`_.
8181
""" # noqa
82-
params = [key]
83-
params += items
84-
return self.execute_command(BF_MADD, *params)
82+
return self.execute_command(BF_MADD, key, *items)
8583

8684
def insert(
8785
self,
@@ -99,7 +97,7 @@ def insert(
9997
If `nocreate` remain `None` and `key` does not exist, a new Bloom Filter
10098
`key` will be created with desired probability of false positives `errorRate`
10199
and expected entries to be inserted as `size`.
102-
For more information see `BF.INSERT <https://oss.redis.com/redisbloom/master/Bloom_Commands/#bfinsert>`_.
100+
For more information see `BF.INSERT <https://redis.io/commands/bf.insert>`_.
103101
""" # noqa
104102
params = [key]
105103
self.append_capacity(params, capacity)
@@ -114,19 +112,16 @@ def insert(
114112
def exists(self, key, item):
115113
"""
116114
Check whether an `item` exists in Bloom Filter `key`.
117-
For more information see `BF.EXISTS <https://oss.redis.com/redisbloom/master/Bloom_Commands/#bfexists>`_.
115+
For more information see `BF.EXISTS <https://redis.io/commands/bf.exists>`_.
118116
""" # noqa
119-
params = [key, item]
120-
return self.execute_command(BF_EXISTS, *params)
117+
return self.execute_command(BF_EXISTS, key, item)
121118

122119
def mexists(self, key, *items):
123120
"""
124121
Check whether `items` exist in Bloom Filter `key`.
125-
For more information see `BF.MEXISTS <https://oss.redis.com/redisbloom/master/Bloom_Commands/#bfmexists>`_.
122+
For more information see `BF.MEXISTS <https://redis.io/commands/bf.mexists>`_.
126123
""" # noqa
127-
params = [key]
128-
params += items
129-
return self.execute_command(BF_MEXISTS, *params)
124+
return self.execute_command(BF_MEXISTS, key, *items)
130125

131126
def scandump(self, key, iter):
132127
"""
@@ -135,7 +130,7 @@ def scandump(self, key, iter):
135130
This is useful for large bloom filters which cannot fit into the normal SAVE and RESTORE model.
136131
The first time this command is called, the value of `iter` should be 0.
137132
This command will return successive (iter, data) pairs until (0, NULL) to indicate completion.
138-
For more information see `BF.SCANDUMP <https://oss.redis.com/redisbloom/master/Bloom_Commands/#bfscandump>`_.
133+
For more information see `BF.SCANDUMP <https://redis.io/commands/bf.scandump>`_.
139134
""" # noqa
140135
if HIREDIS_AVAILABLE:
141136
raise ModuleError("This command cannot be used when hiredis is available.")
@@ -152,15 +147,14 @@ def loadchunk(self, key, iter, data):
152147
See the SCANDUMP command for example usage.
153148
This command will overwrite any bloom filter stored under key.
154149
Ensure that the bloom filter will not be modified between invocations.
155-
For more information see `BF.LOADCHUNK <https://oss.redis.com/redisbloom/master/Bloom_Commands/#bfloadchunk>`_.
150+
For more information see `BF.LOADCHUNK <https://redis.io/commands/bf.loadchunk>`_.
156151
""" # noqa
157-
params = [key, iter, data]
158-
return self.execute_command(BF_LOADCHUNK, *params)
152+
return self.execute_command(BF_LOADCHUNK, key, iter, data)
159153

160154
def info(self, key):
161155
"""
162156
Return capacity, size, number of filters, number of items inserted, and expansion rate.
163-
For more information see `BF.INFO <https://oss.redis.com/redisbloom/master/Bloom_Commands/#bfinfo>`_.
157+
For more information see `BF.INFO <https://redis.io/commands/bf.info>`_.
164158
""" # noqa
165159
return self.execute_command(BF_INFO, key)
166160

@@ -187,17 +181,15 @@ def add(self, key, item):
187181
Add an `item` to a Cuckoo Filter `key`.
188182
For more information see `CF.ADD <https://redis.io/commands/cf.add>`_.
189183
""" # noqa
190-
params = [key, item]
191-
return self.execute_command(CF_ADD, *params)
184+
return self.execute_command(CF_ADD, key, item)
192185

193186
def addnx(self, key, item):
194187
"""
195188
Add an `item` to a Cuckoo Filter `key` only if item does not yet exist.
196189
Command might be slower that `add`.
197190
For more information see `CF.ADDNX <https://redis.io/commands/cf.addnx>`_.
198191
""" # noqa
199-
params = [key, item]
200-
return self.execute_command(CF_ADDNX, *params)
192+
return self.execute_command(CF_ADDNX, key, item)
201193

202194
def insert(self, key, items, capacity=None, nocreate=None):
203195
"""
@@ -230,24 +222,28 @@ def exists(self, key, item):
230222
Check whether an `item` exists in Cuckoo Filter `key`.
231223
For more information see `CF.EXISTS <https://redis.io/commands/cf.exists>`_.
232224
""" # noqa
233-
params = [key, item]
234-
return self.execute_command(CF_EXISTS, *params)
225+
return self.execute_command(CF_EXISTS, key, item)
226+
227+
def mexists(self, key, *items):
228+
"""
229+
Check whether an `items` exist in Cuckoo Filter `key`.
230+
For more information see `CF.MEXISTS <https://redis.io/commands/cf.mexists>`_.
231+
""" # noqa
232+
return self.execute_command(CF_MEXISTS, key, *items)
235233

236234
def delete(self, key, item):
237235
"""
238236
Delete `item` from `key`.
239237
For more information see `CF.DEL <https://redis.io/commands/cf.del>`_.
240238
""" # noqa
241-
params = [key, item]
242-
return self.execute_command(CF_DEL, *params)
239+
return self.execute_command(CF_DEL, key, item)
243240

244241
def count(self, key, item):
245242
"""
246243
Return the number of times an `item` may be in the `key`.
247244
For more information see `CF.COUNT <https://redis.io/commands/cf.count>`_.
248245
""" # noqa
249-
params = [key, item]
250-
return self.execute_command(CF_COUNT, *params)
246+
return self.execute_command(CF_COUNT, key, item)
251247

252248
def scandump(self, key, iter):
253249
"""
@@ -260,8 +256,7 @@ def scandump(self, key, iter):
260256
(0, NULL) to indicate completion.
261257
For more information see `CF.SCANDUMP <https://redis.io/commands/cf.scandump>`_.
262258
""" # noqa
263-
params = [key, iter]
264-
return self.execute_command(CF_SCANDUMP, *params)
259+
return self.execute_command(CF_SCANDUMP, key, iter)
265260

266261
def loadchunk(self, key, iter, data):
267262
"""
@@ -271,8 +266,7 @@ def loadchunk(self, key, iter, data):
271266
Ensure that the Cuckoo filter will not be modified between invocations.
272267
For more information see `CF.LOADCHUNK <https://redis.io/commands/cf.loadchunk>`_.
273268
""" # noqa
274-
params = [key, iter, data]
275-
return self.execute_command(CF_LOADCHUNK, *params)
269+
return self.execute_command(CF_LOADCHUNK, key, iter, data)
276270

277271
def info(self, key):
278272
"""
@@ -292,17 +286,14 @@ def reserve(self, key, k, width, depth, decay):
292286
positives `errorRate` expected entries to be inserted as `size`.
293287
For more information see `TOPK.RESERVE <https://redis.io/commands/topk.reserve>`_.
294288
""" # noqa
295-
params = [key, k, width, depth, decay]
296-
return self.execute_command(TOPK_RESERVE, *params)
289+
return self.execute_command(TOPK_RESERVE, key, k, width, depth, decay)
297290

298291
def add(self, key, *items):
299292
"""
300293
Add one `item` or more to a Top-K Filter `key`.
301294
For more information see `TOPK.ADD <https://redis.io/commands/topk.add>`_.
302295
""" # noqa
303-
params = [key]
304-
params += items
305-
return self.execute_command(TOPK_ADD, *params)
296+
return self.execute_command(TOPK_ADD, key, *items)
306297

307298
def incrby(self, key, items, increments):
308299
"""
@@ -323,18 +314,14 @@ def query(self, key, *items):
323314
Check whether one `item` or more is a Top-K item at `key`.
324315
For more information see `TOPK.QUERY <https://redis.io/commands/topk.query>`_.
325316
""" # noqa
326-
params = [key]
327-
params += items
328-
return self.execute_command(TOPK_QUERY, *params)
317+
return self.execute_command(TOPK_QUERY, key, *items)
329318

330319
def count(self, key, *items):
331320
"""
332321
Return count for one `item` or more from `key`.
333322
For more information see `TOPK.COUNT <https://redis.io/commands/topk.count>`_.
334323
""" # noqa
335-
params = [key]
336-
params += items
337-
return self.execute_command(TOPK_COUNT, *params)
324+
return self.execute_command(TOPK_COUNT, key, *items)
338325

339326
def list(self, key, withcount=False):
340327
"""
@@ -362,8 +349,7 @@ def create(self, key, compression):
362349
Allocate the memory and initialize the t-digest.
363350
For more information see `TDIGEST.CREATE <https://redis.io/commands/tdigest.create>`_.
364351
""" # noqa
365-
params = [key, compression]
366-
return self.execute_command(TDIGEST_CREATE, *params)
352+
return self.execute_command(TDIGEST_CREATE, key, compression)
367353

368354
def reset(self, key):
369355
"""
@@ -391,8 +377,7 @@ def merge(self, toKey, fromKey):
391377
Merge all of the values from 'fromKey' to 'toKey' sketch.
392378
For more information see `TDIGEST.MERGE <https://redis.io/commands/tdigest.merge>`_.
393379
""" # noqa
394-
params = [toKey, fromKey]
395-
return self.execute_command(TDIGEST_MERGE, *params)
380+
return self.execute_command(TDIGEST_MERGE, toKey, fromKey)
396381

397382
def min(self, key):
398383
"""
@@ -414,16 +399,14 @@ def quantile(self, key, quantile):
414399
added to this TDigest would be less than or equal to the cutoff.
415400
For more information see `TDIGEST.QUANTILE <https://redis.io/commands/tdigest.quantile>`_.
416401
""" # noqa
417-
params = [key, quantile]
418-
return self.execute_command(TDIGEST_QUANTILE, *params)
402+
return self.execute_command(TDIGEST_QUANTILE, key, quantile)
419403

420404
def cdf(self, key, value):
421405
"""
422406
Return double fraction of all points added which are <= value.
423407
For more information see `TDIGEST.CDF <https://redis.io/commands/tdigest.cdf>`_.
424408
""" # noqa
425-
params = [key, value]
426-
return self.execute_command(TDIGEST_CDF, *params)
409+
return self.execute_command(TDIGEST_CDF, key, value)
427410

428411
def info(self, key):
429412
"""
@@ -443,16 +426,14 @@ def initbydim(self, key, width, depth):
443426
Initialize a Count-Min Sketch `key` to dimensions (`width`, `depth`) specified by user.
444427
For more information see `CMS.INITBYDIM <https://redis.io/commands/cms.initbydim>`_.
445428
""" # noqa
446-
params = [key, width, depth]
447-
return self.execute_command(CMS_INITBYDIM, *params)
429+
return self.execute_command(CMS_INITBYDIM, key, width, depth)
448430

449431
def initbyprob(self, key, error, probability):
450432
"""
451433
Initialize a Count-Min Sketch `key` to characteristics (`error`, `probability`) specified by user.
452434
For more information see `CMS.INITBYPROB <https://redis.io/commands/cms.initbyprob>`_.
453435
""" # noqa
454-
params = [key, error, probability]
455-
return self.execute_command(CMS_INITBYPROB, *params)
436+
return self.execute_command(CMS_INITBYPROB, key, error, probability)
456437

457438
def incrby(self, key, items, increments):
458439
"""
@@ -473,9 +454,7 @@ def query(self, key, *items):
473454
Return count for an `item` from `key`. Multiple items can be queried with one call.
474455
For more information see `CMS.QUERY <https://redis.io/commands/cms.query>`_.
475456
""" # noqa
476-
params = [key]
477-
params += items
478-
return self.execute_command(CMS_QUERY, *params)
457+
return self.execute_command(CMS_QUERY, key, *items)
479458

480459
def merge(self, destKey, numKeys, srcKeys, weights=[]):
481460
"""

redis/commands/core.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2593,15 +2593,15 @@ def lpop(self, name: str, count: Optional[int] = None) -> Union[str, List, None]
25932593
else:
25942594
return self.execute_command("LPOP", name)
25952595

2596-
def lpush(self, name: str, *values: List) -> Union[Awaitable[int], int]:
2596+
def lpush(self, name: str, *values: FieldT) -> Union[Awaitable[int], int]:
25972597
"""
25982598
Push ``values`` onto the head of the list ``name``
25992599
26002600
For more information see https://redis.io/commands/lpush
26012601
"""
26022602
return self.execute_command("LPUSH", name, *values)
26032603

2604-
def lpushx(self, name: str, *values: List) -> Union[Awaitable[int], int]:
2604+
def lpushx(self, name: str, *values: FieldT) -> Union[Awaitable[int], int]:
26052605
"""
26062606
Push ``value`` onto the head of the list ``name`` if ``name`` exists
26072607
@@ -2679,7 +2679,7 @@ def rpoplpush(self, src: str, dst: str) -> Union[Awaitable[str], str]:
26792679
"""
26802680
return self.execute_command("RPOPLPUSH", src, dst)
26812681

2682-
def rpush(self, name: str, *values: List) -> Union[Awaitable[int], int]:
2682+
def rpush(self, name: str, *values: FieldT) -> Union[Awaitable[int], int]:
26832683
"""
26842684
Push ``values`` onto the tail of the list ``name``
26852685
@@ -3169,7 +3169,7 @@ class SetCommands(CommandsProtocol):
31693169
see: https://redis.io/topics/data-types#sets
31703170
"""
31713171

3172-
def sadd(self, name: str, *values: List) -> Union[Awaitable[int], int]:
3172+
def sadd(self, name: str, *values: FieldT) -> Union[Awaitable[int], int]:
31733173
"""
31743174
Add ``value(s)`` to set ``name``
31753175
@@ -3307,7 +3307,7 @@ def srandmember(
33073307
args = (number is not None) and [number] or []
33083308
return self.execute_command("SRANDMEMBER", name, *args)
33093309

3310-
def srem(self, name: str, *values: List) -> Union[Awaitable[int], int]:
3310+
def srem(self, name: str, *values: FieldT) -> Union[Awaitable[int], int]:
33113311
"""
33123312
Remove ``values`` from set ``name``
33133313
@@ -4586,7 +4586,7 @@ def zrank(self, name: KeyT, value: EncodableT) -> ResponseT:
45864586
"""
45874587
return self.execute_command("ZRANK", name, value)
45884588

4589-
def zrem(self, name: KeyT, *values: EncodableT) -> ResponseT:
4589+
def zrem(self, name: KeyT, *values: FieldT) -> ResponseT:
45904590
"""
45914591
Remove member ``values`` from sorted set ``name``
45924592
@@ -4735,7 +4735,7 @@ class HyperlogCommands(CommandsProtocol):
47354735
see: https://redis.io/topics/data-types-intro#hyperloglogs
47364736
"""
47374737

4738-
def pfadd(self, name: KeyT, *values: EncodableT) -> ResponseT:
4738+
def pfadd(self, name: KeyT, *values: FieldT) -> ResponseT:
47394739
"""
47404740
Adds the specified elements to the specified HyperLogLog.
47414741

tests/test_asyncio/test_cluster.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ async def test_startup_nodes(self) -> None:
227227

228228
await cluster.close()
229229

230+
startup_nodes = [ClusterNode("127.0.0.1", 16379)]
231+
async with RedisCluster(startup_nodes=startup_nodes) as rc:
232+
assert await rc.set("A", 1)
233+
assert await rc.get("A") == b"1"
234+
230235
async def test_empty_startup_nodes(self) -> None:
231236
"""
232237
Test that exception is raised when empty providing empty startup_nodes

tests/test_bloom.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ def test_cf_exists_and_del(client):
173173
assert client.cf().add("cuckoo", "filter")
174174
assert client.cf().exists("cuckoo", "filter")
175175
assert not client.cf().exists("cuckoo", "notexist")
176+
assert [1, 0] == client.cf().mexists("cuckoo", "filter", "notexist")
176177
assert 1 == client.cf().count("cuckoo", "filter")
177178
assert 0 == client.cf().count("cuckoo", "notexist")
178179
assert client.cf().delete("cuckoo", "filter")

0 commit comments

Comments
 (0)