Skip to content

Commit

Permalink
fix:issue with ZRANGE and ZRANGESTORE with BYLEX (#214)
Browse files Browse the repository at this point in the history
Fix #203
  • Loading branch information
cunla authored Jul 18, 2023
1 parent 640faeb commit a08ec67
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
6 changes: 6 additions & 0 deletions fakeredis/_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ def __gt__(self, other):
def __eq__(self, other):
return isinstance(other, BeforeAny)

def __hash__(self):
return 1


@functools.total_ordering
class AfterAny:
Expand All @@ -247,6 +250,9 @@ def __lt__(self, other):
def __eq__(self, other):
return isinstance(other, AfterAny)

def __hash__(self):
return 1


class ScoreTest:
"""Argument converter for sorted set score endpoints."""
Expand Down
6 changes: 4 additions & 2 deletions fakeredis/_zset.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ def islice_score(self, start, stop, reverse=False):
def irange_lex(self, start, stop, inclusive=(True, True), reverse=False):
if not self._byscore:
return iter([])
score = self._byscore[0][0]
it = self._byscore.irange((score, start), (score, stop),
default_score = self._byscore[0][0]
start_score = self._bylex.get(start, default_score)
stop_score = self._bylex.get(stop, default_score)
it = self._byscore.irange((start_score, start), (stop_score, stop),
inclusive=inclusive, reverse=reverse)
return (item[1] for item in it)

Expand Down
7 changes: 3 additions & 4 deletions test/test_mixins/test_sortedset_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,10 +1164,9 @@ def test_zrangestore(r: redis.Redis):
assert r.zrangestore("b", "a", 2, 1, byscore=True, offset=0, num=1, desc=True)
assert r.zrange("b", 0, -1) == [b"a2"]
# by lex
# TODO: fix
# assert r.zrange("a", "[a2", "(a3", bylex=True, offset=0, num=1) == [b"a2"]
# assert r.zrangestore("b", "a", "[a2", "(a3", bylex=True, offset=0, num=1)
# assert r.zrange("b", 0, -1) == [b"a2"]
assert r.zrange("a", "[a2", "(a3", bylex=True, offset=0, num=1) == [b"a2"]
assert r.zrangestore("b", "a", "[a2", "(a3", bylex=True, offset=0, num=1)
assert r.zrange("b", 0, -1) == [b"a2"]


@pytest.mark.min_server('7')
Expand Down
2 changes: 2 additions & 0 deletions test/test_mixins/test_transactions_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ def test_get_within_pipeline(r: redis.Redis):
p.watch("test")
assert set(r.keys()) == expected_keys


@pytest.mark.fake
def test_get_within_pipeline_w_host():
r = fakeredis.FakeRedis('localhost')
Expand All @@ -329,6 +330,7 @@ def test_get_within_pipeline_w_host():
p.watch("test")
assert set(r.keys()) == expected_keys


@pytest.mark.fake
def test_get_within_pipeline_no_args():
r = fakeredis.FakeRedis()
Expand Down

0 comments on commit a08ec67

Please sign in to comment.