forked from mirror/redis
Refactored zRangeByScore into zRangeBy.
This commit is contained in:
parent
2de07f2493
commit
2abf5c5f14
26
commands.go
26
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(
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue