Skip to content

Commit 738d0c7

Browse files
committed
update modules
1 parent 2c4b386 commit 738d0c7

File tree

16 files changed

+423
-497
lines changed

16 files changed

+423
-497
lines changed

redis/commands/bf/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from ..helpers import parse_to_list
44
from .commands import * # noqa
55
from .info import BFInfo, CFInfo, CMSInfo, TDigestInfo, TopKInfo
6-
from .utils import parse_tdigest_quantile
76

87

98
class AbstractBloom(object):
@@ -166,12 +165,16 @@ def __init__(self, client, **kwargs):
166165
# TDIGEST_RESET: bool_ok,
167166
# TDIGEST_ADD: spaceHolder,
168167
# TDIGEST_MERGE: spaceHolder,
169-
TDIGEST_CDF: float,
170-
TDIGEST_QUANTILE: parse_tdigest_quantile,
168+
TDIGEST_CDF: parse_to_list,
169+
TDIGEST_QUANTILE: parse_to_list,
171170
TDIGEST_MIN: float,
172171
TDIGEST_MAX: float,
173172
TDIGEST_TRIMMED_MEAN: float,
174173
TDIGEST_INFO: TDigestInfo,
174+
TDIGEST_RANK: parse_to_list,
175+
TDIGEST_REVRANK: parse_to_list,
176+
TDIGEST_BYRANK: parse_to_list,
177+
TDIGEST_BYREVRANK: parse_to_list,
175178
}
176179

177180
self.client = client

redis/commands/bf/commands.py

Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
from deprecated import deprecated
2-
31
from redis.client import NEVER_DECODE
42
from redis.exceptions import ModuleError
5-
from redis.utils import HIREDIS_AVAILABLE
3+
from redis.utils import HIREDIS_AVAILABLE, deprecated_function
64

75
BF_RESERVE = "BF.RESERVE"
86
BF_ADD = "BF.ADD"
@@ -52,7 +50,10 @@
5250
TDIGEST_MAX = "TDIGEST.MAX"
5351
TDIGEST_INFO = "TDIGEST.INFO"
5452
TDIGEST_TRIMMED_MEAN = "TDIGEST.TRIMMED_MEAN"
55-
TDIGEST_MERGESTORE = "TDIGEST.MERGESTORE"
53+
TDIGEST_RANK = "TDIGEST.RANK"
54+
TDIGEST_REVRANK = "TDIGEST.REVRANK"
55+
TDIGEST_BYRANK = "TDIGEST.BYRANK"
56+
TDIGEST_BYREVRANK = "TDIGEST.BYREVRANK"
5657

5758

5859
class BFCommands:
@@ -324,7 +325,7 @@ def query(self, key, *items):
324325
""" # noqa
325326
return self.execute_command(TOPK_QUERY, key, *items)
326327

327-
@deprecated(version="4.4.0", reason="deprecated since redisbloom 2.4.0")
328+
@deprecated_function(version="4.4.0", reason="deprecated since redisbloom 2.4.0")
328329
def count(self, key, *items):
329330
"""
330331
Return count for one `item` or more from `key`.
@@ -358,7 +359,7 @@ def create(self, key, compression=100):
358359
Allocate the memory and initialize the t-digest.
359360
For more information see `TDIGEST.CREATE <https://redis.io/commands/tdigest.create>`_.
360361
""" # noqa
361-
return self.execute_command(TDIGEST_CREATE, key, compression)
362+
return self.execute_command(TDIGEST_CREATE, key, "COMPRESSION", compression)
362363

363364
def reset(self, key):
364365
"""
@@ -367,26 +368,30 @@ def reset(self, key):
367368
""" # noqa
368369
return self.execute_command(TDIGEST_RESET, key)
369370

370-
def add(self, key, values, weights):
371+
def add(self, key, values):
371372
"""
372-
Add one or more samples (value with weight) to a sketch `key`.
373-
Both `values` and `weights` are lists.
374-
For more information see `TDIGEST.ADD <https://redis.io/commands/tdigest.add>`_.
373+
Adds one or more observations to a t-digest sketch `key`.
375374
376-
Example:
377-
378-
>>> tdigestadd('A', [1500.0], [1.0])
375+
For more information see `TDIGEST.ADD <https://redis.io/commands/tdigest.add>`_.
379376
""" # noqa
380-
params = [key]
381-
self.append_values_and_weights(params, values, weights)
382-
return self.execute_command(TDIGEST_ADD, *params)
377+
return self.execute_command(TDIGEST_ADD, key, *values)
383378

384-
def merge(self, toKey, fromKey):
379+
def merge(self, destination_key, num_keys, *keys, compression=None, override=False):
385380
"""
386-
Merge all of the values from 'fromKey' to 'toKey' sketch.
381+
Merges all of the values from `keys` to 'destination-key' sketch.
382+
It is mandatory to provide the `num_keys` before passing the input keys and
383+
the other (optional) arguments.
384+
If `destination_key` already exists its values are merged with the input keys.
385+
If you wish to override the destination key contents use the `OVERRIDE` parameter.
386+
387387
For more information see `TDIGEST.MERGE <https://redis.io/commands/tdigest.merge>`_.
388388
""" # noqa
389-
return self.execute_command(TDIGEST_MERGE, toKey, fromKey)
389+
params = [destination_key, num_keys, *keys]
390+
if compression is not None:
391+
params.extend(["COMPRESSION", compression])
392+
if override:
393+
params.append("OVERRIDE")
394+
return self.execute_command(TDIGEST_MERGE, *params)
390395

391396
def min(self, key):
392397
"""
@@ -411,12 +416,12 @@ def quantile(self, key, quantile, *quantiles):
411416
""" # noqa
412417
return self.execute_command(TDIGEST_QUANTILE, key, quantile, *quantiles)
413418

414-
def cdf(self, key, value):
419+
def cdf(self, key, value, *values):
415420
"""
416421
Return double fraction of all points added which are <= value.
417422
For more information see `TDIGEST.CDF <https://redis.io/commands/tdigest.cdf>`_.
418423
""" # noqa
419-
return self.execute_command(TDIGEST_CDF, key, value)
424+
return self.execute_command(TDIGEST_CDF, key, value, *values)
420425

421426
def info(self, key):
422427
"""
@@ -436,18 +441,39 @@ def trimmed_mean(self, key, low_cut_quantile, high_cut_quantile):
436441
TDIGEST_TRIMMED_MEAN, key, low_cut_quantile, high_cut_quantile
437442
)
438443

439-
def mergestore(self, dest_key, numkeys, *sourcekeys, compression=False):
444+
def rank(self, key, value, *values):
445+
"""
446+
Retrieve the estimated rank of value (the number of observations in the sketch
447+
that are smaller than value + half the number of observations that are equal to value).
448+
449+
For more information see `TDIGEST.RANK <https://redis.io/commands/tdigest.rank>`_.
450+
""" # noqa
451+
return self.execute_command(TDIGEST_RANK, key, value, *values)
452+
453+
def revrank(self, key, value, *values):
454+
"""
455+
Retrieve the estimated rank of value (the number of observations in the sketch
456+
that are larger than value + half the number of observations that are equal to value).
457+
458+
For more information see `TDIGEST.REVRANK <https://redis.io/commands/tdigest.revrank>`_.
459+
""" # noqa
460+
return self.execute_command(TDIGEST_REVRANK, key, value, *values)
461+
462+
def byrank(self, key, rank, *ranks):
440463
"""
441-
Merges all of the values from `sourcekeys` keys to `dest_key` sketch.
442-
If destination already exists, it is overwritten.
464+
Retrieve an estimation of the value with the given rank.
443465
466+
For more information see `TDIGEST.BY_RANK <https://redis.io/commands/tdigest.by_rank>`_.
467+
""" # noqa
468+
return self.execute_command(TDIGEST_BYRANK, key, rank, *ranks)
444469

445-
For more information see `TDIGEST.MERGESTORE <https://redis.io/commands/tdigest.mergestore>`_.
470+
def byrevrank(self, key, rank, *ranks):
471+
"""
472+
Retrieve an estimation of the value with the given reverse rank.
473+
474+
For more information see `TDIGEST.BY_REVRANK <https://redis.io/commands/tdigest.by_revrank>`_.
446475
""" # noqa
447-
params = [dest_key, numkeys, *sourcekeys]
448-
if compression:
449-
params.extend(["COMPRESSION", compression])
450-
return self.execute_command(TDIGEST_MERGESTORE, *params)
476+
return self.execute_command(TDIGEST_BYREVRANK, key, rank, *ranks)
451477

452478

453479
class CMSCommands:

redis/commands/bf/info.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,20 @@ def __init__(self, args):
6868
class TDigestInfo(object):
6969
compression = None
7070
capacity = None
71-
mergedNodes = None
72-
unmergedNodes = None
73-
mergedWeight = None
74-
unmergedWeight = None
75-
totalCompressions = None
71+
merged_nodes = None
72+
unmerged_nodes = None
73+
merged_weight = None
74+
unmerged_weight = None
75+
total_compressions = None
76+
memory_usage = None
7677

7778
def __init__(self, args):
7879
response = dict(zip(map(nativestr, args[::2]), args[1::2]))
7980
self.compression = response["Compression"]
8081
self.capacity = response["Capacity"]
81-
self.mergedNodes = response["Merged nodes"]
82-
self.unmergedNodes = response["Unmerged nodes"]
83-
self.mergedWeight = response["Merged weight"]
84-
self.unmergedWeight = response["Unmerged weight"]
85-
self.totalCompressions = response["Total compressions"]
82+
self.merged_nodes = response["Merged nodes"]
83+
self.unmerged_nodes = response["Unmerged nodes"]
84+
self.merged_weight = response["Merged weight"]
85+
self.unmerged_weight = response["Unmerged weight"]
86+
self.total_compressions = response["Total compressions"]
87+
self.memory_usage = response["Memory usage"]

