forked from mirror/redis
parent
86155dcfb7
commit
f3bba01df2
42
commands.go
42
commands.go
|
@ -206,6 +206,8 @@ type Cmdable interface {
|
||||||
ZLexCount(key, min, max string) *IntCmd
|
ZLexCount(key, min, max string) *IntCmd
|
||||||
ZIncrBy(key string, increment float64, member string) *FloatCmd
|
ZIncrBy(key string, increment float64, member string) *FloatCmd
|
||||||
ZInterStore(destination string, store ZStore, keys ...string) *IntCmd
|
ZInterStore(destination string, store ZStore, keys ...string) *IntCmd
|
||||||
|
ZPopMax(key string, count ...int64) *ZSliceCmd
|
||||||
|
ZPopMin(key string, count ...int64) *ZSliceCmd
|
||||||
ZRange(key string, start, stop int64) *StringSliceCmd
|
ZRange(key string, start, stop int64) *StringSliceCmd
|
||||||
ZRangeWithScores(key string, start, stop int64) *ZSliceCmd
|
ZRangeWithScores(key string, start, stop int64) *ZSliceCmd
|
||||||
ZRangeByScore(key string, opt ZRangeBy) *StringSliceCmd
|
ZRangeByScore(key string, opt ZRangeBy) *StringSliceCmd
|
||||||
|
@ -1694,6 +1696,46 @@ func (c *cmdable) ZInterStore(destination string, store ZStore, keys ...string)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *cmdable) ZPopMax(key string, count ...int64) *ZSliceCmd {
|
||||||
|
args := []interface{}{
|
||||||
|
"zpopmax",
|
||||||
|
key,
|
||||||
|
}
|
||||||
|
|
||||||
|
switch len(count) {
|
||||||
|
case 0:
|
||||||
|
break
|
||||||
|
case 1:
|
||||||
|
args = append(args, count[0])
|
||||||
|
default:
|
||||||
|
panic("too many arguments")
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := NewZSliceCmd(args...)
|
||||||
|
c.process(cmd)
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *cmdable) ZPopMin(key string, count ...int64) *ZSliceCmd {
|
||||||
|
args := []interface{}{
|
||||||
|
"zpopmin",
|
||||||
|
key,
|
||||||
|
}
|
||||||
|
|
||||||
|
switch len(count) {
|
||||||
|
case 0:
|
||||||
|
break
|
||||||
|
case 1:
|
||||||
|
args = append(args, count[0])
|
||||||
|
default:
|
||||||
|
panic("too many arguments")
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := NewZSliceCmd(args...)
|
||||||
|
c.process(cmd)
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
func (c *cmdable) zRange(key string, start, stop int64, withScores bool) *StringSliceCmd {
|
func (c *cmdable) zRange(key string, start, stop int64, withScores bool) *StringSliceCmd {
|
||||||
args := []interface{}{
|
args := []interface{}{
|
||||||
"zrange",
|
"zrange",
|
||||||
|
|
129
commands_test.go
129
commands_test.go
|
@ -2518,6 +2518,135 @@ var _ = Describe("Commands", func() {
|
||||||
}}))
|
}}))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("should ZPopMax", func() {
|
||||||
|
err := client.ZAdd("zset", redis.Z{
|
||||||
|
Score: 1,
|
||||||
|
Member: "one",
|
||||||
|
}).Err()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
err = client.ZAdd("zset", redis.Z{
|
||||||
|
Score: 2,
|
||||||
|
Member: "two",
|
||||||
|
}).Err()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
err = client.ZAdd("zset", redis.Z{
|
||||||
|
Score: 3,
|
||||||
|
Member: "three",
|
||||||
|
}).Err()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
members, err := client.ZPopMax("zset").Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(members).To(Equal([]redis.Z{{
|
||||||
|
Score: 3,
|
||||||
|
Member: "three",
|
||||||
|
}}))
|
||||||
|
|
||||||
|
// adding back 3
|
||||||
|
err = client.ZAdd("zset", redis.Z{
|
||||||
|
Score: 3,
|
||||||
|
Member: "three",
|
||||||
|
}).Err()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
members, err = client.ZPopMax("zset", 2).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(members).To(Equal([]redis.Z{{
|
||||||
|
Score: 3,
|
||||||
|
Member: "three",
|
||||||
|
}, {
|
||||||
|
Score: 2,
|
||||||
|
Member: "two",
|
||||||
|
}}))
|
||||||
|
|
||||||
|
// adding back 2 & 3
|
||||||
|
err = client.ZAdd("zset", redis.Z{
|
||||||
|
Score: 3,
|
||||||
|
Member: "three",
|
||||||
|
}).Err()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
err = client.ZAdd("zset", redis.Z{
|
||||||
|
Score: 2,
|
||||||
|
Member: "two",
|
||||||
|
}).Err()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
members, err = client.ZPopMax("zset", 10).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(members).To(Equal([]redis.Z{{
|
||||||
|
Score: 3,
|
||||||
|
Member: "three",
|
||||||
|
}, {
|
||||||
|
Score: 2,
|
||||||
|
Member: "two",
|
||||||
|
}, {
|
||||||
|
Score: 1,
|
||||||
|
Member: "one",
|
||||||
|
}}))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should ZPopMin", func() {
|
||||||
|
err := client.ZAdd("zset", redis.Z{
|
||||||
|
Score: 1,
|
||||||
|
Member: "one",
|
||||||
|
}).Err()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
err = client.ZAdd("zset", redis.Z{
|
||||||
|
Score: 2,
|
||||||
|
Member: "two",
|
||||||
|
}).Err()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
err = client.ZAdd("zset", redis.Z{
|
||||||
|
Score: 3,
|
||||||
|
Member: "three",
|
||||||
|
}).Err()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
members, err := client.ZPopMin("zset").Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(members).To(Equal([]redis.Z{{
|
||||||
|
Score: 1,
|
||||||
|
Member: "one",
|
||||||
|
}}))
|
||||||
|
|
||||||
|
// adding back 1
|
||||||
|
err = client.ZAdd("zset", redis.Z{
|
||||||
|
Score: 1,
|
||||||
|
Member: "one",
|
||||||
|
}).Err()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
members, err = client.ZPopMin("zset", 2).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(members).To(Equal([]redis.Z{{
|
||||||
|
Score: 1,
|
||||||
|
Member: "one",
|
||||||
|
}, {
|
||||||
|
Score: 2,
|
||||||
|
Member: "two",
|
||||||
|
}}))
|
||||||
|
|
||||||
|
// adding back 1 & 2
|
||||||
|
err = client.ZAdd("zset", redis.Z{
|
||||||
|
Score: 1,
|
||||||
|
Member: "one",
|
||||||
|
}).Err()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
err = client.ZAdd("zset", redis.Z{
|
||||||
|
Score: 2,
|
||||||
|
Member: "two",
|
||||||
|
}).Err()
|
||||||
|
members, err = client.ZPopMin("zset", 10).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(members).To(Equal([]redis.Z{{
|
||||||
|
Score: 1,
|
||||||
|
Member: "one",
|
||||||
|
}, {
|
||||||
|
Score: 2,
|
||||||
|
Member: "two",
|
||||||
|
}, {
|
||||||
|
Score: 3,
|
||||||
|
Member: "three",
|
||||||
|
}}))
|
||||||
|
})
|
||||||
|
|
||||||
It("should ZRange", func() {
|
It("should ZRange", func() {
|
||||||
err := client.ZAdd("zset", redis.Z{Score: 1, Member: "one"}).Err()
|
err := client.ZAdd("zset", redis.Z{Score: 1, Member: "one"}).Err()
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
Loading…
Reference in New Issue