forked from mirror/redis
Reverted change to struct ZRangeByScore, implemented ZRevRangeByLex.
This commit is contained in:
parent
15c887f700
commit
5498ba400d
27
commands.go
27
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(
|
||||
|
|
|
@ -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{}))
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue