bugfix for revrangebyscore command

min and max score param position may be same as redis
This commit is contained in:
siddontang 2014-07-01 07:55:34 +08:00
parent d5cd9e10eb
commit 1e6bcc6a50
2 changed files with 15 additions and 5 deletions

View File

@ -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
}

View File

@ -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 {