diff --git a/server/cmd_zset.go b/server/cmd_zset.go index d51c825..eb25073 100644 --- a/server/cmd_zset.go +++ b/server/cmd_zset.go @@ -335,7 +335,17 @@ func zrangebyscoreGeneric(c *client, reverse bool) error { } key := args[0] - min, max, err := zparseScoreRange(args[1], args[2]) + + var minScore, maxScore []byte + + if !reverse { + minScore, maxScore = args[1], args[2] + } else { + minScore, maxScore = args[2], args[1] + } + + min, max, err := zparseScoreRange(minScore, maxScore) + if err != nil { return err } diff --git a/server/cmd_zset_test.go b/server/cmd_zset_test.go index 69664cf..cf512c7 100644 --- a/server/cmd_zset_test.go +++ b/server/cmd_zset_test.go @@ -264,7 +264,7 @@ func TestZSetRangeScore(t *testing.T) { } } - if v, err := ledis.MultiBulk(c.Do("zrevrangebyscore", key, 1, 4, "withscores")); err != nil { + if v, err := ledis.MultiBulk(c.Do("zrevrangebyscore", key, 4, 1, "withscores")); err != nil { t.Fatal(err) } else { if err := testZSetRange(v, "d", 4, "c", 3, "b", 2, "a", 1); err != nil { @@ -272,7 +272,7 @@ func TestZSetRangeScore(t *testing.T) { } } - if v, err := ledis.MultiBulk(c.Do("zrevrangebyscore", key, 1, 4, "withscores", "limit", 1, 2)); err != nil { + if v, err := ledis.MultiBulk(c.Do("zrevrangebyscore", key, 4, 1, "withscores", "limit", 1, 2)); err != nil { t.Fatal(err) } else { if err := testZSetRange(v, "c", 3, "b", 2); err != nil { @@ -280,7 +280,7 @@ func TestZSetRangeScore(t *testing.T) { } } - if v, err := ledis.MultiBulk(c.Do("zrevrangebyscore", key, "-inf", "+inf", "withscores")); err != nil { + if v, err := ledis.MultiBulk(c.Do("zrevrangebyscore", key, "+inf", "-inf", "withscores")); err != nil { t.Fatal(err) } else { if err := testZSetRange(v, "d", 4, "c", 3, "b", 2, "a", 1); err != nil { @@ -288,7 +288,7 @@ func TestZSetRangeScore(t *testing.T) { } } - if v, err := ledis.MultiBulk(c.Do("zrevrangebyscore", key, "(1", "(4")); err != nil { + if v, err := ledis.MultiBulk(c.Do("zrevrangebyscore", key, "(4", "(1")); err != nil { t.Fatal(err) } else { if err := testZSetRange(v, "c", "b"); err != nil {