From 45e45f842245a6bcb9daa107c68ca1ebaa4537f2 Mon Sep 17 00:00:00 2001 From: blaxill Date: Mon, 24 Jun 2013 19:33:39 +0200 Subject: [PATCH] Fix ZRevRangeByScoreWithScores to return scores. --- commands.go | 2 +- redis_test.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/commands.go b/commands.go index db363b0..4c03583 100644 --- a/commands.go +++ b/commands.go @@ -928,7 +928,7 @@ func (c *Client) ZRevRangeByScore(key, start, stop string, offset, count int64) } func (c *Client) ZRevRangeByScoreWithScores(key, start, stop string, offset, count int64) *StringSliceReq { - return c.zRevRangeByScore(key, start, stop, false, offset, count) + return c.zRevRangeByScore(key, start, stop, true, offset, count) } func (c *Client) ZRevRangeByScoreWithScoresMap( diff --git a/redis_test.go b/redis_test.go index 1e5f537..e960ca1 100644 --- a/redis_test.go +++ b/redis_test.go @@ -2038,6 +2038,31 @@ func (t *RedisTest) TestZRangeByScore(c *C) { c.Assert(zRangeByScore.Val(), DeepEquals, []string{}) } +func (t *RedisTest) TestZRangeByScoreWithScores(c *C) { + zAdd := t.client.ZAdd("zset", redis.Z{1, "one"}) + c.Assert(zAdd.Err(), IsNil) + zAdd = t.client.ZAdd("zset", redis.Z{2, "two"}) + c.Assert(zAdd.Err(), IsNil) + zAdd = t.client.ZAdd("zset", redis.Z{3, "three"}) + c.Assert(zAdd.Err(), IsNil) + + zRangeByScore := t.client.ZRangeByScoreWithScores("zset", "-inf", "+inf", 0, 0) + c.Assert(zRangeByScore.Err(), IsNil) + c.Assert(zRangeByScore.Val(), DeepEquals, []string{"one", "1", "two", "2", "three", "3"}) + + zRangeByScore = t.client.ZRangeByScoreWithScores("zset", "1", "2", 0, 0) + c.Assert(zRangeByScore.Err(), IsNil) + c.Assert(zRangeByScore.Val(), DeepEquals, []string{"one", "1", "two", "2"}) + + zRangeByScore = t.client.ZRangeByScoreWithScores("zset", "(1", "2", 0, 0) + c.Assert(zRangeByScore.Err(), IsNil) + c.Assert(zRangeByScore.Val(), DeepEquals, []string{"two", "2"}) + + zRangeByScore = t.client.ZRangeByScoreWithScores("zset", "(1", "(2", 0, 0) + c.Assert(zRangeByScore.Err(), IsNil) + c.Assert(zRangeByScore.Val(), DeepEquals, []string{}) +} + func (t *RedisTest) TestZRangeByScoreWithScoresMap(c *C) { zAdd := t.client.ZAdd("zset", redis.Z{1, "one"}) c.Assert(zAdd.Err(), IsNil) @@ -2194,6 +2219,27 @@ func (t *RedisTest) TestZRevRangeByScore(c *C) { c.Assert(zRevRangeByScore.Val(), DeepEquals, []string{}) } +func (t *RedisTest) TestZRevRangeByScoreWithScores(c *C) { + zAdd := t.client.ZAdd("zset", redis.Z{1, "one"}) + c.Assert(zAdd.Err(), IsNil) + zAdd = t.client.ZAdd("zset", redis.Z{2, "two"}) + c.Assert(zAdd.Err(), IsNil) + zAdd = t.client.ZAdd("zset", redis.Z{3, "three"}) + c.Assert(zAdd.Err(), IsNil) + + zRevRangeByScore := t.client.ZRevRangeByScoreWithScores("zset", "+inf", "-inf", 0, 0) + c.Assert(zRevRangeByScore.Err(), IsNil) + c.Assert(zRevRangeByScore.Val(), DeepEquals, []string{"three", "3", "two", "2", "one", "1"}) + + zRevRangeByScore = t.client.ZRevRangeByScoreWithScores("zset", "2", "(1", 0, 0) + c.Assert(zRevRangeByScore.Err(), IsNil) + c.Assert(zRevRangeByScore.Val(), DeepEquals, []string{"two", "2"}) + + zRevRangeByScore = t.client.ZRevRangeByScoreWithScores("zset", "(2", "(1", 0, 0) + c.Assert(zRevRangeByScore.Err(), IsNil) + c.Assert(zRevRangeByScore.Val(), DeepEquals, []string{}) +} + func (t *RedisTest) TestZRevRangeByScoreWithScoresMap(c *C) { zAdd := t.client.ZAdd("zset", redis.Z{1, "one"}) c.Assert(zAdd.Err(), IsNil)