forked from mirror/redis
This commit is contained in:
parent
2dc0bd1c0a
commit
026823f334
41
commands.go
41
commands.go
|
@ -10,6 +10,10 @@ func formatFloat(f float64) string {
|
|||
return strconv.FormatFloat(f, 'f', -1, 64)
|
||||
}
|
||||
|
||||
func formatInt(i int64) string {
|
||||
return strconv.FormatInt(i, 10)
|
||||
}
|
||||
|
||||
func readTimeout(sec int64) time.Duration {
|
||||
if sec == 0 {
|
||||
return 0
|
||||
|
@ -882,8 +886,7 @@ func (c *commandable) ZRangeWithScores(key string, start, stop int64) *ZSliceCmd
|
|||
}
|
||||
|
||||
type ZRangeByScore struct {
|
||||
Min, Max string
|
||||
|
||||
Min, Max string
|
||||
Offset, Count int64
|
||||
}
|
||||
|
||||
|
@ -954,32 +957,20 @@ func (c *commandable) ZRemRangeByScore(key, min, max string) *IntCmd {
|
|||
return cmd
|
||||
}
|
||||
|
||||
func (c *commandable) zRevRange(key, start, stop string, withScores bool) *StringSliceCmd {
|
||||
args := []string{"ZREVRANGE", key, start, stop}
|
||||
if withScores {
|
||||
args = append(args, "WITHSCORES")
|
||||
}
|
||||
cmd := NewStringSliceCmd(args...)
|
||||
func (c *commandable) ZRevRange(key string, start, stop int64) *StringSliceCmd {
|
||||
cmd := NewStringSliceCmd("ZREVRANGE", key, formatInt(start), formatInt(stop))
|
||||
c.Process(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c *commandable) ZRevRange(key, start, stop string) *StringSliceCmd {
|
||||
return c.zRevRange(key, start, stop, false)
|
||||
}
|
||||
|
||||
func (c *commandable) ZRevRangeWithScores(key, start, stop string) *ZSliceCmd {
|
||||
args := []string{"ZREVRANGE", key, start, stop, "WITHSCORES"}
|
||||
cmd := NewZSliceCmd(args...)
|
||||
func (c *commandable) ZRevRangeWithScores(key string, start, stop int64) *ZSliceCmd {
|
||||
cmd := NewZSliceCmd("ZREVRANGE", key, formatInt(start), formatInt(stop), "WITHSCORES")
|
||||
c.Process(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c *commandable) zRevRangeByScore(key string, opt ZRangeByScore, withScores bool) *StringSliceCmd {
|
||||
func (c *commandable) ZRevRangeByScore(key string, opt ZRangeByScore) *StringSliceCmd {
|
||||
args := []string{"ZREVRANGEBYSCORE", key, opt.Max, opt.Min}
|
||||
if withScores {
|
||||
args = append(args, "WITHSCORES")
|
||||
}
|
||||
if opt.Offset != 0 || opt.Count != 0 {
|
||||
args = append(
|
||||
args,
|
||||
|
@ -993,10 +984,6 @@ func (c *commandable) zRevRangeByScore(key string, opt ZRangeByScore, withScores
|
|||
return cmd
|
||||
}
|
||||
|
||||
func (c *commandable) ZRevRangeByScore(key string, opt ZRangeByScore) *StringSliceCmd {
|
||||
return c.zRevRangeByScore(key, opt, false)
|
||||
}
|
||||
|
||||
func (c *commandable) ZRevRangeByScoreWithScores(key string, opt ZRangeByScore) *ZSliceCmd {
|
||||
args := []string{"ZREVRANGEBYSCORE", key, opt.Max, opt.Min, "WITHSCORES"}
|
||||
if opt.Offset != 0 || opt.Count != 0 {
|
||||
|
@ -1024,12 +1011,8 @@ func (c *commandable) ZScore(key, member string) *FloatCmd {
|
|||
return cmd
|
||||
}
|
||||
|
||||
func (c *commandable) ZUnionStore(
|
||||
destination string,
|
||||
store ZStore,
|
||||
keys ...string,
|
||||
) *IntCmd {
|
||||
args := []string{"ZUNIONSTORE", destination, strconv.FormatInt(int64(len(keys)), 10)}
|
||||
func (c *commandable) ZUnionStore(dest string, store ZStore, keys ...string) *IntCmd {
|
||||
args := []string{"ZUNIONSTORE", dest, strconv.FormatInt(int64(len(keys)), 10)}
|
||||
args = append(args, keys...)
|
||||
if len(store.Weights) > 0 {
|
||||
args = append(args, "WEIGHTS")
|
||||
|
|
|
@ -2009,15 +2009,15 @@ var _ = Describe("Commands", func() {
|
|||
zAdd = client.ZAdd("zset", redis.Z{3, "three"})
|
||||
Expect(zAdd.Err()).NotTo(HaveOccurred())
|
||||
|
||||
zRevRange := client.ZRevRange("zset", "0", "-1")
|
||||
zRevRange := client.ZRevRange("zset", 0, -1)
|
||||
Expect(zRevRange.Err()).NotTo(HaveOccurred())
|
||||
Expect(zRevRange.Val()).To(Equal([]string{"three", "two", "one"}))
|
||||
|
||||
zRevRange = client.ZRevRange("zset", "2", "3")
|
||||
zRevRange = client.ZRevRange("zset", 2, 3)
|
||||
Expect(zRevRange.Err()).NotTo(HaveOccurred())
|
||||
Expect(zRevRange.Val()).To(Equal([]string{"one"}))
|
||||
|
||||
zRevRange = client.ZRevRange("zset", "-2", "-1")
|
||||
zRevRange = client.ZRevRange("zset", -2, -1)
|
||||
Expect(zRevRange.Err()).NotTo(HaveOccurred())
|
||||
Expect(zRevRange.Val()).To(Equal([]string{"two", "one"}))
|
||||
})
|
||||
|
@ -2030,15 +2030,15 @@ var _ = Describe("Commands", func() {
|
|||
zAdd = client.ZAdd("zset", redis.Z{3, "three"})
|
||||
Expect(zAdd.Err()).NotTo(HaveOccurred())
|
||||
|
||||
val, err := client.ZRevRangeWithScores("zset", "0", "-1").Result()
|
||||
val, err := client.ZRevRangeWithScores("zset", 0, -1).Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(val).To(Equal([]redis.Z{{3, "three"}, {2, "two"}, {1, "one"}}))
|
||||
|
||||
val, err = client.ZRevRangeWithScores("zset", "2", "3").Result()
|
||||
val, err = client.ZRevRangeWithScores("zset", 2, 3).Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(val).To(Equal([]redis.Z{{1, "one"}}))
|
||||
|
||||
val, err = client.ZRevRangeWithScores("zset", "-2", "-1").Result()
|
||||
val, err = client.ZRevRangeWithScores("zset", -2, -1).Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(val).To(Equal([]redis.Z{{2, "two"}, {1, "one"}}))
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue