Skip to content

Commit

Permalink
Merge pull request #102 from alicebob/lex
Browse files Browse the repository at this point in the history
zrangebylex test
  • Loading branch information
alicebob authored Aug 17, 2019
2 parents 4acafe3 + 7d1fb49 commit 0195e13
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd_sorted_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -1125,10 +1125,12 @@ func withLexRange(members []string, min string, minIncl bool, max string, maxInc
return nil
}
if min != "-" {
found := false
if minIncl {
for i, m := range members {
if m >= min {
members = members[i:]
found = true
break
}
}
Expand All @@ -1137,10 +1139,14 @@ func withLexRange(members []string, min string, minIncl bool, max string, maxInc
for i, m := range members {
if m > min {
members = members[i:]
found = true
break
}
}
}
if !found {
return nil
}
}
if max != "+" {
if maxIncl {
Expand Down
4 changes: 4 additions & 0 deletions cmd_sorted_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,10 @@ func TestSortedSetRangeByLex(t *testing.T) {
"zwei",
}, b)

b, err = redis.Strings(c.Do("ZRANGEBYLEX", "z", "[zz", "+"))
ok(t, err)
equals(t, []string{}, b)

b, err = redis.Strings(c.Do("ZREVRANGEBYLEX", "z", "+", "-"))
ok(t, err)
equals(t, []string{
Expand Down
6 changes: 6 additions & 0 deletions integration/sorted_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,12 @@ func TestSortedSetRangeByLex(t *testing.T) {
fail("ZLEXCOUNT", "key", "!a", "[b"),
fail("ZLEXCOUNT", "str", "[a", "[b"),
)

testCommands(t,
succ("ZADD", "idx", 0, "ccc"),
succ("ZRANGEBYLEX", "idx", "[d", "[e"),
succ("ZRANGEBYLEX", "idx", "[c", "[d"),
)
}

func TestSortedSetIncyby(t *testing.T) {
Expand Down

0 comments on commit 0195e13

Please sign in to comment.