coredis 5.5.0__cp313-cp313-macosx_11_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 22fe76227e35f92ab5c3__mypyc.cpython-313-darwin.so +0 -0
- coredis/__init__.py +42 -0
- coredis/_enum.py +42 -0
- coredis/_json.py +11 -0
- coredis/_packer.cpython-313-darwin.so +0 -0
- coredis/_packer.py +71 -0
- coredis/_protocols.py +50 -0
- coredis/_py_311_typing.py +20 -0
- coredis/_py_312_typing.py +17 -0
- coredis/_sidecar.py +114 -0
- coredis/_utils.cpython-313-darwin.so +0 -0
- coredis/_utils.py +440 -0
- coredis/_version.py +34 -0
- coredis/_version.pyi +1 -0
- coredis/cache.py +801 -0
- coredis/client/__init__.py +6 -0
- coredis/client/basic.py +1240 -0
- coredis/client/cluster.py +1265 -0
- coredis/commands/__init__.py +64 -0
- coredis/commands/_key_spec.py +517 -0
- coredis/commands/_utils.py +108 -0
- coredis/commands/_validators.py +159 -0
- coredis/commands/_wrappers.py +175 -0
- coredis/commands/bitfield.py +110 -0
- coredis/commands/constants.py +662 -0
- coredis/commands/core.py +8484 -0
- coredis/commands/function.py +408 -0
- coredis/commands/monitor.py +168 -0
- coredis/commands/pubsub.py +905 -0
- coredis/commands/request.py +108 -0
- coredis/commands/script.py +296 -0
- coredis/commands/sentinel.py +246 -0
- coredis/config.py +50 -0
- coredis/connection.py +906 -0
- coredis/constants.cpython-313-darwin.so +0 -0
- coredis/constants.py +37 -0
- coredis/credentials.py +45 -0
- coredis/exceptions.py +360 -0
- coredis/experimental/__init__.py +1 -0
- coredis/globals.py +23 -0
- coredis/modules/__init__.py +121 -0
- coredis/modules/autocomplete.py +138 -0
- coredis/modules/base.py +262 -0
- coredis/modules/filters.py +1319 -0
- coredis/modules/graph.py +362 -0
- coredis/modules/json.py +691 -0
- coredis/modules/response/__init__.py +0 -0
- coredis/modules/response/_callbacks/__init__.py +0 -0
- coredis/modules/response/_callbacks/autocomplete.py +42 -0
- coredis/modules/response/_callbacks/graph.py +237 -0
- coredis/modules/response/_callbacks/json.py +21 -0
- coredis/modules/response/_callbacks/search.py +221 -0
- coredis/modules/response/_callbacks/timeseries.py +158 -0
- coredis/modules/response/types.py +179 -0
- coredis/modules/search.py +1089 -0
- coredis/modules/timeseries.py +1139 -0
- coredis/parser.cpython-313-darwin.so +0 -0
- coredis/parser.py +344 -0
- coredis/pipeline.py +1225 -0
- coredis/pool/__init__.py +11 -0
- coredis/pool/basic.py +453 -0
- coredis/pool/cluster.py +517 -0
- coredis/pool/nodemanager.py +340 -0
- coredis/py.typed +0 -0
- coredis/recipes/__init__.py +0 -0
- coredis/recipes/credentials/__init__.py +5 -0
- coredis/recipes/credentials/iam_provider.py +63 -0
- coredis/recipes/locks/__init__.py +5 -0
- coredis/recipes/locks/extend.lua +17 -0
- coredis/recipes/locks/lua_lock.py +281 -0
- coredis/recipes/locks/release.lua +10 -0
- coredis/response/__init__.py +5 -0
- coredis/response/_callbacks/__init__.py +538 -0
- coredis/response/_callbacks/acl.py +32 -0
- coredis/response/_callbacks/cluster.py +183 -0
- coredis/response/_callbacks/command.py +86 -0
- coredis/response/_callbacks/connection.py +31 -0
- coredis/response/_callbacks/geo.py +58 -0
- coredis/response/_callbacks/hash.py +85 -0
- coredis/response/_callbacks/keys.py +59 -0
- coredis/response/_callbacks/module.py +33 -0
- coredis/response/_callbacks/script.py +85 -0
- coredis/response/_callbacks/sentinel.py +179 -0
- coredis/response/_callbacks/server.py +241 -0
- coredis/response/_callbacks/sets.py +44 -0
- coredis/response/_callbacks/sorted_set.py +204 -0
- coredis/response/_callbacks/streams.py +185 -0
- coredis/response/_callbacks/strings.py +70 -0
- coredis/response/_callbacks/vector_sets.py +159 -0
- coredis/response/_utils.py +33 -0
- coredis/response/types.py +416 -0
- coredis/retry.py +233 -0
- coredis/sentinel.py +477 -0
- coredis/stream.py +369 -0
- coredis/tokens.py +2286 -0
- coredis/typing.py +593 -0
- coredis-5.5.0.dist-info/METADATA +211 -0
- coredis-5.5.0.dist-info/RECORD +100 -0
- coredis-5.5.0.dist-info/WHEEL +6 -0
- coredis-5.5.0.dist-info/licenses/LICENSE +23 -0
|
@@ -0,0 +1,1319 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from deprecated.sphinx import versionadded
|
|
4
|
+
|
|
5
|
+
from .._utils import dict_to_flat_list
|
|
6
|
+
from ..commands._validators import mutually_inclusive_parameters
|
|
7
|
+
from ..commands.constants import CommandFlag, CommandGroup, CommandName
|
|
8
|
+
from ..commands.request import CommandRequest
|
|
9
|
+
from ..response._callbacks import (
|
|
10
|
+
BoolCallback,
|
|
11
|
+
BoolsCallback,
|
|
12
|
+
DictCallback,
|
|
13
|
+
FirstValueCallback,
|
|
14
|
+
FloatCallback,
|
|
15
|
+
FloatsCallback,
|
|
16
|
+
IntCallback,
|
|
17
|
+
MixedTupleCallback,
|
|
18
|
+
SimpleStringCallback,
|
|
19
|
+
TupleCallback,
|
|
20
|
+
)
|
|
21
|
+
from ..tokens import PrefixToken, PureToken
|
|
22
|
+
from ..typing import (
|
|
23
|
+
AnyStr,
|
|
24
|
+
CommandArgList,
|
|
25
|
+
KeyT,
|
|
26
|
+
Literal,
|
|
27
|
+
Mapping,
|
|
28
|
+
Parameters,
|
|
29
|
+
ResponsePrimitive,
|
|
30
|
+
StringT,
|
|
31
|
+
ValueT,
|
|
32
|
+
)
|
|
33
|
+
from .base import Module, ModuleGroup, module_command
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class RedisBloom(Module[AnyStr]):
|
|
37
|
+
NAME = "bf"
|
|
38
|
+
FULL_NAME = "RedisBloom"
|
|
39
|
+
DESCRIPTION = """RedisBloom is a Redis module that implements various probabilistic
|
|
40
|
+
data structures such as BloomFilter.
|
|
41
|
+
"""
|
|
42
|
+
DOCUMENTATION_URL = "https://redis.io/docs/stack/bloom/"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@versionadded(version="4.12")
|
|
46
|
+
class BloomFilter(ModuleGroup[AnyStr]):
|
|
47
|
+
MODULE = RedisBloom
|
|
48
|
+
COMMAND_GROUP = CommandGroup.BF
|
|
49
|
+
|
|
50
|
+
@module_command(
|
|
51
|
+
CommandName.BF_RESERVE,
|
|
52
|
+
group=COMMAND_GROUP,
|
|
53
|
+
version_introduced="1.0.0",
|
|
54
|
+
module=MODULE,
|
|
55
|
+
)
|
|
56
|
+
def reserve(
|
|
57
|
+
self,
|
|
58
|
+
key: KeyT,
|
|
59
|
+
error_rate: int | float,
|
|
60
|
+
capacity: int,
|
|
61
|
+
expansion: int | None = None,
|
|
62
|
+
nonscaling: bool | None = None,
|
|
63
|
+
) -> CommandRequest[bool]:
|
|
64
|
+
"""
|
|
65
|
+
Creates a new Bloom Filter
|
|
66
|
+
|
|
67
|
+
:param key: The key under which the filter is found.
|
|
68
|
+
:param error_rate: The desired probability for false positives.
|
|
69
|
+
:param capacity: The number of entries intended to be added to the filter.
|
|
70
|
+
:param expansion: The size of the new sub-filter when `capacity` is reached.
|
|
71
|
+
:param nonscaling: Prevents the filter from creating additional sub-filters.
|
|
72
|
+
"""
|
|
73
|
+
command_arguments: CommandArgList = [key, error_rate, capacity]
|
|
74
|
+
if expansion is not None:
|
|
75
|
+
command_arguments.extend([PrefixToken.EXPANSION, expansion])
|
|
76
|
+
if nonscaling:
|
|
77
|
+
command_arguments.append(PureToken.NONSCALING)
|
|
78
|
+
|
|
79
|
+
return self.client.create_request(
|
|
80
|
+
CommandName.BF_RESERVE, *command_arguments, callback=SimpleStringCallback()
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
@module_command(
|
|
84
|
+
CommandName.BF_ADD,
|
|
85
|
+
group=COMMAND_GROUP,
|
|
86
|
+
version_introduced="1.0.0",
|
|
87
|
+
module=MODULE,
|
|
88
|
+
)
|
|
89
|
+
def add(self, key: KeyT, item: ValueT) -> CommandRequest[bool]:
|
|
90
|
+
"""
|
|
91
|
+
Adds an item to a Bloom Filter
|
|
92
|
+
|
|
93
|
+
:param key: The key under which the filter is found.
|
|
94
|
+
:param item: The item to add to the filter.
|
|
95
|
+
"""
|
|
96
|
+
command_arguments: CommandArgList = [key, item]
|
|
97
|
+
|
|
98
|
+
return self.client.create_request(
|
|
99
|
+
CommandName.BF_ADD, *command_arguments, callback=BoolCallback()
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
@module_command(
|
|
103
|
+
CommandName.BF_MADD,
|
|
104
|
+
group=COMMAND_GROUP,
|
|
105
|
+
version_introduced="1.0.0",
|
|
106
|
+
module=MODULE,
|
|
107
|
+
)
|
|
108
|
+
def madd(self, key: KeyT, items: Parameters[ValueT]) -> CommandRequest[tuple[bool, ...]]:
|
|
109
|
+
"""
|
|
110
|
+
Adds one or more items to a Bloom Filter. A filter will be created if it does not exist
|
|
111
|
+
|
|
112
|
+
:param key: The key under which the filter is found.
|
|
113
|
+
:param items: One or more items to add.
|
|
114
|
+
"""
|
|
115
|
+
command_arguments: CommandArgList = [key, *items]
|
|
116
|
+
|
|
117
|
+
return self.client.create_request(
|
|
118
|
+
CommandName.BF_MADD, *command_arguments, callback=BoolsCallback()
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
@module_command(
|
|
122
|
+
CommandName.BF_INSERT,
|
|
123
|
+
group=COMMAND_GROUP,
|
|
124
|
+
version_introduced="1.0.0",
|
|
125
|
+
module=MODULE,
|
|
126
|
+
)
|
|
127
|
+
def insert(
|
|
128
|
+
self,
|
|
129
|
+
key: KeyT,
|
|
130
|
+
items: Parameters[ValueT],
|
|
131
|
+
capacity: int | None = None,
|
|
132
|
+
error: int | float | None = None,
|
|
133
|
+
expansion: int | None = None,
|
|
134
|
+
nocreate: bool | None = None,
|
|
135
|
+
nonscaling: bool | None = None,
|
|
136
|
+
) -> CommandRequest[tuple[bool, ...]]:
|
|
137
|
+
"""
|
|
138
|
+
Adds one or more items to a Bloom Filter. A filter will be created if it
|
|
139
|
+
does not exist
|
|
140
|
+
|
|
141
|
+
:param key: The key under which the filter is found.
|
|
142
|
+
:param items: One or more items to add.
|
|
143
|
+
:param capacity: The desired capacity for the filter to be created.
|
|
144
|
+
:param error: The error ratio of the newly created filter if it does not yet exist.
|
|
145
|
+
:param expansion: The expansion factor for the filter when capacity is reached.
|
|
146
|
+
:param nocreate: Indicates that the filter should not be created if it does not
|
|
147
|
+
already exist.
|
|
148
|
+
:param nonscaling: Prevents the filter from creating additional sub-filters
|
|
149
|
+
if initial capacity is reached.
|
|
150
|
+
"""
|
|
151
|
+
command_arguments: CommandArgList = [key]
|
|
152
|
+
if capacity is not None:
|
|
153
|
+
command_arguments.extend([PrefixToken.CAPACITY, capacity])
|
|
154
|
+
if error is not None:
|
|
155
|
+
command_arguments.extend([PrefixToken.ERROR, error])
|
|
156
|
+
if expansion is not None:
|
|
157
|
+
command_arguments.extend([PrefixToken.EXPANSION, expansion])
|
|
158
|
+
if nocreate:
|
|
159
|
+
command_arguments.append(PureToken.NOCREATE)
|
|
160
|
+
if nonscaling:
|
|
161
|
+
command_arguments.append(PureToken.NONSCALING)
|
|
162
|
+
command_arguments.append(PureToken.ITEMS)
|
|
163
|
+
command_arguments.extend(items)
|
|
164
|
+
return self.client.create_request(
|
|
165
|
+
CommandName.BF_INSERT, *command_arguments, callback=BoolsCallback()
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
@module_command(
|
|
169
|
+
CommandName.BF_EXISTS,
|
|
170
|
+
group=COMMAND_GROUP,
|
|
171
|
+
version_introduced="1.0.0",
|
|
172
|
+
module=MODULE,
|
|
173
|
+
flags={CommandFlag.READONLY},
|
|
174
|
+
cacheable=True,
|
|
175
|
+
)
|
|
176
|
+
def exists(self, key: KeyT, item: ValueT) -> CommandRequest[bool]:
|
|
177
|
+
"""
|
|
178
|
+
Checks whether an item exists in a Bloom Filter
|
|
179
|
+
|
|
180
|
+
:param key: The key under which the filter is found.
|
|
181
|
+
:param item: The item to check for existence.
|
|
182
|
+
"""
|
|
183
|
+
return self.client.create_request(CommandName.BF_EXISTS, key, item, callback=BoolCallback())
|
|
184
|
+
|
|
185
|
+
@module_command(
|
|
186
|
+
CommandName.BF_MEXISTS,
|
|
187
|
+
group=COMMAND_GROUP,
|
|
188
|
+
version_introduced="1.0.0",
|
|
189
|
+
module=MODULE,
|
|
190
|
+
flags={CommandFlag.READONLY},
|
|
191
|
+
cacheable=True,
|
|
192
|
+
)
|
|
193
|
+
def mexists(self, key: KeyT, items: Parameters[ValueT]) -> CommandRequest[tuple[bool, ...]]:
|
|
194
|
+
"""
|
|
195
|
+
Checks whether one or more items exist in a Bloom Filter
|
|
196
|
+
|
|
197
|
+
:param key: The key under which the filter is found.
|
|
198
|
+
:param items: One or more items to check.
|
|
199
|
+
"""
|
|
200
|
+
return self.client.create_request(
|
|
201
|
+
CommandName.BF_MEXISTS, key, *items, callback=BoolsCallback()
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
@module_command(
|
|
205
|
+
CommandName.BF_SCANDUMP,
|
|
206
|
+
group=COMMAND_GROUP,
|
|
207
|
+
version_introduced="1.0.0",
|
|
208
|
+
module=MODULE,
|
|
209
|
+
)
|
|
210
|
+
def scandump(self, key: KeyT, iterator: int) -> CommandRequest[tuple[int, bytes | None]]:
|
|
211
|
+
"""
|
|
212
|
+
Begins an incremental save of the bloom filter
|
|
213
|
+
|
|
214
|
+
:param key: The key under which the filter is found.
|
|
215
|
+
:param iterator: Iterator value; either 0 to start a dump or the iterator
|
|
216
|
+
from a previous invocation of this command.
|
|
217
|
+
|
|
218
|
+
:return: A tuple of iterator value and data. If iterator is 0, iteration has
|
|
219
|
+
completed. The iterator-data pair should be passed to :meth:`loadchunk` when
|
|
220
|
+
restoring the filter.
|
|
221
|
+
"""
|
|
222
|
+
|
|
223
|
+
return self.client.create_request(
|
|
224
|
+
CommandName.BF_SCANDUMP,
|
|
225
|
+
key,
|
|
226
|
+
iterator,
|
|
227
|
+
callback=MixedTupleCallback[int, bytes | None](),
|
|
228
|
+
execution_parameters={"decode": False},
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
@module_command(
|
|
232
|
+
CommandName.BF_LOADCHUNK,
|
|
233
|
+
group=COMMAND_GROUP,
|
|
234
|
+
version_introduced="1.0.0",
|
|
235
|
+
module=MODULE,
|
|
236
|
+
)
|
|
237
|
+
def loadchunk(self, key: KeyT, iterator: int, data: bytes) -> CommandRequest[bool]:
|
|
238
|
+
"""
|
|
239
|
+
Restores a filter previously saved using :meth:`scandump`
|
|
240
|
+
|
|
241
|
+
:param key: Name of the key to restore.
|
|
242
|
+
:param iterator: Iterator value associated with the data chunk.
|
|
243
|
+
:param data: Current data chunk.
|
|
244
|
+
"""
|
|
245
|
+
command_arguments: CommandArgList = [key, iterator, data]
|
|
246
|
+
|
|
247
|
+
return self.client.create_request(
|
|
248
|
+
CommandName.BF_LOADCHUNK,
|
|
249
|
+
*command_arguments,
|
|
250
|
+
callback=SimpleStringCallback(),
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
@module_command(
|
|
254
|
+
CommandName.BF_INFO,
|
|
255
|
+
group=COMMAND_GROUP,
|
|
256
|
+
version_introduced="1.0.0",
|
|
257
|
+
module=MODULE,
|
|
258
|
+
flags={CommandFlag.READONLY},
|
|
259
|
+
cacheable=True,
|
|
260
|
+
)
|
|
261
|
+
def info(
|
|
262
|
+
self,
|
|
263
|
+
key: KeyT,
|
|
264
|
+
single_value: None
|
|
265
|
+
| (
|
|
266
|
+
Literal[
|
|
267
|
+
PureToken.CAPACITY,
|
|
268
|
+
PureToken.EXPANSION,
|
|
269
|
+
PureToken.FILTERS,
|
|
270
|
+
PureToken.ITEMS,
|
|
271
|
+
PureToken.SIZE,
|
|
272
|
+
]
|
|
273
|
+
) = None,
|
|
274
|
+
) -> CommandRequest[int] | CommandRequest[dict[AnyStr, int]]:
|
|
275
|
+
"""
|
|
276
|
+
Returns information about a Bloom Filter
|
|
277
|
+
|
|
278
|
+
:param key: The key name for an existing Bloom filter.
|
|
279
|
+
:param single_value: Optional parameter to get a specific information field.
|
|
280
|
+
|
|
281
|
+
:return: A dictionary with all information fields if :paramref:`single_value`
|
|
282
|
+
is not specified, or an integer representing the value of the specified field.
|
|
283
|
+
"""
|
|
284
|
+
if single_value:
|
|
285
|
+
return self.client.create_request(
|
|
286
|
+
CommandName.BF_INFO,
|
|
287
|
+
key,
|
|
288
|
+
single_value,
|
|
289
|
+
callback=FirstValueCallback[int](),
|
|
290
|
+
)
|
|
291
|
+
else:
|
|
292
|
+
return self.client.create_request(
|
|
293
|
+
CommandName.BF_INFO, key, callback=DictCallback[AnyStr, int]()
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
@module_command(
|
|
297
|
+
CommandName.BF_CARD,
|
|
298
|
+
group=COMMAND_GROUP,
|
|
299
|
+
version_introduced="2.4.4",
|
|
300
|
+
module=MODULE,
|
|
301
|
+
flags={CommandFlag.READONLY},
|
|
302
|
+
cacheable=True,
|
|
303
|
+
)
|
|
304
|
+
def card(self, key: KeyT) -> CommandRequest[int]:
|
|
305
|
+
"""
|
|
306
|
+
Returns the cardinality of a Bloom filter
|
|
307
|
+
|
|
308
|
+
:param key: The key name for an existing Bloom filter.
|
|
309
|
+
"""
|
|
310
|
+
return self.client.create_request(CommandName.BF_CARD, key, callback=IntCallback())
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
@versionadded(version="4.12")
|
|
314
|
+
class CuckooFilter(ModuleGroup[AnyStr]):
|
|
315
|
+
MODULE = RedisBloom
|
|
316
|
+
COMMAND_GROUP = CommandGroup.CF
|
|
317
|
+
|
|
318
|
+
@module_command(
|
|
319
|
+
CommandName.CF_RESERVE,
|
|
320
|
+
group=COMMAND_GROUP,
|
|
321
|
+
version_introduced="1.0.0",
|
|
322
|
+
module=MODULE,
|
|
323
|
+
)
|
|
324
|
+
def reserve(
|
|
325
|
+
self,
|
|
326
|
+
key: KeyT,
|
|
327
|
+
capacity: int,
|
|
328
|
+
bucketsize: int | None = None,
|
|
329
|
+
maxiterations: int | None = None,
|
|
330
|
+
expansion: int | None = None,
|
|
331
|
+
) -> CommandRequest[bool]:
|
|
332
|
+
"""
|
|
333
|
+
Creates a new Cuckoo Filter
|
|
334
|
+
|
|
335
|
+
:param key: The name of the filter.
|
|
336
|
+
:param capacity: Estimated capacity for the filter.
|
|
337
|
+
:param bucketsize: Number of items in each bucket.
|
|
338
|
+
:param maxiterations: Number of attempts to swap items between buckets
|
|
339
|
+
before declaring filter as full and creating an additional filter.
|
|
340
|
+
:param expansion: When a new filter is created, its size is the size of the
|
|
341
|
+
current filter multiplied by ``expansion``.
|
|
342
|
+
"""
|
|
343
|
+
command_arguments: CommandArgList = [key, capacity]
|
|
344
|
+
if bucketsize is not None:
|
|
345
|
+
command_arguments.extend([PrefixToken.BUCKETSIZE, bucketsize])
|
|
346
|
+
if maxiterations is not None:
|
|
347
|
+
command_arguments.extend([PrefixToken.MAXITERATIONS, maxiterations])
|
|
348
|
+
if expansion is not None:
|
|
349
|
+
command_arguments.extend([PrefixToken.EXPANSION, expansion])
|
|
350
|
+
return self.client.create_request(
|
|
351
|
+
CommandName.CF_RESERVE, *command_arguments, callback=SimpleStringCallback()
|
|
352
|
+
)
|
|
353
|
+
|
|
354
|
+
@module_command(
|
|
355
|
+
CommandName.CF_ADD,
|
|
356
|
+
group=COMMAND_GROUP,
|
|
357
|
+
version_introduced="1.0.0",
|
|
358
|
+
module=MODULE,
|
|
359
|
+
)
|
|
360
|
+
def add(self, key: KeyT, item: ValueT) -> CommandRequest[bool]:
|
|
361
|
+
"""
|
|
362
|
+
Adds an item to a Cuckoo Filter
|
|
363
|
+
|
|
364
|
+
:param key: The name of the filter.
|
|
365
|
+
:param item: The item to add.
|
|
366
|
+
"""
|
|
367
|
+
command_arguments: CommandArgList = [key, item]
|
|
368
|
+
|
|
369
|
+
return self.client.create_request(
|
|
370
|
+
CommandName.CF_ADD, *command_arguments, callback=BoolCallback()
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
@module_command(
|
|
374
|
+
CommandName.CF_ADDNX,
|
|
375
|
+
group=COMMAND_GROUP,
|
|
376
|
+
version_introduced="1.0.0",
|
|
377
|
+
module=MODULE,
|
|
378
|
+
)
|
|
379
|
+
def addnx(self, key: KeyT, item: ValueT) -> CommandRequest[bool]:
|
|
380
|
+
"""
|
|
381
|
+
Adds an item to a Cuckoo Filter if the item did not exist previously.
|
|
382
|
+
|
|
383
|
+
:param key: The name of the filter.
|
|
384
|
+
:param item: The item to add.
|
|
385
|
+
"""
|
|
386
|
+
command_arguments: CommandArgList = [key, item]
|
|
387
|
+
|
|
388
|
+
return self.client.create_request(
|
|
389
|
+
CommandName.CF_ADDNX, *command_arguments, callback=BoolCallback()
|
|
390
|
+
)
|
|
391
|
+
|
|
392
|
+
@module_command(
|
|
393
|
+
CommandName.CF_INSERT,
|
|
394
|
+
group=COMMAND_GROUP,
|
|
395
|
+
version_introduced="1.0.0",
|
|
396
|
+
module=MODULE,
|
|
397
|
+
)
|
|
398
|
+
def insert(
|
|
399
|
+
self,
|
|
400
|
+
key: KeyT,
|
|
401
|
+
items: Parameters[ValueT],
|
|
402
|
+
capacity: int | None = None,
|
|
403
|
+
nocreate: bool | None = None,
|
|
404
|
+
) -> CommandRequest[tuple[bool, ...]]:
|
|
405
|
+
"""
|
|
406
|
+
Adds one or more items to a Cuckoo Filter. A filter will be created if it does not exist
|
|
407
|
+
|
|
408
|
+
:param key: The name of the filter.
|
|
409
|
+
:param items: One or more items to add.
|
|
410
|
+
:param capacity: Specifies the desired capacity of the new filter, if this filter
|
|
411
|
+
does not exist yet.
|
|
412
|
+
:param nocreate: If specified, prevents automatic filter creation if the filter
|
|
413
|
+
does not exist.
|
|
414
|
+
:return: A tuple of boolean values indicating if the command was executed correctly.
|
|
415
|
+
"""
|
|
416
|
+
command_arguments: CommandArgList = [key]
|
|
417
|
+
if capacity is not None:
|
|
418
|
+
command_arguments.extend([PrefixToken.CAPACITY, capacity])
|
|
419
|
+
if nocreate is not None:
|
|
420
|
+
command_arguments.append(PureToken.NOCREATE)
|
|
421
|
+
command_arguments.append(PureToken.ITEMS)
|
|
422
|
+
command_arguments.extend(items)
|
|
423
|
+
|
|
424
|
+
return self.client.create_request(
|
|
425
|
+
CommandName.CF_INSERT, *command_arguments, callback=BoolsCallback()
|
|
426
|
+
)
|
|
427
|
+
|
|
428
|
+
@module_command(
|
|
429
|
+
CommandName.CF_INSERTNX,
|
|
430
|
+
group=COMMAND_GROUP,
|
|
431
|
+
version_introduced="1.0.0",
|
|
432
|
+
module=MODULE,
|
|
433
|
+
)
|
|
434
|
+
def insertnx(
|
|
435
|
+
self,
|
|
436
|
+
key: KeyT,
|
|
437
|
+
items: Parameters[ValueT],
|
|
438
|
+
capacity: int | None = None,
|
|
439
|
+
nocreate: bool | None = None,
|
|
440
|
+
) -> CommandRequest[tuple[bool, ...]]:
|
|
441
|
+
"""
|
|
442
|
+
Adds one or more items to a Cuckoo Filter if the items did not exist previously.
|
|
443
|
+
A filter will be created if it does not exist
|
|
444
|
+
|
|
445
|
+
:param key: The name of the filter.
|
|
446
|
+
:param items: One or more items to add.
|
|
447
|
+
:param capacity: Specifies the desired capacity of the new filter,
|
|
448
|
+
if this filter does not exist yet.
|
|
449
|
+
:param nocreate: If specified, prevents automatic filter creation
|
|
450
|
+
if the filter does not exist.
|
|
451
|
+
"""
|
|
452
|
+
command_arguments: CommandArgList = [key]
|
|
453
|
+
if capacity is not None:
|
|
454
|
+
command_arguments.extend([PrefixToken.CAPACITY, capacity])
|
|
455
|
+
if nocreate is not None:
|
|
456
|
+
command_arguments.append(PureToken.NOCREATE)
|
|
457
|
+
command_arguments.append(PureToken.ITEMS)
|
|
458
|
+
command_arguments.extend(items)
|
|
459
|
+
|
|
460
|
+
return self.client.create_request(
|
|
461
|
+
CommandName.CF_INSERTNX, *command_arguments, callback=BoolsCallback()
|
|
462
|
+
)
|
|
463
|
+
|
|
464
|
+
@module_command(
|
|
465
|
+
CommandName.CF_EXISTS,
|
|
466
|
+
group=COMMAND_GROUP,
|
|
467
|
+
version_introduced="1.0.0",
|
|
468
|
+
module=MODULE,
|
|
469
|
+
flags={CommandFlag.READONLY},
|
|
470
|
+
cacheable=True,
|
|
471
|
+
)
|
|
472
|
+
def exists(self, key: KeyT, item: ValueT) -> CommandRequest[bool]:
|
|
473
|
+
"""
|
|
474
|
+
Checks whether an item exist in a Cuckoo Filter
|
|
475
|
+
|
|
476
|
+
:param key: The name of the filter.
|
|
477
|
+
:param item: The item to check for.
|
|
478
|
+
"""
|
|
479
|
+
command_arguments: CommandArgList = [key, item]
|
|
480
|
+
|
|
481
|
+
return self.client.create_request(
|
|
482
|
+
CommandName.CF_EXISTS, *command_arguments, callback=BoolCallback()
|
|
483
|
+
)
|
|
484
|
+
|
|
485
|
+
@module_command(
|
|
486
|
+
CommandName.CF_MEXISTS,
|
|
487
|
+
group=COMMAND_GROUP,
|
|
488
|
+
version_introduced="1.0.0",
|
|
489
|
+
module=MODULE,
|
|
490
|
+
flags={CommandFlag.READONLY},
|
|
491
|
+
cacheable=True,
|
|
492
|
+
)
|
|
493
|
+
def mexists(self, key: KeyT, items: Parameters[ValueT]) -> CommandRequest[tuple[bool, ...]]:
|
|
494
|
+
"""
|
|
495
|
+
Checks whether one or more items exist in a Cuckoo Filter
|
|
496
|
+
|
|
497
|
+
:param key: The name of the filter.
|
|
498
|
+
:param items: The item(s) to check for.
|
|
499
|
+
"""
|
|
500
|
+
command_arguments: CommandArgList = [key, *items]
|
|
501
|
+
|
|
502
|
+
return self.client.create_request(
|
|
503
|
+
CommandName.CF_MEXISTS, *command_arguments, callback=BoolsCallback()
|
|
504
|
+
)
|
|
505
|
+
|
|
506
|
+
@module_command(
|
|
507
|
+
CommandName.CF_DEL,
|
|
508
|
+
group=COMMAND_GROUP,
|
|
509
|
+
version_introduced="1.0.0",
|
|
510
|
+
module=MODULE,
|
|
511
|
+
)
|
|
512
|
+
def delete(self, key: KeyT, item: ValueT) -> CommandRequest[bool]:
|
|
513
|
+
"""
|
|
514
|
+
Deletes an item from a Cuckoo Filter
|
|
515
|
+
|
|
516
|
+
:param key: The name of the filter.
|
|
517
|
+
:param item: The item to delete from the filter.
|
|
518
|
+
"""
|
|
519
|
+
command_arguments: CommandArgList = [key, item]
|
|
520
|
+
|
|
521
|
+
return self.client.create_request(
|
|
522
|
+
CommandName.CF_DEL, *command_arguments, callback=BoolCallback()
|
|
523
|
+
)
|
|
524
|
+
|
|
525
|
+
@module_command(
|
|
526
|
+
CommandName.CF_COUNT,
|
|
527
|
+
group=COMMAND_GROUP,
|
|
528
|
+
version_introduced="1.0.0",
|
|
529
|
+
module=MODULE,
|
|
530
|
+
flags={CommandFlag.READONLY},
|
|
531
|
+
cacheable=True,
|
|
532
|
+
)
|
|
533
|
+
def count(self, key: KeyT, item: ValueT) -> CommandRequest[int]:
|
|
534
|
+
"""
|
|
535
|
+
Return the number of times an item might be in a Cuckoo Filter
|
|
536
|
+
|
|
537
|
+
:param key: The name of the filter.
|
|
538
|
+
:param item: The item to count.
|
|
539
|
+
"""
|
|
540
|
+
command_arguments: CommandArgList = [key, item]
|
|
541
|
+
|
|
542
|
+
return self.client.create_request(
|
|
543
|
+
CommandName.CF_COUNT, *command_arguments, callback=IntCallback()
|
|
544
|
+
)
|
|
545
|
+
|
|
546
|
+
@module_command(
|
|
547
|
+
CommandName.CF_SCANDUMP,
|
|
548
|
+
group=COMMAND_GROUP,
|
|
549
|
+
version_introduced="1.0.0",
|
|
550
|
+
module=MODULE,
|
|
551
|
+
)
|
|
552
|
+
def scandump(self, key: KeyT, iterator: int) -> CommandRequest[tuple[int, bytes | None]]:
|
|
553
|
+
"""
|
|
554
|
+
Begins an incremental save of the bloom filter
|
|
555
|
+
|
|
556
|
+
:param key: Name of the filter.
|
|
557
|
+
:param iterator: Iterator value. This is either 0, or the iterator from a
|
|
558
|
+
previous invocation of this command.
|
|
559
|
+
"""
|
|
560
|
+
command_arguments: CommandArgList = [key, iterator]
|
|
561
|
+
|
|
562
|
+
return self.client.create_request(
|
|
563
|
+
CommandName.CF_SCANDUMP,
|
|
564
|
+
*command_arguments,
|
|
565
|
+
execution_parameters={"decode": False},
|
|
566
|
+
callback=MixedTupleCallback[int, bytes | None](),
|
|
567
|
+
)
|
|
568
|
+
|
|
569
|
+
@module_command(
|
|
570
|
+
CommandName.CF_LOADCHUNK,
|
|
571
|
+
group=COMMAND_GROUP,
|
|
572
|
+
version_introduced="1.0.0",
|
|
573
|
+
module=MODULE,
|
|
574
|
+
)
|
|
575
|
+
def loadchunk(self, key: KeyT, iterator: int, data: StringT) -> CommandRequest[bool]:
|
|
576
|
+
"""
|
|
577
|
+
Restores a filter previously saved using SCANDUMP
|
|
578
|
+
|
|
579
|
+
:param key: Name of the key to restore.
|
|
580
|
+
:param iter: Iterator value associated with :paramref:`data` (returned by :meth:`scandump`).
|
|
581
|
+
:param data: Current data chunk (returned by :meth:`scandump`).
|
|
582
|
+
|
|
583
|
+
"""
|
|
584
|
+
command_arguments: CommandArgList = [key, iterator, data]
|
|
585
|
+
|
|
586
|
+
return self.client.create_request(
|
|
587
|
+
CommandName.CF_LOADCHUNK,
|
|
588
|
+
*command_arguments,
|
|
589
|
+
callback=SimpleStringCallback(),
|
|
590
|
+
)
|
|
591
|
+
|
|
592
|
+
@module_command(
|
|
593
|
+
CommandName.CF_INFO,
|
|
594
|
+
group=COMMAND_GROUP,
|
|
595
|
+
version_introduced="1.0.0",
|
|
596
|
+
module=MODULE,
|
|
597
|
+
flags={CommandFlag.READONLY},
|
|
598
|
+
)
|
|
599
|
+
def info(self, key: KeyT) -> CommandRequest[dict[AnyStr, ResponsePrimitive]]:
|
|
600
|
+
"""
|
|
601
|
+
Returns information about a Cuckoo Filter
|
|
602
|
+
|
|
603
|
+
:param key: The name of the filter.
|
|
604
|
+
"""
|
|
605
|
+
|
|
606
|
+
return self.client.create_request(
|
|
607
|
+
CommandName.CF_INFO,
|
|
608
|
+
key,
|
|
609
|
+
callback=DictCallback[AnyStr, ResponsePrimitive](),
|
|
610
|
+
)
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
@versionadded(version="4.12")
|
|
614
|
+
class CountMinSketch(ModuleGroup[AnyStr]):
|
|
615
|
+
MODULE = RedisBloom
|
|
616
|
+
COMMAND_GROUP = CommandGroup.CMS
|
|
617
|
+
|
|
618
|
+
@module_command(
|
|
619
|
+
CommandName.CMS_INITBYDIM,
|
|
620
|
+
group=COMMAND_GROUP,
|
|
621
|
+
version_introduced="2.0.0",
|
|
622
|
+
module=MODULE,
|
|
623
|
+
)
|
|
624
|
+
def initbydim(self, key: KeyT, width: int, depth: int) -> CommandRequest[bool]:
|
|
625
|
+
"""
|
|
626
|
+
Initializes a Count-Min Sketch to dimensions specified by user
|
|
627
|
+
|
|
628
|
+
:param key: Name of the sketch.
|
|
629
|
+
:param width: Number of counters in each array. Reduces error size.
|
|
630
|
+
:param depth: Number of counter-arrays. Reduces error probability.
|
|
631
|
+
"""
|
|
632
|
+
return self.client.create_request(
|
|
633
|
+
CommandName.CMS_INITBYDIM,
|
|
634
|
+
key,
|
|
635
|
+
width,
|
|
636
|
+
depth,
|
|
637
|
+
callback=SimpleStringCallback(),
|
|
638
|
+
)
|
|
639
|
+
|
|
640
|
+
@module_command(
|
|
641
|
+
CommandName.CMS_INITBYPROB,
|
|
642
|
+
group=COMMAND_GROUP,
|
|
643
|
+
version_introduced="2.0.0",
|
|
644
|
+
module=MODULE,
|
|
645
|
+
)
|
|
646
|
+
def initbyprob(
|
|
647
|
+
self, key: KeyT, error: int | float, probability: int | float
|
|
648
|
+
) -> CommandRequest[bool]:
|
|
649
|
+
"""
|
|
650
|
+
Initializes a Count-Min Sketch to accommodate requested tolerances.
|
|
651
|
+
|
|
652
|
+
:param key: Name of the sketch.
|
|
653
|
+
:param error: Estimate size of error as a percent of total counted items.
|
|
654
|
+
:param probability: Desired probability for inflated count as a decimal value
|
|
655
|
+
between 0 and 1.
|
|
656
|
+
"""
|
|
657
|
+
return self.client.create_request(
|
|
658
|
+
CommandName.CMS_INITBYPROB,
|
|
659
|
+
key,
|
|
660
|
+
error,
|
|
661
|
+
probability,
|
|
662
|
+
callback=SimpleStringCallback(),
|
|
663
|
+
)
|
|
664
|
+
|
|
665
|
+
@module_command(
|
|
666
|
+
CommandName.CMS_INCRBY,
|
|
667
|
+
group=COMMAND_GROUP,
|
|
668
|
+
version_introduced="2.0.0",
|
|
669
|
+
module=MODULE,
|
|
670
|
+
)
|
|
671
|
+
def incrby(self, key: KeyT, items: Mapping[AnyStr, int]) -> CommandRequest[tuple[int, ...]]:
|
|
672
|
+
"""
|
|
673
|
+
Increases the count of one or more items by increment
|
|
674
|
+
|
|
675
|
+
:param key: The name of the HyperLogLog sketch.
|
|
676
|
+
:param items: A dictionary containing the items to increment and
|
|
677
|
+
their respective increments.
|
|
678
|
+
"""
|
|
679
|
+
|
|
680
|
+
return self.client.create_request(
|
|
681
|
+
CommandName.CMS_INCRBY,
|
|
682
|
+
key,
|
|
683
|
+
*dict_to_flat_list(items),
|
|
684
|
+
callback=TupleCallback[int](),
|
|
685
|
+
)
|
|
686
|
+
|
|
687
|
+
@module_command(
|
|
688
|
+
CommandName.CMS_QUERY,
|
|
689
|
+
group=COMMAND_GROUP,
|
|
690
|
+
version_introduced="2.0.0",
|
|
691
|
+
module=MODULE,
|
|
692
|
+
flags={CommandFlag.READONLY},
|
|
693
|
+
cacheable=True,
|
|
694
|
+
)
|
|
695
|
+
def query(
|
|
696
|
+
self,
|
|
697
|
+
key: KeyT,
|
|
698
|
+
items: Parameters[StringT],
|
|
699
|
+
) -> CommandRequest[tuple[int, ...]]:
|
|
700
|
+
"""
|
|
701
|
+
Returns the count for one or more items in a sketch
|
|
702
|
+
|
|
703
|
+
:param key: The name of the Count-Min Sketch.
|
|
704
|
+
:param items: One or more items for which to return the count.
|
|
705
|
+
"""
|
|
706
|
+
command_arguments: CommandArgList = [key, *items]
|
|
707
|
+
|
|
708
|
+
return self.client.create_request(
|
|
709
|
+
CommandName.CMS_QUERY, *command_arguments, callback=TupleCallback[int]()
|
|
710
|
+
)
|
|
711
|
+
|
|
712
|
+
@module_command(
|
|
713
|
+
CommandName.CMS_MERGE,
|
|
714
|
+
group=COMMAND_GROUP,
|
|
715
|
+
version_introduced="2.0.0",
|
|
716
|
+
module=MODULE,
|
|
717
|
+
)
|
|
718
|
+
def merge(
|
|
719
|
+
self,
|
|
720
|
+
destination: KeyT,
|
|
721
|
+
sources: Parameters[KeyT],
|
|
722
|
+
weights: Parameters[int | float] | None = None,
|
|
723
|
+
) -> CommandRequest[bool]:
|
|
724
|
+
"""
|
|
725
|
+
Merges several sketches into one sketch
|
|
726
|
+
|
|
727
|
+
:param destination: The name of the destination sketch. Must be initialized.
|
|
728
|
+
:param sources: Names of the source sketches to be merged.
|
|
729
|
+
:param weights: Multiples of each sketch. Default is 1.
|
|
730
|
+
"""
|
|
731
|
+
_sources: list[KeyT] = list(sources)
|
|
732
|
+
command_arguments: CommandArgList = [destination, len(_sources), *_sources]
|
|
733
|
+
if weights:
|
|
734
|
+
command_arguments.append(PrefixToken.WEIGHTS)
|
|
735
|
+
command_arguments.extend(weights)
|
|
736
|
+
|
|
737
|
+
return self.client.create_request(
|
|
738
|
+
CommandName.CMS_MERGE, *command_arguments, callback=SimpleStringCallback()
|
|
739
|
+
)
|
|
740
|
+
|
|
741
|
+
@module_command(
|
|
742
|
+
CommandName.CMS_INFO,
|
|
743
|
+
group=COMMAND_GROUP,
|
|
744
|
+
version_introduced="2.0.0",
|
|
745
|
+
module=MODULE,
|
|
746
|
+
flags={CommandFlag.READONLY},
|
|
747
|
+
cacheable=True,
|
|
748
|
+
)
|
|
749
|
+
def info(self, key: KeyT) -> CommandRequest[dict[AnyStr, int]]:
|
|
750
|
+
"""
|
|
751
|
+
Returns information about a sketch
|
|
752
|
+
|
|
753
|
+
:param key: The name of the sketch.
|
|
754
|
+
:return: A dictionary containing the width, depth, and total count of the sketch.
|
|
755
|
+
"""
|
|
756
|
+
|
|
757
|
+
return self.client.create_request(
|
|
758
|
+
CommandName.CMS_INFO,
|
|
759
|
+
key,
|
|
760
|
+
callback=DictCallback[AnyStr, int](),
|
|
761
|
+
)
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
@versionadded(version="4.12")
|
|
765
|
+
class TopK(ModuleGroup[AnyStr]):
|
|
766
|
+
MODULE = RedisBloom
|
|
767
|
+
COMMAND_GROUP = CommandGroup.TOPK
|
|
768
|
+
|
|
769
|
+
@mutually_inclusive_parameters("width", "depth", "decay")
|
|
770
|
+
@module_command(
|
|
771
|
+
CommandName.TOPK_RESERVE,
|
|
772
|
+
group=COMMAND_GROUP,
|
|
773
|
+
version_introduced="2.0.0",
|
|
774
|
+
module=MODULE,
|
|
775
|
+
)
|
|
776
|
+
def reserve(
|
|
777
|
+
self,
|
|
778
|
+
key: KeyT,
|
|
779
|
+
topk: int,
|
|
780
|
+
width: int | None = None,
|
|
781
|
+
depth: int | None = None,
|
|
782
|
+
decay: int | float | None = None,
|
|
783
|
+
) -> CommandRequest[bool]:
|
|
784
|
+
"""
|
|
785
|
+
Reserve a TopK sketch with specified parameters.
|
|
786
|
+
|
|
787
|
+
:param key: Name of the TOP-K sketch.
|
|
788
|
+
:param topk: Number of top occurring items to keep.
|
|
789
|
+
:param width: Number of counters kept in each array.
|
|
790
|
+
:param depth: Number of arrays.
|
|
791
|
+
:param decay: The probability of reducing a counter in an occupied bucket.
|
|
792
|
+
It is raised to power of it's counter (``decay ^ bucket[i].counter``).
|
|
793
|
+
Therefore, as the counter gets higher, the chance of a reduction is being reduced.
|
|
794
|
+
"""
|
|
795
|
+
command_arguments: CommandArgList = [key, topk]
|
|
796
|
+
if width is not None and depth is not None and decay is not None:
|
|
797
|
+
command_arguments.extend([width, depth, decay])
|
|
798
|
+
return self.client.create_request(
|
|
799
|
+
CommandName.TOPK_RESERVE,
|
|
800
|
+
*command_arguments,
|
|
801
|
+
callback=SimpleStringCallback(),
|
|
802
|
+
)
|
|
803
|
+
|
|
804
|
+
@module_command(
|
|
805
|
+
CommandName.TOPK_ADD,
|
|
806
|
+
group=COMMAND_GROUP,
|
|
807
|
+
version_introduced="2.0.0",
|
|
808
|
+
module=MODULE,
|
|
809
|
+
)
|
|
810
|
+
def add(
|
|
811
|
+
self, key: KeyT, items: Parameters[AnyStr]
|
|
812
|
+
) -> CommandRequest[tuple[AnyStr | None, ...]]:
|
|
813
|
+
"""
|
|
814
|
+
Increases the count of one or more items by increment
|
|
815
|
+
|
|
816
|
+
:param key: Name of the TOP-K sketch.
|
|
817
|
+
:param items: Item(s) to be added.
|
|
818
|
+
|
|
819
|
+
"""
|
|
820
|
+
return self.client.create_request(
|
|
821
|
+
CommandName.TOPK_ADD,
|
|
822
|
+
key,
|
|
823
|
+
*items,
|
|
824
|
+
callback=TupleCallback[AnyStr | None](),
|
|
825
|
+
)
|
|
826
|
+
|
|
827
|
+
@module_command(
|
|
828
|
+
CommandName.TOPK_INCRBY,
|
|
829
|
+
group=COMMAND_GROUP,
|
|
830
|
+
version_introduced="2.0.0",
|
|
831
|
+
module=MODULE,
|
|
832
|
+
)
|
|
833
|
+
def incrby(
|
|
834
|
+
self, key: KeyT, items: Mapping[AnyStr, int]
|
|
835
|
+
) -> CommandRequest[tuple[AnyStr | None, ...]]:
|
|
836
|
+
"""
|
|
837
|
+
Increases the count of one or more items by increment
|
|
838
|
+
|
|
839
|
+
:param key: Name of the TOP-K sketch.
|
|
840
|
+
:param items: Dictionary of items and their corresponding increment values.
|
|
841
|
+
"""
|
|
842
|
+
return self.client.create_request(
|
|
843
|
+
CommandName.TOPK_INCRBY,
|
|
844
|
+
key,
|
|
845
|
+
*dict_to_flat_list(items),
|
|
846
|
+
callback=TupleCallback[AnyStr | None](),
|
|
847
|
+
)
|
|
848
|
+
|
|
849
|
+
@module_command(
|
|
850
|
+
CommandName.TOPK_QUERY,
|
|
851
|
+
group=COMMAND_GROUP,
|
|
852
|
+
version_introduced="2.0.0",
|
|
853
|
+
module=MODULE,
|
|
854
|
+
flags={CommandFlag.READONLY},
|
|
855
|
+
cacheable=True,
|
|
856
|
+
)
|
|
857
|
+
def query(
|
|
858
|
+
self,
|
|
859
|
+
key: KeyT,
|
|
860
|
+
items: Parameters[StringT],
|
|
861
|
+
) -> CommandRequest[tuple[bool, ...]]:
|
|
862
|
+
"""
|
|
863
|
+
Checks whether an item is one of Top-K items.
|
|
864
|
+
Multiple items can be checked at once.
|
|
865
|
+
|
|
866
|
+
:param key: Name of the TOP-K sketch.
|
|
867
|
+
:param items: Item(s) to be queried.
|
|
868
|
+
"""
|
|
869
|
+
command_arguments: CommandArgList = [key, *items]
|
|
870
|
+
|
|
871
|
+
return self.client.create_request(
|
|
872
|
+
CommandName.TOPK_QUERY, *command_arguments, callback=BoolsCallback()
|
|
873
|
+
)
|
|
874
|
+
|
|
875
|
+
@module_command(
|
|
876
|
+
CommandName.TOPK_COUNT,
|
|
877
|
+
group=COMMAND_GROUP,
|
|
878
|
+
version_introduced="2.0.0",
|
|
879
|
+
module=MODULE,
|
|
880
|
+
)
|
|
881
|
+
def count(
|
|
882
|
+
self,
|
|
883
|
+
key: KeyT,
|
|
884
|
+
items: Parameters[StringT],
|
|
885
|
+
) -> CommandRequest[tuple[int, ...]]:
|
|
886
|
+
"""
|
|
887
|
+
Return the count for one or more items are in a sketch
|
|
888
|
+
|
|
889
|
+
:param key: The name of the TOP-K sketch.
|
|
890
|
+
:param items: One or more items to count.
|
|
891
|
+
"""
|
|
892
|
+
command_arguments: CommandArgList = [key, *items]
|
|
893
|
+
|
|
894
|
+
return self.client.create_request(
|
|
895
|
+
CommandName.TOPK_COUNT, *command_arguments, callback=TupleCallback[int]()
|
|
896
|
+
)
|
|
897
|
+
|
|
898
|
+
@module_command(
|
|
899
|
+
CommandName.TOPK_LIST,
|
|
900
|
+
group=COMMAND_GROUP,
|
|
901
|
+
version_introduced="2.0.0",
|
|
902
|
+
module=MODULE,
|
|
903
|
+
flags={CommandFlag.READONLY},
|
|
904
|
+
cacheable=True,
|
|
905
|
+
)
|
|
906
|
+
def list(
|
|
907
|
+
self, key: KeyT, withcount: bool | None = None
|
|
908
|
+
) -> CommandRequest[dict[AnyStr, int]] | CommandRequest[tuple[AnyStr, ...]]:
|
|
909
|
+
"""
|
|
910
|
+
Return full list of items in Top K list
|
|
911
|
+
|
|
912
|
+
:param key: Name of the TOP-K sketch.
|
|
913
|
+
:param withcount: Whether to include counts of each element.
|
|
914
|
+
"""
|
|
915
|
+
command_arguments: CommandArgList = [key]
|
|
916
|
+
if withcount:
|
|
917
|
+
command_arguments.append(PureToken.WITHCOUNT)
|
|
918
|
+
return self.client.create_request(
|
|
919
|
+
CommandName.TOPK_LIST,
|
|
920
|
+
*command_arguments,
|
|
921
|
+
callback=DictCallback[AnyStr, int](),
|
|
922
|
+
)
|
|
923
|
+
else:
|
|
924
|
+
return self.client.create_request(
|
|
925
|
+
CommandName.TOPK_LIST,
|
|
926
|
+
*command_arguments,
|
|
927
|
+
callback=TupleCallback[AnyStr](),
|
|
928
|
+
)
|
|
929
|
+
|
|
930
|
+
@module_command(
|
|
931
|
+
CommandName.TOPK_INFO,
|
|
932
|
+
group=COMMAND_GROUP,
|
|
933
|
+
version_introduced="2.0.0",
|
|
934
|
+
module=MODULE,
|
|
935
|
+
flags={CommandFlag.READONLY},
|
|
936
|
+
cacheable=True,
|
|
937
|
+
)
|
|
938
|
+
def info(self, key: KeyT) -> CommandRequest[dict[AnyStr, int]]:
|
|
939
|
+
"""
|
|
940
|
+
Returns information about a sketch
|
|
941
|
+
|
|
942
|
+
:param key: Name of the TOP-K sketch.
|
|
943
|
+
:return: A dictionary containing the following information:
|
|
944
|
+
- ``k``: The number of items tracked by the sketch.
|
|
945
|
+
- ``width``: The width of the sketch.
|
|
946
|
+
- ``depth``: The depth of the sketch.
|
|
947
|
+
- ``decay``: The decay factor used by the sketch.
|
|
948
|
+
"""
|
|
949
|
+
|
|
950
|
+
return self.client.create_request(
|
|
951
|
+
CommandName.TOPK_INFO,
|
|
952
|
+
key,
|
|
953
|
+
callback=DictCallback[AnyStr, int](),
|
|
954
|
+
)
|
|
955
|
+
|
|
956
|
+
|
|
957
|
+
@versionadded(version="4.12")
|
|
958
|
+
class TDigest(ModuleGroup[AnyStr]):
|
|
959
|
+
MODULE = RedisBloom
|
|
960
|
+
COMMAND_GROUP = CommandGroup.TDIGEST
|
|
961
|
+
|
|
962
|
+
@module_command(
|
|
963
|
+
CommandName.TDIGEST_CREATE,
|
|
964
|
+
group=COMMAND_GROUP,
|
|
965
|
+
version_introduced="2.4.0",
|
|
966
|
+
module=MODULE,
|
|
967
|
+
)
|
|
968
|
+
def create(self, key: KeyT, compression: int | None = None) -> CommandRequest[bool]:
|
|
969
|
+
"""
|
|
970
|
+
Allocates memory and initializes a new t-digest sketch
|
|
971
|
+
|
|
972
|
+
:param key: The key name for the new t-digest sketch.
|
|
973
|
+
:param compression: A controllable tradeoff between accuracy and memory consumption.
|
|
974
|
+
"""
|
|
975
|
+
command_arguments: CommandArgList = [key]
|
|
976
|
+
if compression is not None:
|
|
977
|
+
command_arguments.extend([PrefixToken.COMPRESSION, compression])
|
|
978
|
+
return self.client.create_request(
|
|
979
|
+
CommandName.TDIGEST_CREATE,
|
|
980
|
+
*command_arguments,
|
|
981
|
+
callback=SimpleStringCallback(),
|
|
982
|
+
)
|
|
983
|
+
|
|
984
|
+
@module_command(
|
|
985
|
+
CommandName.TDIGEST_RESET,
|
|
986
|
+
group=COMMAND_GROUP,
|
|
987
|
+
version_introduced="2.4.0",
|
|
988
|
+
module=MODULE,
|
|
989
|
+
)
|
|
990
|
+
def reset(self, key: KeyT) -> CommandRequest[bool]:
|
|
991
|
+
"""
|
|
992
|
+
Resets a t-digest sketch: empty the sketch and re-initializes it.
|
|
993
|
+
|
|
994
|
+
:param key: The key name for an existing t-digest sketch.
|
|
995
|
+
"""
|
|
996
|
+
return self.client.create_request(
|
|
997
|
+
CommandName.TDIGEST_RESET, key, callback=SimpleStringCallback()
|
|
998
|
+
)
|
|
999
|
+
|
|
1000
|
+
@module_command(
|
|
1001
|
+
CommandName.TDIGEST_ADD,
|
|
1002
|
+
group=COMMAND_GROUP,
|
|
1003
|
+
version_introduced="2.4.0",
|
|
1004
|
+
module=MODULE,
|
|
1005
|
+
)
|
|
1006
|
+
def add(
|
|
1007
|
+
self,
|
|
1008
|
+
key: KeyT,
|
|
1009
|
+
values: Parameters[int | float],
|
|
1010
|
+
) -> CommandRequest[bool]:
|
|
1011
|
+
"""
|
|
1012
|
+
Adds one or more observations to a t-digest sketch
|
|
1013
|
+
|
|
1014
|
+
:param key: Key name for an existing t-digest sketch.
|
|
1015
|
+
:param values: value(s) of observation(s)
|
|
1016
|
+
"""
|
|
1017
|
+
command_arguments: CommandArgList = [key, *values]
|
|
1018
|
+
|
|
1019
|
+
return self.client.create_request(
|
|
1020
|
+
CommandName.TDIGEST_ADD,
|
|
1021
|
+
*command_arguments,
|
|
1022
|
+
callback=SimpleStringCallback(),
|
|
1023
|
+
)
|
|
1024
|
+
|
|
1025
|
+
@module_command(
|
|
1026
|
+
CommandName.TDIGEST_MERGE,
|
|
1027
|
+
group=COMMAND_GROUP,
|
|
1028
|
+
version_introduced="2.4.0",
|
|
1029
|
+
module=MODULE,
|
|
1030
|
+
)
|
|
1031
|
+
def merge(
|
|
1032
|
+
self,
|
|
1033
|
+
destination_key: KeyT,
|
|
1034
|
+
source_keys: Parameters[KeyT],
|
|
1035
|
+
compression: int | None = None,
|
|
1036
|
+
override: bool | None = None,
|
|
1037
|
+
) -> CommandRequest[bool]:
|
|
1038
|
+
"""
|
|
1039
|
+
Merges multiple t-digest sketches into a single sketch
|
|
1040
|
+
|
|
1041
|
+
:param destination_key: Key name for a t-digest sketch to merge observation values to.
|
|
1042
|
+
If it does not exist, a new sketch is created.
|
|
1043
|
+
If it is an existing sketch, its values are merged with the values of the source keys.
|
|
1044
|
+
To override the destination key contents use :paramref:`override`.
|
|
1045
|
+
:param source_keys: Key names for t-digest sketches to merge observation values from.
|
|
1046
|
+
:param compression: Controllable tradeoff between accuracy and memory consumption.
|
|
1047
|
+
:param override: When specified, if :paramref:`destination_key` already exists,
|
|
1048
|
+
it is overwritten.
|
|
1049
|
+
|
|
1050
|
+
"""
|
|
1051
|
+
_source_keys: list[KeyT] = list(source_keys)
|
|
1052
|
+
command_arguments: CommandArgList = [
|
|
1053
|
+
destination_key,
|
|
1054
|
+
len(_source_keys),
|
|
1055
|
+
*_source_keys,
|
|
1056
|
+
]
|
|
1057
|
+
if compression is not None:
|
|
1058
|
+
command_arguments.extend([PrefixToken.COMPRESSION, compression])
|
|
1059
|
+
if override is not None:
|
|
1060
|
+
command_arguments.append(PureToken.OVERRIDE)
|
|
1061
|
+
return self.client.create_request(
|
|
1062
|
+
CommandName.TDIGEST_MERGE,
|
|
1063
|
+
*command_arguments,
|
|
1064
|
+
callback=SimpleStringCallback(),
|
|
1065
|
+
)
|
|
1066
|
+
|
|
1067
|
+
@module_command(
|
|
1068
|
+
CommandName.TDIGEST_MIN,
|
|
1069
|
+
group=COMMAND_GROUP,
|
|
1070
|
+
version_introduced="2.4.0",
|
|
1071
|
+
module=MODULE,
|
|
1072
|
+
flags={CommandFlag.READONLY},
|
|
1073
|
+
cacheable=True,
|
|
1074
|
+
)
|
|
1075
|
+
def min(self, key: KeyT) -> CommandRequest[float]:
|
|
1076
|
+
"""
|
|
1077
|
+
Returns the minimum observation value from a t-digest sketch
|
|
1078
|
+
|
|
1079
|
+
:param key: The key name for an existing t-digest sketch.
|
|
1080
|
+
"""
|
|
1081
|
+
|
|
1082
|
+
return self.client.create_request(CommandName.TDIGEST_MIN, key, callback=FloatCallback())
|
|
1083
|
+
|
|
1084
|
+
@module_command(
|
|
1085
|
+
CommandName.TDIGEST_MAX,
|
|
1086
|
+
group=COMMAND_GROUP,
|
|
1087
|
+
version_introduced="2.4.0",
|
|
1088
|
+
module=MODULE,
|
|
1089
|
+
flags={CommandFlag.READONLY},
|
|
1090
|
+
cacheable=True,
|
|
1091
|
+
)
|
|
1092
|
+
def max(self, key: KeyT) -> CommandRequest[float]:
|
|
1093
|
+
"""
|
|
1094
|
+
Returns the maximum observation value from a t-digest sketch
|
|
1095
|
+
|
|
1096
|
+
:param key: The key name for an existing t-digest sketch.
|
|
1097
|
+
"""
|
|
1098
|
+
|
|
1099
|
+
return self.client.create_request(CommandName.TDIGEST_MAX, key, callback=FloatCallback())
|
|
1100
|
+
|
|
1101
|
+
@module_command(
|
|
1102
|
+
CommandName.TDIGEST_QUANTILE,
|
|
1103
|
+
group=COMMAND_GROUP,
|
|
1104
|
+
version_introduced="2.4.0",
|
|
1105
|
+
module=MODULE,
|
|
1106
|
+
flags={CommandFlag.READONLY},
|
|
1107
|
+
cacheable=True,
|
|
1108
|
+
)
|
|
1109
|
+
def quantile(
|
|
1110
|
+
self,
|
|
1111
|
+
key: KeyT,
|
|
1112
|
+
quantiles: Parameters[int | float],
|
|
1113
|
+
) -> CommandRequest[tuple[float, ...]]:
|
|
1114
|
+
"""
|
|
1115
|
+
Returns, for each input fraction, an estimation of the value (floating point)
|
|
1116
|
+
that is smaller than the given fraction of observations
|
|
1117
|
+
|
|
1118
|
+
:param key: Key name for an existing t-digest sketch.
|
|
1119
|
+
:param quantiles: Input fractions (between 0 and 1 inclusively).
|
|
1120
|
+
"""
|
|
1121
|
+
command_arguments: CommandArgList = [key, *quantiles]
|
|
1122
|
+
|
|
1123
|
+
return self.client.create_request(
|
|
1124
|
+
CommandName.TDIGEST_QUANTILE, *command_arguments, callback=FloatsCallback()
|
|
1125
|
+
)
|
|
1126
|
+
|
|
1127
|
+
@module_command(
|
|
1128
|
+
CommandName.TDIGEST_CDF,
|
|
1129
|
+
group=COMMAND_GROUP,
|
|
1130
|
+
version_introduced="2.4.0",
|
|
1131
|
+
module=MODULE,
|
|
1132
|
+
flags={CommandFlag.READONLY},
|
|
1133
|
+
cacheable=True,
|
|
1134
|
+
)
|
|
1135
|
+
def cdf(
|
|
1136
|
+
self,
|
|
1137
|
+
key: KeyT,
|
|
1138
|
+
values: Parameters[int | float],
|
|
1139
|
+
) -> CommandRequest[tuple[float, ...]]:
|
|
1140
|
+
"""
|
|
1141
|
+
Returns, for each input value, an estimation of the fraction (floating-point)
|
|
1142
|
+
of (observations smaller than the given value + half the observations equal
|
|
1143
|
+
to the given value)
|
|
1144
|
+
|
|
1145
|
+
:param key: The key name for an existing t-digest sketch.
|
|
1146
|
+
:param values: The values for which the CDF should be retrieved.
|
|
1147
|
+
"""
|
|
1148
|
+
command_arguments: CommandArgList = [key, *values]
|
|
1149
|
+
|
|
1150
|
+
return self.client.create_request(
|
|
1151
|
+
CommandName.TDIGEST_CDF, *command_arguments, callback=FloatsCallback()
|
|
1152
|
+
)
|
|
1153
|
+
|
|
1154
|
+
@module_command(
|
|
1155
|
+
CommandName.TDIGEST_TRIMMED_MEAN,
|
|
1156
|
+
group=COMMAND_GROUP,
|
|
1157
|
+
version_introduced="2.4.0",
|
|
1158
|
+
module=MODULE,
|
|
1159
|
+
flags={CommandFlag.READONLY},
|
|
1160
|
+
cacheable=True,
|
|
1161
|
+
)
|
|
1162
|
+
def trimmed_mean(
|
|
1163
|
+
self,
|
|
1164
|
+
key: KeyT,
|
|
1165
|
+
low_cut_quantile: int | float,
|
|
1166
|
+
high_cut_quantile: int | float,
|
|
1167
|
+
) -> CommandRequest[float]:
|
|
1168
|
+
"""
|
|
1169
|
+
Returns an estimation of the mean value from the sketch,
|
|
1170
|
+
excluding observation values outside the low and high cutoff quantiles
|
|
1171
|
+
|
|
1172
|
+
:param key: The key name for an existing t-digest sketch.
|
|
1173
|
+
:param low_cut_quantile: A floating-point value in the range [0..1],
|
|
1174
|
+
should be lower than :paramref:`high_cut_quantile`.
|
|
1175
|
+
:param high_cut_quantile: A floating-point value in the range [0..1],
|
|
1176
|
+
should be higher than `low_cut_quantile`.
|
|
1177
|
+
|
|
1178
|
+
"""
|
|
1179
|
+
command_arguments: CommandArgList = [key, low_cut_quantile, high_cut_quantile]
|
|
1180
|
+
|
|
1181
|
+
return self.client.create_request(
|
|
1182
|
+
CommandName.TDIGEST_TRIMMED_MEAN,
|
|
1183
|
+
*command_arguments,
|
|
1184
|
+
callback=FloatCallback(),
|
|
1185
|
+
)
|
|
1186
|
+
|
|
1187
|
+
@module_command(
|
|
1188
|
+
CommandName.TDIGEST_RANK,
|
|
1189
|
+
group=COMMAND_GROUP,
|
|
1190
|
+
version_introduced="2.4.0",
|
|
1191
|
+
module=MODULE,
|
|
1192
|
+
flags={CommandFlag.READONLY},
|
|
1193
|
+
cacheable=True,
|
|
1194
|
+
)
|
|
1195
|
+
def rank(
|
|
1196
|
+
self,
|
|
1197
|
+
key: KeyT,
|
|
1198
|
+
values: Parameters[int | float],
|
|
1199
|
+
) -> CommandRequest[tuple[int, ...]]:
|
|
1200
|
+
"""
|
|
1201
|
+
Returns, for each input value (floating-point), the estimated rank of
|
|
1202
|
+
the value (the number of observations in the sketch that are smaller
|
|
1203
|
+
than the value + half the number of observations that are equal to the value)
|
|
1204
|
+
|
|
1205
|
+
:param key: The key name for an existing t-digest sketch.
|
|
1206
|
+
:param values: Input values for which the rank should be estimated.
|
|
1207
|
+
"""
|
|
1208
|
+
command_arguments: CommandArgList = [key, *values]
|
|
1209
|
+
|
|
1210
|
+
return self.client.create_request(
|
|
1211
|
+
CommandName.TDIGEST_RANK, *command_arguments, callback=TupleCallback[int]()
|
|
1212
|
+
)
|
|
1213
|
+
|
|
1214
|
+
@module_command(
|
|
1215
|
+
CommandName.TDIGEST_REVRANK,
|
|
1216
|
+
group=COMMAND_GROUP,
|
|
1217
|
+
version_introduced="2.4.0",
|
|
1218
|
+
module=MODULE,
|
|
1219
|
+
flags={CommandFlag.READONLY},
|
|
1220
|
+
cacheable=True,
|
|
1221
|
+
)
|
|
1222
|
+
def revrank(
|
|
1223
|
+
self,
|
|
1224
|
+
key: KeyT,
|
|
1225
|
+
values: Parameters[int | float],
|
|
1226
|
+
) -> CommandRequest[tuple[int, ...]]:
|
|
1227
|
+
"""
|
|
1228
|
+
Returns, for each input value (floating-point), the estimated reverse rank of
|
|
1229
|
+
the value (the number of observations in the sketch that are larger than
|
|
1230
|
+
the value + half the number of observations that are equal to the value)
|
|
1231
|
+
|
|
1232
|
+
:param key: The name of an existing t-digest sketch.
|
|
1233
|
+
:param values: The input values for which the reverse rank should be estimated.
|
|
1234
|
+
"""
|
|
1235
|
+
command_arguments: CommandArgList = [key, *values]
|
|
1236
|
+
|
|
1237
|
+
return self.client.create_request(
|
|
1238
|
+
CommandName.TDIGEST_REVRANK,
|
|
1239
|
+
*command_arguments,
|
|
1240
|
+
callback=TupleCallback[int](),
|
|
1241
|
+
)
|
|
1242
|
+
|
|
1243
|
+
@module_command(
|
|
1244
|
+
CommandName.TDIGEST_BYRANK,
|
|
1245
|
+
group=COMMAND_GROUP,
|
|
1246
|
+
version_introduced="2.4.0",
|
|
1247
|
+
module=MODULE,
|
|
1248
|
+
flags={CommandFlag.READONLY},
|
|
1249
|
+
cacheable=True,
|
|
1250
|
+
)
|
|
1251
|
+
def byrank(
|
|
1252
|
+
self,
|
|
1253
|
+
key: KeyT,
|
|
1254
|
+
ranks: Parameters[int | float],
|
|
1255
|
+
) -> CommandRequest[tuple[float, ...]]:
|
|
1256
|
+
"""
|
|
1257
|
+
Returns, for each input rank, an estimation of the value (floating-point) with
|
|
1258
|
+
that rank
|
|
1259
|
+
|
|
1260
|
+
:param key: The key name for an existing t-digest sketch.
|
|
1261
|
+
:param ranks: The ranks for which the estimated values should be retrieved.
|
|
1262
|
+
"""
|
|
1263
|
+
command_arguments: CommandArgList = [key, *ranks]
|
|
1264
|
+
|
|
1265
|
+
return self.client.create_request(
|
|
1266
|
+
CommandName.TDIGEST_BYRANK, *command_arguments, callback=FloatsCallback()
|
|
1267
|
+
)
|
|
1268
|
+
|
|
1269
|
+
@module_command(
|
|
1270
|
+
CommandName.TDIGEST_BYREVRANK,
|
|
1271
|
+
group=COMMAND_GROUP,
|
|
1272
|
+
version_introduced="2.4.0",
|
|
1273
|
+
module=MODULE,
|
|
1274
|
+
flags={CommandFlag.READONLY},
|
|
1275
|
+
cacheable=True,
|
|
1276
|
+
)
|
|
1277
|
+
def byrevrank(
|
|
1278
|
+
self,
|
|
1279
|
+
key: KeyT,
|
|
1280
|
+
reverse_ranks: Parameters[int | float],
|
|
1281
|
+
) -> CommandRequest[tuple[float, ...]]:
|
|
1282
|
+
"""
|
|
1283
|
+
Returns, for each input reverse rank, an estimation of the value
|
|
1284
|
+
(floating-point) with that reverse rank
|
|
1285
|
+
|
|
1286
|
+
:param key: The key name for an existing t-digest sketch.
|
|
1287
|
+
:param reverse_ranks: The reverse ranks for which the values should be retrieved.
|
|
1288
|
+
"""
|
|
1289
|
+
command_arguments: CommandArgList = [key, *reverse_ranks]
|
|
1290
|
+
|
|
1291
|
+
return self.client.create_request(
|
|
1292
|
+
CommandName.TDIGEST_BYREVRANK,
|
|
1293
|
+
*command_arguments,
|
|
1294
|
+
callback=FloatsCallback(),
|
|
1295
|
+
)
|
|
1296
|
+
|
|
1297
|
+
@module_command(
|
|
1298
|
+
CommandName.TDIGEST_INFO,
|
|
1299
|
+
group=COMMAND_GROUP,
|
|
1300
|
+
version_introduced="2.4.0",
|
|
1301
|
+
module=MODULE,
|
|
1302
|
+
flags={CommandFlag.READONLY},
|
|
1303
|
+
cacheable=True,
|
|
1304
|
+
)
|
|
1305
|
+
def info(self, key: KeyT) -> CommandRequest[dict[AnyStr, ResponsePrimitive]]:
|
|
1306
|
+
"""
|
|
1307
|
+
Returns information and statistics about a t-digest sketch
|
|
1308
|
+
|
|
1309
|
+
:param key: The key name for an existing t-digest sketch.
|
|
1310
|
+
:return: Dictionary with information about the sketch, including compression,
|
|
1311
|
+
capacity, number of merged and unmerged nodes, weight of merged and unmerged nodes,
|
|
1312
|
+
number of observations, total compressions, and memory usage.
|
|
1313
|
+
"""
|
|
1314
|
+
|
|
1315
|
+
return self.client.create_request(
|
|
1316
|
+
CommandName.TDIGEST_INFO,
|
|
1317
|
+
key,
|
|
1318
|
+
callback=DictCallback[AnyStr, ResponsePrimitive](),
|
|
1319
|
+
)
|