redis/commands/graph/query_result.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def parse_boolean(self, value):
270270
"""
271271
value = value.decode() if isinstance(value, bytes) else value
272272
try:
273-
scalar = strtobool(value)
273+
scalar = True if strtobool(value) else False
274274
except ValueError:
275275
sys.stderr.write("unknown boolean type\n")
276276
scalar = None

redis/commands/json/commands.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
from json import JSONDecodeError, loads
33
from typing import Dict, List, Optional, Union
44

5-
from deprecated import deprecated
6-
75
from redis.exceptions import DataError
6+
from redis.utils import deprecated_function
87

98
from ._util import JsonType
109
from .decoders import decode_dict_keys
@@ -137,7 +136,7 @@ def numincrby(self, name: str, path: str, number: int) -> str:
137136
"JSON.NUMINCRBY", name, str(path), self._encode(number)
138137
)
139138

140-
@deprecated(version="4.0.0", reason="deprecated since redisjson 1.0.0")
139+
@deprecated_function(version="4.0.0", reason="deprecated since redisjson 1.0.0")
141140
def nummultby(self, name: str, path: str, number: int) -> str:
142141
"""Multiply the numeric (integer or floating point) JSON value under
143142
``path`` at key ``name`` with the provided ``number``.
@@ -368,19 +367,19 @@ def debug(
368367
pieces.append(str(path))
369368
return self.execute_command("JSON.DEBUG", *pieces)
370369

371-
@deprecated(
370+
@deprecated_function(
372371
version="4.0.0", reason="redisjson-py supported this, call get directly."
373372
)
374373
def jsonget(self, *args, **kwargs):
375374
return self.get(*args, **kwargs)
376375

377-
@deprecated(
376+
@deprecated_function(
378377
version="4.0.0", reason="redisjson-py supported this, call get directly."
379378
)
380379
def jsonmget(self, *args, **kwargs):
381380
return self.mget(*args, **kwargs)
382381

383-
@deprecated(
382+
@deprecated_function(
384383
version="4.0.0", reason="redisjson-py supported this, call get directly."
385384
)
386385
def jsonset(self, *args, **kwargs):

redis/commands/search/aggregation.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ def __init__(self, query="*"):
104104
self._aggregateplan = []
105105
self._loadfields = []
106106
self._loadall = False
107-
self._limit = Limit()
108107
self._max = 0
109108
self._with_schema = False
110109
self._verbatim = False
@@ -211,7 +210,8 @@ def limit(self, offset, num):
211210
`sort_by()` instead.
212211
213212
"""
214-
self._limit = Limit(offset, num)
213+
_limit = Limit(offset, num)
214+
self._aggregateplan.extend(_limit.build_args())
215215
return self
216216

217217
def sort_by(self, *fields, **kwargs):
@@ -323,8 +323,6 @@ def build_args(self):
323323

324324
ret.extend(self._aggregateplan)
325325

326-
ret += self._limit.build_args()
327-
328326
return ret
329327

330328

redis/commands/search/commands.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Dict, Optional, Union
44

55
from redis.client import Pipeline
6+
from redis.utils import deprecated_function
67

78
from ..helpers import parse_to_dict
89
from ._util import to_string
@@ -20,6 +21,7 @@
2021
ADD_CMD = "FT.ADD"
2122
ADDHASH_CMD = "FT.ADDHASH"
2223
DROP_CMD = "FT.DROP"
24+
DROPINDEX_CMD = "FT.DROPINDEX"
2325
EXPLAIN_CMD = "FT.EXPLAIN"
2426
EXPLAINCLI_CMD = "FT.EXPLAINCLI"
2527
DEL_CMD = "FT.DEL"
@@ -170,8 +172,8 @@ def dropindex(self, delete_documents=False):
170172
171173
For more information see `FT.DROPINDEX <https://redis.io/commands/ft.dropindex>`_.
172174
""" # noqa
173-
keep_str = "" if delete_documents else "KEEPDOCS"
174-
return self.execute_command(DROP_CMD, self.index_name, keep_str)
175+
delete_str = "DD" if delete_documents else ""
176+
return self.execute_command(DROPINDEX_CMD, self.index_name, delete_str)
175177

176178
def _add_document(
177179
self,
@@ -235,6 +237,9 @@ def _add_document_hash(
235237

236238
return self.execute_command(*args)
237239

240+
@deprecated_function(
241+
version="2.0.0", reason="deprecated since redisearch 2.0, call hset instead"
242+
)
238243
def add_document(
239244
self,
240245
doc_id,
@@ -288,6 +293,9 @@ def add_document(
288293
**fields,
289294
)
290295

296+
@deprecated_function(
297+
version="2.0.0", reason="deprecated since redisearch 2.0, call hset instead"
298+
)
291299
def add_document_hash(self, doc_id, score=1.0, language=None, replace=False):
292300
"""
293301
Add a hash document to the index.

redis/commands/search/querystring.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ def __init__(self, lon, lat, radius, unit="km"):
132132
self.radius = radius
133133
self.unit = unit
134134

135+
def to_string(self):
136+
return f"[{self.lon} {self.lat} {self.radius} {self.unit}]"
137+
135138

136139
class Node:
137140
def __init__(self, *children, **kwparams):

0 commit comments

Comments
 (0)