diff --git a/cmd_sorted_set.go b/cmd_sorted_set.go index 9bff614f..7184befc 100644 --- a/cmd_sorted_set.go +++ b/cmd_sorted_set.go @@ -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 } } @@ -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 { diff --git a/cmd_sorted_set_test.go b/cmd_sorted_set_test.go index a9ff5dfa..a70d0a92 100644 --- a/cmd_sorted_set_test.go +++ b/cmd_sorted_set_test.go @@ -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{ diff --git a/integration/sorted_set_test.go b/integration/sorted_set_test.go index c80d4403..7c01302e 100644 --- a/integration/sorted_set_test.go +++ b/integration/sorted_set_test.go @@ -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) {