Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbe84b93

Browse files
authored
Add support to BF.CARD (#2545)
* Add support to BF.CARD* Add Async test* change to with pytest.raises
1 parent7dd73a3 commitbe84b93

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

‎redis/commands/bf/__init__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ def __init__(self, client, **kwargs):
198198
# BF_MEXISTS: spaceHolder,
199199
# BF_SCANDUMP: spaceHolder,
200200
# BF_LOADCHUNK: spaceHolder,
201+
# BF_CARD: spaceHolder,
201202
BF_INFO:BFInfo,
202203
}
203204

‎redis/commands/bf/commands.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
BF_SCANDUMP="BF.SCANDUMP"
1212
BF_LOADCHUNK="BF.LOADCHUNK"
1313
BF_INFO="BF.INFO"
14+
BF_CARD="BF.CARD"
1415

1516
CF_RESERVE="CF.RESERVE"
1617
CF_ADD="CF.ADD"
@@ -165,6 +166,14 @@ def info(self, key):
165166
"""# noqa
166167
returnself.execute_command(BF_INFO,key)
167168

169+
defcard(self,key):
170+
"""
171+
Returns the cardinality of a Bloom filter - number of items that were added to a Bloom filter and detected as unique
172+
(items that caused at least one bit to be set in at least one sub-filter).
173+
For more information see `BF.CARD <https://redis.io/commands/bf.card>`_.
174+
"""# noqa
175+
returnself.execute_command(BF_CARD,key)
176+
168177

169178
classCFCommands:
170179
"""Cuckoo Filter commands."""

‎tests/test_asyncio/test_bloom.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,21 @@ async def test_bf_info(modclient: redis.Redis):
149149
assertTrue
150150

151151

152+
@pytest.mark.redismod
153+
asyncdeftest_bf_card(modclient:redis.Redis):
154+
# return 0 if the key does not exist
155+
assertawaitmodclient.bf().card("not_exist")==0
156+
157+
# Store a filter
158+
assertawaitmodclient.bf().add("bf1","item_foo")==1
159+
assertawaitmodclient.bf().card("bf1")==1
160+
161+
# Error when key is of a type other than Bloom filter.
162+
withpytest.raises(redis.ResponseError):
163+
awaitmodclient.set("setKey","value")
164+
awaitmodclient.bf().card("setKey")
165+
166+
152167
# region Test Cuckoo Filter
153168
@pytest.mark.redismod
154169
asyncdeftest_cf_add_and_insert(modclient:redis.Redis):

‎tests/test_bloom.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,21 @@ def test_bf_info(client):
165165
assertTrue
166166

167167

168+
@pytest.mark.redismod
169+
deftest_bf_card(client):
170+
# return 0 if the key does not exist
171+
assertclient.bf().card("not_exist")==0
172+
173+
# Store a filter
174+
assertclient.bf().add("bf1","item_foo")==1
175+
assertclient.bf().card("bf1")==1
176+
177+
# Error when key is of a type other than Bloom filter.
178+
withpytest.raises(redis.ResponseError):
179+
client.set("setKey","value")
180+
client.bf().card("setKey")
181+
182+
168183
# region Test Cuckoo Filter
169184
@pytest.mark.redismod
170185
deftest_cf_add_and_insert(client):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp