Rename ZRangeByScore to ZRange since it is used in ZRangeByLex.

This commit is contained in:
Vladimir Mihailenco 2016-04-09 13:15:33 +03:00
parent 294973c76f
commit 51349cd90e
2 changed files with 31 additions and 32 deletions

View File

@ -1169,13 +1169,12 @@ func (c *commandable) ZRangeWithScores(key string, start, stop int64) *ZSliceCmd
return cmd return cmd
} }
// TODO: Rename to something more generic in v4 type ZRangeBy struct {
type ZRangeByScore struct {
Min, Max string Min, Max string
Offset, Count int64 Offset, Count int64
} }
func (c *commandable) zRangeBy(zcmd, key string, opt ZRangeByScore, withScores bool) *StringSliceCmd { func (c *commandable) zRangeBy(zcmd, key string, opt ZRangeBy, withScores bool) *StringSliceCmd {
args := []interface{}{zcmd, key, opt.Min, opt.Max} args := []interface{}{zcmd, key, opt.Min, opt.Max}
if withScores { if withScores {
args = append(args, "WITHSCORES") args = append(args, "WITHSCORES")
@ -1193,15 +1192,15 @@ func (c *commandable) zRangeBy(zcmd, key string, opt ZRangeByScore, withScores b
return cmd return cmd
} }
func (c *commandable) ZRangeByScore(key string, opt ZRangeByScore) *StringSliceCmd { func (c *commandable) ZRangeByScore(key string, opt ZRangeBy) *StringSliceCmd {
return c.zRangeBy("ZRANGEBYSCORE", key, opt, false) return c.zRangeBy("ZRANGEBYSCORE", key, opt, false)
} }
func (c *commandable) ZRangeByLex(key string, opt ZRangeByScore) *StringSliceCmd { func (c *commandable) ZRangeByLex(key string, opt ZRangeBy) *StringSliceCmd {
return c.zRangeBy("ZRANGEBYLEX", key, opt, false) 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"} args := []interface{}{"ZRANGEBYSCORE", key, opt.Min, opt.Max, "WITHSCORES"}
if opt.Offset != 0 || opt.Count != 0 { if opt.Offset != 0 || opt.Count != 0 {
args = append( args = append(
@ -1263,7 +1262,7 @@ func (c *commandable) ZRevRangeWithScores(key string, start, stop int64) *ZSlice
return cmd return cmd
} }
func (c *commandable) zRevRangeBy(zcmd, key string, opt ZRangeByScore) *StringSliceCmd { func (c *commandable) zRevRangeBy(zcmd, key string, opt ZRangeBy) *StringSliceCmd {
args := []interface{}{zcmd, key, opt.Max, opt.Min} args := []interface{}{zcmd, key, opt.Max, opt.Min}
if opt.Offset != 0 || opt.Count != 0 { if opt.Offset != 0 || opt.Count != 0 {
args = append( args = append(
@ -1278,15 +1277,15 @@ func (c *commandable) zRevRangeBy(zcmd, key string, opt ZRangeByScore) *StringSl
return cmd return cmd
} }
func (c *commandable) ZRevRangeByScore(key string, opt ZRangeByScore) *StringSliceCmd { func (c *commandable) ZRevRangeByScore(key string, opt ZRangeBy) *StringSliceCmd {
return c.zRevRangeBy("ZREVRANGEBYSCORE", key, opt) return c.zRevRangeBy("ZREVRANGEBYSCORE", key, opt)
} }
func (c *commandable) ZRevRangeByLex(key string, opt ZRangeByScore) *StringSliceCmd { func (c *commandable) ZRevRangeByLex(key string, opt ZRangeBy) *StringSliceCmd {
return c.zRevRangeBy("ZREVRANGEBYLEX", key, opt) return c.zRevRangeBy("ZREVRANGEBYLEX", key, opt)
} }
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"} args := []interface{}{"ZREVRANGEBYSCORE", key, opt.Max, opt.Min, "WITHSCORES"}
if opt.Offset != 0 || opt.Count != 0 { if opt.Offset != 0 || opt.Count != 0 {
args = append( args = append(

View File

@ -2199,28 +2199,28 @@ var _ = Describe("Commands", func() {
zAdd = client.ZAdd("zset", redis.Z{3, "three"}) zAdd = client.ZAdd("zset", redis.Z{3, "three"})
Expect(zAdd.Err()).NotTo(HaveOccurred()) Expect(zAdd.Err()).NotTo(HaveOccurred())
zRangeByScore := client.ZRangeByScore("zset", redis.ZRangeByScore{ zRangeByScore := client.ZRangeByScore("zset", redis.ZRangeBy{
Min: "-inf", Min: "-inf",
Max: "+inf", Max: "+inf",
}) })
Expect(zRangeByScore.Err()).NotTo(HaveOccurred()) Expect(zRangeByScore.Err()).NotTo(HaveOccurred())
Expect(zRangeByScore.Val()).To(Equal([]string{"one", "two", "three"})) Expect(zRangeByScore.Val()).To(Equal([]string{"one", "two", "three"}))
zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeByScore{ zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeBy{
Min: "1", Min: "1",
Max: "2", Max: "2",
}) })
Expect(zRangeByScore.Err()).NotTo(HaveOccurred()) Expect(zRangeByScore.Err()).NotTo(HaveOccurred())
Expect(zRangeByScore.Val()).To(Equal([]string{"one", "two"})) Expect(zRangeByScore.Val()).To(Equal([]string{"one", "two"}))
zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeByScore{ zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeBy{
Min: "(1", Min: "(1",
Max: "2", Max: "2",
}) })
Expect(zRangeByScore.Err()).NotTo(HaveOccurred()) Expect(zRangeByScore.Err()).NotTo(HaveOccurred())
Expect(zRangeByScore.Val()).To(Equal([]string{"two"})) Expect(zRangeByScore.Val()).To(Equal([]string{"two"}))
zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeByScore{ zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeBy{
Min: "(1", Min: "(1",
Max: "(2", Max: "(2",
}) })
@ -2235,28 +2235,28 @@ var _ = Describe("Commands", func() {
Expect(zAdd.Err()).NotTo(HaveOccurred()) Expect(zAdd.Err()).NotTo(HaveOccurred())
zAdd = client.ZAdd("zset", redis.Z{0, "c"}) zAdd = client.ZAdd("zset", redis.Z{0, "c"})
zRangeByLex := client.ZRangeByLex("zset", redis.ZRangeByScore{ zRangeByLex := client.ZRangeByLex("zset", redis.ZRangeBy{
Min: "-", Min: "-",
Max: "+", Max: "+",
}) })
Expect(zRangeByLex.Err()).NotTo(HaveOccurred()) Expect(zRangeByLex.Err()).NotTo(HaveOccurred())
Expect(zRangeByLex.Val()).To(Equal([]string{"a", "b", "c"})) Expect(zRangeByLex.Val()).To(Equal([]string{"a", "b", "c"}))
zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeByScore{ zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeBy{
Min: "[a", Min: "[a",
Max: "[b", Max: "[b",
}) })
Expect(zRangeByLex.Err()).NotTo(HaveOccurred()) Expect(zRangeByLex.Err()).NotTo(HaveOccurred())
Expect(zRangeByLex.Val()).To(Equal([]string{"a", "b"})) Expect(zRangeByLex.Val()).To(Equal([]string{"a", "b"}))
zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeByScore{ zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeBy{
Min: "(a", Min: "(a",
Max: "[b", Max: "[b",
}) })
Expect(zRangeByLex.Err()).NotTo(HaveOccurred()) Expect(zRangeByLex.Err()).NotTo(HaveOccurred())
Expect(zRangeByLex.Val()).To(Equal([]string{"b"})) Expect(zRangeByLex.Val()).To(Equal([]string{"b"}))
zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeByScore{ zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeBy{
Min: "(a", Min: "(a",
Max: "(b", Max: "(b",
}) })
@ -2272,28 +2272,28 @@ var _ = Describe("Commands", func() {
zAdd = client.ZAdd("zset", redis.Z{3, "three"}) zAdd = client.ZAdd("zset", redis.Z{3, "three"})
Expect(zAdd.Err()).NotTo(HaveOccurred()) Expect(zAdd.Err()).NotTo(HaveOccurred())
val, err := client.ZRangeByScoreWithScores("zset", redis.ZRangeByScore{ val, err := client.ZRangeByScoreWithScores("zset", redis.ZRangeBy{
Min: "-inf", Min: "-inf",
Max: "+inf", Max: "+inf",
}).Result() }).Result()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(val).To(Equal([]redis.Z{{1, "one"}, {2, "two"}, {3, "three"}})) 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", Min: "1",
Max: "2", Max: "2",
}).Result() }).Result()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(val).To(Equal([]redis.Z{{1, "one"}, {2, "two"}})) 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", Min: "(1",
Max: "2", Max: "2",
}).Result() }).Result()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(val).To(Equal([]redis.Z{{2, "two"}})) Expect(val).To(Equal([]redis.Z{{2, "two"}}))
val, err = client.ZRangeByScoreWithScores("zset", redis.ZRangeByScore{ val, err = client.ZRangeByScoreWithScores("zset", redis.ZRangeBy{
Min: "(1", Min: "(1",
Max: "(2", Max: "(2",
}).Result() }).Result()
@ -2420,17 +2420,17 @@ var _ = Describe("Commands", func() {
Expect(zadd.Err()).NotTo(HaveOccurred()) Expect(zadd.Err()).NotTo(HaveOccurred())
vals, err := client.ZRevRangeByScore( 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(err).NotTo(HaveOccurred())
Expect(vals).To(Equal([]string{"three", "two", "one"})) Expect(vals).To(Equal([]string{"three", "two", "one"}))
vals, err = client.ZRevRangeByScore( 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(err).NotTo(HaveOccurred())
Expect(vals).To(Equal([]string{"two"})) Expect(vals).To(Equal([]string{"two"}))
vals, err = client.ZRevRangeByScore( 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(err).NotTo(HaveOccurred())
Expect(vals).To(Equal([]string{})) Expect(vals).To(Equal([]string{}))
}) })
@ -2444,17 +2444,17 @@ var _ = Describe("Commands", func() {
Expect(zadd.Err()).NotTo(HaveOccurred()) Expect(zadd.Err()).NotTo(HaveOccurred())
vals, err := client.ZRevRangeByLex( vals, err := client.ZRevRangeByLex(
"zset", redis.ZRangeByScore{Max: "+", Min: "-"}).Result() "zset", redis.ZRangeBy{Max: "+", Min: "-"}).Result()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(vals).To(Equal([]string{"c", "b", "a"})) Expect(vals).To(Equal([]string{"c", "b", "a"}))
vals, err = client.ZRevRangeByLex( vals, err = client.ZRevRangeByLex(
"zset", redis.ZRangeByScore{Max: "[b", Min: "(a"}).Result() "zset", redis.ZRangeBy{Max: "[b", Min: "(a"}).Result()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(vals).To(Equal([]string{"b"})) Expect(vals).To(Equal([]string{"b"}))
vals, err = client.ZRevRangeByLex( vals, err = client.ZRevRangeByLex(
"zset", redis.ZRangeByScore{Max: "(b", Min: "(a"}).Result() "zset", redis.ZRangeBy{Max: "(b", Min: "(a"}).Result()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(vals).To(Equal([]string{})) Expect(vals).To(Equal([]string{}))
}) })
@ -2468,7 +2468,7 @@ var _ = Describe("Commands", func() {
Expect(zadd.Err()).NotTo(HaveOccurred()) Expect(zadd.Err()).NotTo(HaveOccurred())
vals, err := client.ZRevRangeByScoreWithScores( 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(err).NotTo(HaveOccurred())
Expect(vals).To(Equal([]redis.Z{{3, "three"}, {2, "two"}, {1, "one"}})) Expect(vals).To(Equal([]redis.Z{{3, "three"}, {2, "two"}, {1, "one"}}))
}) })
@ -2482,17 +2482,17 @@ var _ = Describe("Commands", func() {
Expect(zAdd.Err()).NotTo(HaveOccurred()) Expect(zAdd.Err()).NotTo(HaveOccurred())
val, err := client.ZRevRangeByScoreWithScores( 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(err).NotTo(HaveOccurred())
Expect(val).To(Equal([]redis.Z{{3, "three"}, {2, "two"}, {1, "one"}})) Expect(val).To(Equal([]redis.Z{{3, "three"}, {2, "two"}, {1, "one"}}))
val, err = client.ZRevRangeByScoreWithScores( 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(err).NotTo(HaveOccurred())
Expect(val).To(Equal([]redis.Z{{2, "two"}})) Expect(val).To(Equal([]redis.Z{{2, "two"}}))
val, err = client.ZRevRangeByScoreWithScores( 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(err).NotTo(HaveOccurred())
Expect(val).To(Equal([]redis.Z{})) Expect(val).To(Equal([]redis.Z{}))
}) })