From 2de07f24930aaf7f4f0d6c34656fcf5229675bbd Mon Sep 17 00:00:00 2001 From: Jeff Pierce Date: Sat, 22 Aug 2015 20:38:37 -0700 Subject: [PATCH 1/5] Implemented ZRangeByLex with tests. --- commands.go | 16 +++++++++++++--- commands_test.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/commands.go b/commands.go index 887fd737..b07a8046 100644 --- a/commands.go +++ b/commands.go @@ -1094,8 +1094,14 @@ type ZRangeByScore struct { Offset, Count int64 } -func (c *commandable) zRangeByScore(key string, opt ZRangeByScore, withScores bool) *StringSliceCmd { - args := []interface{}{"ZRANGEBYSCORE", key, opt.Min, opt.Max} +func (c *commandable) zRangeByScore(key string, opt ZRangeByScore, withScores, isLex bool) *StringSliceCmd { + var zcmd string + if isLex { + zcmd = "ZRANGEBYLEX" + } else { + zcmd = "ZRANGEBYSCORE" + } + args := []interface{}{zcmd, key, opt.Min, opt.Max} if withScores { args = append(args, "WITHSCORES") } @@ -1113,7 +1119,11 @@ func (c *commandable) zRangeByScore(key string, opt ZRangeByScore, withScores bo } func (c *commandable) ZRangeByScore(key string, opt ZRangeByScore) *StringSliceCmd { - return c.zRangeByScore(key, opt, false) + return c.zRangeByScore(key, opt, false, false) +} + +func (c *commandable) ZRangeByLex(key string, opt ZRangeByScore) *StringSliceCmd { + return c.zRangeByScore(key, opt, false, true) } func (c *commandable) ZRangeByScoreWithScores(key string, opt ZRangeByScore) *ZSliceCmd { diff --git a/commands_test.go b/commands_test.go index 6cd9fc06..d0dbe43c 100644 --- a/commands_test.go +++ b/commands_test.go @@ -2010,6 +2010,42 @@ var _ = Describe("Commands", func() { Expect(zRangeByScore.Val()).To(Equal([]string{})) }) + It("should ZRangeByLex", func() { + zAdd := client.ZAdd("zset", redis.Z{0, "a"}) + Expect(zAdd.Err()).NotTo(HaveOccurred()) + zAdd = client.ZAdd("zset", redis.Z{0, "b"}) + Expect(zAdd.Err()).NotTo(HaveOccurred()) + zAdd = client.ZAdd("zset", redis.Z{0, "c"}) + + zRangeByLex := client.ZRangeByLex("zset", redis.ZRangeByScore{ + Min: "-", + Max: "+", + }) + Expect(zRangeByLex.Err()).NotTo(HaveOccurred()) + Expect(zRangeByLex.Val()).To(Equal([]string{"a", "b", "c"})) + + zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeByScore{ + Min: "[a", + Max: "[b", + }) + Expect(zRangeByLex.Err()).NotTo(HaveOccurred()) + Expect(zRangeByLex.Val()).To(Equal([]string{"a", "b"})) + + zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeByScore{ + Min: "(a", + Max: "[b", + }) + Expect(zRangeByLex.Err()).NotTo(HaveOccurred()) + Expect(zRangeByLex.Val()).To(Equal([]string{"b"})) + + zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeByScore{ + Min: "(a", + Max: "(b", + }) + Expect(zRangeByLex.Err()).NotTo(HaveOccurred()) + Expect(zRangeByLex.Val()).To(Equal([]string{})) + }) + It("should ZRangeByScoreWithScoresMap", func() { zAdd := client.ZAdd("zset", redis.Z{1, "one"}) Expect(zAdd.Err()).NotTo(HaveOccurred()) From 2abf5c5f146e7ce1740eb1ed942596459b71ce1e Mon Sep 17 00:00:00 2001 From: Jeff Pierce Date: Mon, 24 Aug 2015 14:52:00 -0700 Subject: [PATCH 2/5] Refactored zRangeByScore into zRangeBy. --- commands.go | 26 ++++++++++---------------- commands_test.go | 24 ++++++++++++------------ 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/commands.go b/commands.go index b07a8046..a289cd32 100644 --- a/commands.go +++ b/commands.go @@ -1089,19 +1089,13 @@ func (c *commandable) ZRangeWithScores(key string, start, stop int64) *ZSliceCmd return cmd } -type ZRangeByScore struct { +type ZRangeBy struct { Min, Max string Offset, Count int64 } -func (c *commandable) zRangeByScore(key string, opt ZRangeByScore, withScores, isLex bool) *StringSliceCmd { - var zcmd string - if isLex { - zcmd = "ZRANGEBYLEX" - } else { - zcmd = "ZRANGEBYSCORE" - } - args := []interface{}{zcmd, key, opt.Min, opt.Max} +func (c *commandable) zRangeBy(zRangeType, key string, opt ZRangeBy, withScores bool) *StringSliceCmd { + args := []interface{}{zRangeType, key, opt.Min, opt.Max} if withScores { args = append(args, "WITHSCORES") } @@ -1118,15 +1112,15 @@ func (c *commandable) zRangeByScore(key string, opt ZRangeByScore, withScores, i return cmd } -func (c *commandable) ZRangeByScore(key string, opt ZRangeByScore) *StringSliceCmd { - return c.zRangeByScore(key, opt, false, false) +func (c *commandable) ZRangeByScore(key string, opt ZRangeBy) *StringSliceCmd { + return c.zRangeBy("ZRANGEBYSCORE", key, opt, false) } -func (c *commandable) ZRangeByLex(key string, opt ZRangeByScore) *StringSliceCmd { - return c.zRangeByScore(key, opt, false, true) +func (c *commandable) ZRangeByLex(key string, opt ZRangeBy) *StringSliceCmd { + return c.zRangeBy("ZRANGEBYLEX", key, opt, false) } -func (c *commandable) ZRangeByScoreWithScores(key string, opt ZRangeByScore) *ZSliceCmd { +func (c *commandable) ZRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd { args := []interface{}{"ZRANGEBYSCORE", key, opt.Min, opt.Max, "WITHSCORES"} if opt.Offset != 0 || opt.Count != 0 { args = append( @@ -1188,7 +1182,7 @@ func (c *commandable) ZRevRangeWithScores(key string, start, stop int64) *ZSlice return cmd } -func (c *commandable) ZRevRangeByScore(key string, opt ZRangeByScore) *StringSliceCmd { +func (c *commandable) ZRevRangeByScore(key string, opt ZRangeBy) *StringSliceCmd { args := []interface{}{"ZREVRANGEBYSCORE", key, opt.Max, opt.Min} if opt.Offset != 0 || opt.Count != 0 { args = append( @@ -1203,7 +1197,7 @@ func (c *commandable) ZRevRangeByScore(key string, opt ZRangeByScore) *StringSli return cmd } -func (c *commandable) ZRevRangeByScoreWithScores(key string, opt ZRangeByScore) *ZSliceCmd { +func (c *commandable) ZRevRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd { args := []interface{}{"ZREVRANGEBYSCORE", key, opt.Max, opt.Min, "WITHSCORES"} if opt.Offset != 0 || opt.Count != 0 { args = append( diff --git a/commands_test.go b/commands_test.go index d0dbe43c..4ef419e8 100644 --- a/commands_test.go +++ b/commands_test.go @@ -1981,28 +1981,28 @@ var _ = Describe("Commands", func() { zAdd = client.ZAdd("zset", redis.Z{3, "three"}) Expect(zAdd.Err()).NotTo(HaveOccurred()) - zRangeByScore := client.ZRangeByScore("zset", redis.ZRangeByScore{ + zRangeByScore := client.ZRangeByScore("zset", redis.ZRangeBy{ Min: "-inf", Max: "+inf", }) Expect(zRangeByScore.Err()).NotTo(HaveOccurred()) Expect(zRangeByScore.Val()).To(Equal([]string{"one", "two", "three"})) - zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeByScore{ + zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeBy{ Min: "1", Max: "2", }) Expect(zRangeByScore.Err()).NotTo(HaveOccurred()) Expect(zRangeByScore.Val()).To(Equal([]string{"one", "two"})) - zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeByScore{ + zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeBy{ Min: "(1", Max: "2", }) Expect(zRangeByScore.Err()).NotTo(HaveOccurred()) Expect(zRangeByScore.Val()).To(Equal([]string{"two"})) - zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeByScore{ + zRangeByScore = client.ZRangeByScore("ZRANGEBYSCORE", "zset", redis.ZRangeBy{ Min: "(1", Max: "(2", }) @@ -2017,28 +2017,28 @@ var _ = Describe("Commands", func() { Expect(zAdd.Err()).NotTo(HaveOccurred()) zAdd = client.ZAdd("zset", redis.Z{0, "c"}) - zRangeByLex := client.ZRangeByLex("zset", redis.ZRangeByScore{ + zRangeByLex := client.ZRangeByLex("zset", redis.ZRangeBy{ Min: "-", Max: "+", }) Expect(zRangeByLex.Err()).NotTo(HaveOccurred()) Expect(zRangeByLex.Val()).To(Equal([]string{"a", "b", "c"})) - zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeByScore{ + zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeBy{ Min: "[a", Max: "[b", }) Expect(zRangeByLex.Err()).NotTo(HaveOccurred()) Expect(zRangeByLex.Val()).To(Equal([]string{"a", "b"})) - zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeByScore{ + zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeBy{ Min: "(a", Max: "[b", }) Expect(zRangeByLex.Err()).NotTo(HaveOccurred()) Expect(zRangeByLex.Val()).To(Equal([]string{"b"})) - zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeByScore{ + zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeBy{ Min: "(a", Max: "(b", }) @@ -2054,28 +2054,28 @@ var _ = Describe("Commands", func() { zAdd = client.ZAdd("zset", redis.Z{3, "three"}) Expect(zAdd.Err()).NotTo(HaveOccurred()) - val, err := client.ZRangeByScoreWithScores("zset", redis.ZRangeByScore{ + val, err := client.ZRangeByScoreWithScores("zset", redis.ZRangeBy{ Min: "-inf", Max: "+inf", }).Result() Expect(err).NotTo(HaveOccurred()) Expect(val).To(Equal([]redis.Z{{1, "one"}, {2, "two"}, {3, "three"}})) - val, err = client.ZRangeByScoreWithScores("zset", redis.ZRangeByScore{ + val, err = client.ZRangeByScoreWithScores("zset", redis.ZRangeBy{ Min: "1", Max: "2", }).Result() Expect(err).NotTo(HaveOccurred()) Expect(val).To(Equal([]redis.Z{{1, "one"}, {2, "two"}})) - val, err = client.ZRangeByScoreWithScores("zset", redis.ZRangeByScore{ + val, err = client.ZRangeByScoreWithScores("zset", redis.ZRangeBy{ Min: "(1", Max: "2", }).Result() Expect(err).NotTo(HaveOccurred()) Expect(val).To(Equal([]redis.Z{{2, "two"}})) - val, err = client.ZRangeByScoreWithScores("zset", redis.ZRangeByScore{ + val, err = client.ZRangeByScoreWithScores("zset", redis.ZRangeBy{ Min: "(1", Max: "(2", }).Result() From 15c887f70091e468b44c76af8e6a323b70195896 Mon Sep 17 00:00:00 2001 From: Jeff Pierce Date: Mon, 24 Aug 2015 15:01:32 -0700 Subject: [PATCH 3/5] Fixed tests. --- commands_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/commands_test.go b/commands_test.go index 4ef419e8..78a9fbc1 100644 --- a/commands_test.go +++ b/commands_test.go @@ -2002,7 +2002,7 @@ var _ = Describe("Commands", func() { Expect(zRangeByScore.Err()).NotTo(HaveOccurred()) Expect(zRangeByScore.Val()).To(Equal([]string{"two"})) - zRangeByScore = client.ZRangeByScore("ZRANGEBYSCORE", "zset", redis.ZRangeBy{ + zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeBy{ Min: "(1", Max: "(2", }) @@ -2202,17 +2202,17 @@ var _ = Describe("Commands", func() { Expect(zadd.Err()).NotTo(HaveOccurred()) vals, err := client.ZRevRangeByScore( - "zset", redis.ZRangeByScore{Max: "+inf", Min: "-inf"}).Result() + "zset", redis.ZRangeBy{Max: "+inf", Min: "-inf"}).Result() Expect(err).NotTo(HaveOccurred()) Expect(vals).To(Equal([]string{"three", "two", "one"})) vals, err = client.ZRevRangeByScore( - "zset", redis.ZRangeByScore{Max: "2", Min: "(1"}).Result() + "zset", redis.ZRangeBy{Max: "2", Min: "(1"}).Result() Expect(err).NotTo(HaveOccurred()) Expect(vals).To(Equal([]string{"two"})) vals, err = client.ZRevRangeByScore( - "zset", redis.ZRangeByScore{Max: "(2", Min: "(1"}).Result() + "zset", redis.ZRangeBy{Max: "(2", Min: "(1"}).Result() Expect(err).NotTo(HaveOccurred()) Expect(vals).To(Equal([]string{})) }) @@ -2226,7 +2226,7 @@ var _ = Describe("Commands", func() { Expect(zadd.Err()).NotTo(HaveOccurred()) vals, err := client.ZRevRangeByScoreWithScores( - "zset", redis.ZRangeByScore{Max: "+inf", Min: "-inf"}).Result() + "zset", redis.ZRangeBy{Max: "+inf", Min: "-inf"}).Result() Expect(err).NotTo(HaveOccurred()) Expect(vals).To(Equal([]redis.Z{{3, "three"}, {2, "two"}, {1, "one"}})) }) @@ -2240,17 +2240,17 @@ var _ = Describe("Commands", func() { Expect(zAdd.Err()).NotTo(HaveOccurred()) val, err := client.ZRevRangeByScoreWithScores( - "zset", redis.ZRangeByScore{Max: "+inf", Min: "-inf"}).Result() + "zset", redis.ZRangeBy{Max: "+inf", Min: "-inf"}).Result() Expect(err).NotTo(HaveOccurred()) Expect(val).To(Equal([]redis.Z{{3, "three"}, {2, "two"}, {1, "one"}})) val, err = client.ZRevRangeByScoreWithScores( - "zset", redis.ZRangeByScore{Max: "2", Min: "(1"}).Result() + "zset", redis.ZRangeBy{Max: "2", Min: "(1"}).Result() Expect(err).NotTo(HaveOccurred()) Expect(val).To(Equal([]redis.Z{{2, "two"}})) val, err = client.ZRevRangeByScoreWithScores( - "zset", redis.ZRangeByScore{Max: "(2", Min: "(1"}).Result() + "zset", redis.ZRangeBy{Max: "(2", Min: "(1"}).Result() Expect(err).NotTo(HaveOccurred()) Expect(val).To(Equal([]redis.Z{})) }) From 5498ba400da826ef70e8829563fb2c8585d35cd2 Mon Sep 17 00:00:00 2001 From: Jeff Pierce Date: Tue, 25 Aug 2015 12:15:01 -0700 Subject: [PATCH 4/5] Reverted change to struct ZRangeByScore, implemented ZRevRangeByLex. --- commands.go | 27 ++++++++++++++------- commands_test.go | 62 +++++++++++++++++++++++++++++++++--------------- 2 files changed, 61 insertions(+), 28 deletions(-) diff --git a/commands.go b/commands.go index a289cd32..a601645d 100644 --- a/commands.go +++ b/commands.go @@ -1089,13 +1089,14 @@ func (c *commandable) ZRangeWithScores(key string, start, stop int64) *ZSliceCmd return cmd } -type ZRangeBy struct { +// TODO: Rename to something more generic in v4 +type ZRangeByScore struct { Min, Max string Offset, Count int64 } -func (c *commandable) zRangeBy(zRangeType, key string, opt ZRangeBy, withScores bool) *StringSliceCmd { - args := []interface{}{zRangeType, key, opt.Min, opt.Max} +func (c *commandable) zRangeBy(zcmd, key string, opt ZRangeByScore, withScores bool) *StringSliceCmd { + args := []interface{}{zcmd, key, opt.Min, opt.Max} if withScores { args = append(args, "WITHSCORES") } @@ -1112,15 +1113,15 @@ func (c *commandable) zRangeBy(zRangeType, key string, opt ZRangeBy, withScores return cmd } -func (c *commandable) ZRangeByScore(key string, opt ZRangeBy) *StringSliceCmd { +func (c *commandable) ZRangeByScore(key string, opt ZRangeByScore) *StringSliceCmd { return c.zRangeBy("ZRANGEBYSCORE", key, opt, false) } -func (c *commandable) ZRangeByLex(key string, opt ZRangeBy) *StringSliceCmd { +func (c *commandable) ZRangeByLex(key string, opt ZRangeByScore) *StringSliceCmd { return c.zRangeBy("ZRANGEBYLEX", key, opt, false) } -func (c *commandable) ZRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd { +func (c *commandable) ZRangeByScoreWithScores(key string, opt ZRangeByScore) *ZSliceCmd { args := []interface{}{"ZRANGEBYSCORE", key, opt.Min, opt.Max, "WITHSCORES"} if opt.Offset != 0 || opt.Count != 0 { args = append( @@ -1182,8 +1183,8 @@ func (c *commandable) ZRevRangeWithScores(key string, start, stop int64) *ZSlice return cmd } -func (c *commandable) ZRevRangeByScore(key string, opt ZRangeBy) *StringSliceCmd { - args := []interface{}{"ZREVRANGEBYSCORE", key, opt.Max, opt.Min} +func (c *commandable) zRevRangeBy(zcmd, key string, opt ZRangeByScore) *StringSliceCmd { + args := []interface{}{zcmd, key, opt.Max, opt.Min} if opt.Offset != 0 || opt.Count != 0 { args = append( args, @@ -1197,7 +1198,15 @@ func (c *commandable) ZRevRangeByScore(key string, opt ZRangeBy) *StringSliceCmd return cmd } -func (c *commandable) ZRevRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd { +func (c *commandable) ZRevRangeByScore(key string, opt ZRangeByScore) *StringSliceCmd { + return c.zRevRangeBy("ZREVRANGEBYSCORE", key, opt) +} + +func (c commandable) ZRevRangeByLex(key string, opt ZRangeByScore) *StringSliceCmd { + return c.zRevRangeBy("ZREVRANGEBYLEX", key, opt) +} + +func (c *commandable) ZRevRangeByScoreWithScores(key string, opt ZRangeByScore) *ZSliceCmd { args := []interface{}{"ZREVRANGEBYSCORE", key, opt.Max, opt.Min, "WITHSCORES"} if opt.Offset != 0 || opt.Count != 0 { args = append( diff --git a/commands_test.go b/commands_test.go index 78a9fbc1..61b06852 100644 --- a/commands_test.go +++ b/commands_test.go @@ -1981,28 +1981,28 @@ var _ = Describe("Commands", func() { zAdd = client.ZAdd("zset", redis.Z{3, "three"}) Expect(zAdd.Err()).NotTo(HaveOccurred()) - zRangeByScore := client.ZRangeByScore("zset", redis.ZRangeBy{ + zRangeByScore := client.ZRangeByScore("zset", redis.ZRangeByScore{ Min: "-inf", Max: "+inf", }) Expect(zRangeByScore.Err()).NotTo(HaveOccurred()) Expect(zRangeByScore.Val()).To(Equal([]string{"one", "two", "three"})) - zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeBy{ + zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeByScore{ Min: "1", Max: "2", }) Expect(zRangeByScore.Err()).NotTo(HaveOccurred()) Expect(zRangeByScore.Val()).To(Equal([]string{"one", "two"})) - zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeBy{ + zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeByScore{ Min: "(1", Max: "2", }) Expect(zRangeByScore.Err()).NotTo(HaveOccurred()) Expect(zRangeByScore.Val()).To(Equal([]string{"two"})) - zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeBy{ + zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeByScore{ Min: "(1", Max: "(2", }) @@ -2017,28 +2017,28 @@ var _ = Describe("Commands", func() { Expect(zAdd.Err()).NotTo(HaveOccurred()) zAdd = client.ZAdd("zset", redis.Z{0, "c"}) - zRangeByLex := client.ZRangeByLex("zset", redis.ZRangeBy{ + zRangeByLex := client.ZRangeByLex("zset", redis.ZRangeByScore{ Min: "-", Max: "+", }) Expect(zRangeByLex.Err()).NotTo(HaveOccurred()) Expect(zRangeByLex.Val()).To(Equal([]string{"a", "b", "c"})) - zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeBy{ + zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeByScore{ Min: "[a", Max: "[b", }) Expect(zRangeByLex.Err()).NotTo(HaveOccurred()) Expect(zRangeByLex.Val()).To(Equal([]string{"a", "b"})) - zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeBy{ + zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeByScore{ Min: "(a", Max: "[b", }) Expect(zRangeByLex.Err()).NotTo(HaveOccurred()) Expect(zRangeByLex.Val()).To(Equal([]string{"b"})) - zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeBy{ + zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeByScore{ Min: "(a", Max: "(b", }) @@ -2054,28 +2054,28 @@ var _ = Describe("Commands", func() { zAdd = client.ZAdd("zset", redis.Z{3, "three"}) Expect(zAdd.Err()).NotTo(HaveOccurred()) - val, err := client.ZRangeByScoreWithScores("zset", redis.ZRangeBy{ + val, err := client.ZRangeByScoreWithScores("zset", redis.ZRangeByScore{ Min: "-inf", Max: "+inf", }).Result() Expect(err).NotTo(HaveOccurred()) Expect(val).To(Equal([]redis.Z{{1, "one"}, {2, "two"}, {3, "three"}})) - val, err = client.ZRangeByScoreWithScores("zset", redis.ZRangeBy{ + val, err = client.ZRangeByScoreWithScores("zset", redis.ZRangeByScore{ Min: "1", Max: "2", }).Result() Expect(err).NotTo(HaveOccurred()) Expect(val).To(Equal([]redis.Z{{1, "one"}, {2, "two"}})) - val, err = client.ZRangeByScoreWithScores("zset", redis.ZRangeBy{ + val, err = client.ZRangeByScoreWithScores("zset", redis.ZRangeByScore{ Min: "(1", Max: "2", }).Result() Expect(err).NotTo(HaveOccurred()) Expect(val).To(Equal([]redis.Z{{2, "two"}})) - val, err = client.ZRangeByScoreWithScores("zset", redis.ZRangeBy{ + val, err = client.ZRangeByScoreWithScores("zset", redis.ZRangeByScore{ Min: "(1", Max: "(2", }).Result() @@ -2202,17 +2202,41 @@ var _ = Describe("Commands", func() { Expect(zadd.Err()).NotTo(HaveOccurred()) vals, err := client.ZRevRangeByScore( - "zset", redis.ZRangeBy{Max: "+inf", Min: "-inf"}).Result() + "zset", redis.ZRangeByScore{Max: "+inf", Min: "-inf"}).Result() Expect(err).NotTo(HaveOccurred()) Expect(vals).To(Equal([]string{"three", "two", "one"})) vals, err = client.ZRevRangeByScore( - "zset", redis.ZRangeBy{Max: "2", Min: "(1"}).Result() + "zset", redis.ZRangeByScore{Max: "2", Min: "(1"}).Result() Expect(err).NotTo(HaveOccurred()) Expect(vals).To(Equal([]string{"two"})) vals, err = client.ZRevRangeByScore( - "zset", redis.ZRangeBy{Max: "(2", Min: "(1"}).Result() + "zset", redis.ZRangeByScore{Max: "(2", Min: "(1"}).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(vals).To(Equal([]string{})) + }) + + It("should ZRevRangeByLex", func() { + zadd := client.ZAdd("zset", redis.Z{0, "a"}) + Expect(zadd.Err()).NotTo(HaveOccurred()) + zadd = client.ZAdd("zset", redis.Z{0, "b"}) + Expect(zadd.Err()).NotTo(HaveOccurred()) + zadd = client.ZAdd("zset", redis.Z{0, "c"}) + Expect(zadd.Err()).NotTo(HaveOccurred()) + + vals, err := client.ZRevRangeByLex( + "zset", redis.ZRangeByScore{Max: "+", Min: "-"}).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(vals).To(Equal([]string{"c", "b", "a"})) + + vals, err := client.ZRevRangeByLex( + "zset", redis.ZRangeByScore{Max: "[b", Min: "(a"}).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(vals).To(Equal([]string{"b"})) + + vals, err := client.ZRevRangeByLex( + "zset", redis.ZRangeByScore{Max: "(b", Min: "(a"}).Result() Expect(err).NotTo(HaveOccurred()) Expect(vals).To(Equal([]string{})) }) @@ -2226,7 +2250,7 @@ var _ = Describe("Commands", func() { Expect(zadd.Err()).NotTo(HaveOccurred()) vals, err := client.ZRevRangeByScoreWithScores( - "zset", redis.ZRangeBy{Max: "+inf", Min: "-inf"}).Result() + "zset", redis.ZRangeByScore{Max: "+inf", Min: "-inf"}).Result() Expect(err).NotTo(HaveOccurred()) Expect(vals).To(Equal([]redis.Z{{3, "three"}, {2, "two"}, {1, "one"}})) }) @@ -2240,17 +2264,17 @@ var _ = Describe("Commands", func() { Expect(zAdd.Err()).NotTo(HaveOccurred()) val, err := client.ZRevRangeByScoreWithScores( - "zset", redis.ZRangeBy{Max: "+inf", Min: "-inf"}).Result() + "zset", redis.ZRangeByScore{Max: "+inf", Min: "-inf"}).Result() Expect(err).NotTo(HaveOccurred()) Expect(val).To(Equal([]redis.Z{{3, "three"}, {2, "two"}, {1, "one"}})) val, err = client.ZRevRangeByScoreWithScores( - "zset", redis.ZRangeBy{Max: "2", Min: "(1"}).Result() + "zset", redis.ZRangeByScore{Max: "2", Min: "(1"}).Result() Expect(err).NotTo(HaveOccurred()) Expect(val).To(Equal([]redis.Z{{2, "two"}})) val, err = client.ZRevRangeByScoreWithScores( - "zset", redis.ZRangeBy{Max: "(2", Min: "(1"}).Result() + "zset", redis.ZRangeByScore{Max: "(2", Min: "(1"}).Result() Expect(err).NotTo(HaveOccurred()) Expect(val).To(Equal([]redis.Z{})) }) From 7cafa2f3a5aca129d684384809cb8ef847796d07 Mon Sep 17 00:00:00 2001 From: Jeff Pierce Date: Tue, 25 Aug 2015 12:18:17 -0700 Subject: [PATCH 5/5] Fixed syntax on ZRevRangeByLex test. --- commands_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands_test.go b/commands_test.go index 61b06852..2ca079fb 100644 --- a/commands_test.go +++ b/commands_test.go @@ -2230,12 +2230,12 @@ var _ = Describe("Commands", func() { Expect(err).NotTo(HaveOccurred()) Expect(vals).To(Equal([]string{"c", "b", "a"})) - vals, err := client.ZRevRangeByLex( + vals, err = client.ZRevRangeByLex( "zset", redis.ZRangeByScore{Max: "[b", Min: "(a"}).Result() Expect(err).NotTo(HaveOccurred()) Expect(vals).To(Equal([]string{"b"})) - vals, err := client.ZRevRangeByLex( + vals, err = client.ZRevRangeByLex( "zset", redis.ZRangeByScore{Max: "(b", Min: "(a"}).Result() Expect(err).NotTo(HaveOccurred()) Expect(vals).To(Equal([]string{}))