Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-added zrevrangebylex #667

Merged
merged 2 commits into from
Oct 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
get stuck in an endless loop if a specific number of bytes were
delivered from the socket. This fix also increases performance of
parsing large responses from the Redis server.
* Added support for ZREVRANGEBYLEX.
* 2.10.3
* Fixed a bug with the bytearray support introduced in 2.10.2. Thanks
Josh Owen.
Expand Down
16 changes: 16 additions & 0 deletions redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,22 @@ def zrangebylex(self, name, min, max, start=None, num=None):
pieces.extend([Token('LIMIT'), start, num])
return self.execute_command(*pieces)

def zrevrangebylex(self, name, max, min, start=None, num=None):
"""
Return the reversed lexicographical range of values from sorted set
``name`` between ``max`` and ``min``.

If ``start`` and ``num`` are specified, then return a slice of the
range.
"""
if (start is not None and num is None) or \
(num is not None and start is None):
raise RedisError("``start`` and ``num`` must both be specified")
pieces = ['ZREVRANGEBYLEX', name, max, min]
if start is not None and num is not None:
pieces.extend([Token('LIMIT'), start, num])
return self.execute_command(*pieces)

def zrangebyscore(self, name, min, max, start=None, num=None,
withscores=False, score_cast_func=float):
"""
Expand Down
11 changes: 11 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,17 @@ def test_zrangebylex(self, r):
assert r.zrangebylex('a', '[f', '+') == [b('f'), b('g')]
assert r.zrangebylex('a', '-', '+', start=3, num=2) == [b('d'), b('e')]

@skip_if_server_version_lt('2.9.9')
def test_zrevrangebylex(self, r):
r.zadd('a', a=0, b=0, c=0, d=0, e=0, f=0, g=0)
assert r.zrevrangebylex('a', '[c', '-') == [b('c'), b('b'), b('a')]
assert r.zrevrangebylex('a', '(c', '-') == [b('b'), b('a')]
assert r.zrevrangebylex('a', '(g', '[aaa') == \
[b('f'), b('e'), b('d'), b('c'), b('b')]
assert r.zrevrangebylex('a', '+', '[f') == [b('g'), b('f')]
assert r.zrevrangebylex('a', '+', '-', start=3, num=2) == \
[b('d'), b('c')]

def test_zrangebyscore(self, r):
r.zadd('a', a1=1, a2=2, a3=3, a4=4, a5=5)
assert r.zrangebyscore('a', 2, 4) == [b('a2'), b('a3'), b('a4')]
Expand Down