diff options
author | Avital Fine <79420960+AvitalFineRedis@users.noreply.github.com> | 2021-11-08 16:51:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-08 17:51:54 +0200 |
commit | ea04bae5e082ff71aaa1f9a9d07d9bda10b7696e (patch) | |
tree | 760ced42882ae6ba995f39e97f9e30446d741713 /redis/commands | |
parent | bba75187931af84dd21c91bcf1b3bd422c9aed72 (diff) | |
download | redis-py-ea04bae5e082ff71aaa1f9a9d07d9bda10b7696e.tar.gz |
Restore zrange functionality for older versions of Redis (#1670)
Diffstat (limited to 'redis/commands')
-rw-r--r-- | redis/commands/core.py | 62 |
1 files changed, 48 insertions, 14 deletions
diff --git a/redis/commands/core.py b/redis/commands/core.py index 8dba5a2..90997ff 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -2536,9 +2536,14 @@ class CoreCommands: ``score_cast_func`` a callable used to cast the score return value """ - return self.zrange(name, start, end, desc=True, - withscores=withscores, - score_cast_func=score_cast_func) + pieces = ['ZREVRANGE', name, start, end] + if withscores: + pieces.append(b'WITHSCORES') + options = { + 'withscores': withscores, + 'score_cast_func': score_cast_func + } + return self.execute_command(*pieces, **options) def zrangestore(self, dest, name, start, end, byscore=False, bylex=False, desc=False, @@ -2575,7 +2580,13 @@ class CoreCommands: If ``start`` and ``num`` are specified, then return a slice of the range. """ - return self.zrange(name, min, max, bylex=True, offset=start, num=num) + if (start is not None and num is None) or \ + (num is not None and start is None): + raise DataError("``start`` and ``num`` must both be specified") + pieces = ['ZRANGEBYLEX', name, min, max] + if start is not None and num is not None: + pieces.extend([b'LIMIT', start, num]) + return self.execute_command(*pieces) def zrevrangebylex(self, name, max, min, start=None, num=None): """ @@ -2585,8 +2596,13 @@ class CoreCommands: If ``start`` and ``num`` are specified, then return a slice of the range. """ - return self.zrange(name, max, min, desc=True, - bylex=True, offset=start, num=num) + if (start is not None and num is None) or \ + (num is not None and start is None): + raise DataError("``start`` and ``num`` must both be specified") + pieces = ['ZREVRANGEBYLEX', name, max, min] + if start is not None and num is not None: + pieces.extend(['LIMIT', start, num]) + return self.execute_command(*pieces) def zrangebyscore(self, name, min, max, start=None, num=None, withscores=False, score_cast_func=float): @@ -2602,10 +2618,19 @@ class CoreCommands: `score_cast_func`` a callable used to cast the score return value """ - return self.zrange(name, min, max, byscore=True, - offset=start, num=num, - withscores=withscores, - score_cast_func=score_cast_func) + if (start is not None and num is None) or \ + (num is not None and start is None): + raise DataError("``start`` and ``num`` must both be specified") + pieces = ['ZRANGEBYSCORE', name, min, max] + if start is not None and num is not None: + pieces.extend(['LIMIT', start, num]) + if withscores: + pieces.append('WITHSCORES') + options = { + 'withscores': withscores, + 'score_cast_func': score_cast_func + } + return self.execute_command(*pieces, **options) def zrevrangebyscore(self, name, max, min, start=None, num=None, withscores=False, score_cast_func=float): @@ -2621,10 +2646,19 @@ class CoreCommands: ``score_cast_func`` a callable used to cast the score return value """ - return self.zrange(name, max, min, desc=True, - byscore=True, offset=start, - num=num, withscores=withscores, - score_cast_func=score_cast_func) + if (start is not None and num is None) or \ + (num is not None and start is None): + raise DataError("``start`` and ``num`` must both be specified") + pieces = ['ZREVRANGEBYSCORE', name, max, min] + if start is not None and num is not None: + pieces.extend(['LIMIT', start, num]) + if withscores: + pieces.append('WITHSCORES') + options = { + 'withscores': withscores, + 'score_cast_func': score_cast_func + } + return self.execute_command(*pieces, **options) def zrank(self, name, value): """ |