Merge pull request #479 from go-redis/fix/zremrangebylex

Add ZRemRangeByLex.
This commit is contained in:
Vladimir Mihailenco 2017-01-26 16:10:34 +02:00 committed by GitHub
commit a8345871dc
2 changed files with 34 additions and 0 deletions

View File

@ -170,6 +170,7 @@ type Cmdable interface {
ZRem(key string, members ...interface{}) *IntCmd ZRem(key string, members ...interface{}) *IntCmd
ZRemRangeByRank(key string, start, stop int64) *IntCmd ZRemRangeByRank(key string, start, stop int64) *IntCmd
ZRemRangeByScore(key, min, max string) *IntCmd ZRemRangeByScore(key, min, max string) *IntCmd
ZRemRangeByLex(key, min, max string) *IntCmd
ZRevRange(key string, start, stop int64) *StringSliceCmd ZRevRange(key string, start, stop int64) *StringSliceCmd
ZRevRangeWithScores(key string, start, stop int64) *ZSliceCmd ZRevRangeWithScores(key string, start, stop int64) *ZSliceCmd
ZRevRangeByScore(key string, opt ZRangeBy) *StringSliceCmd ZRevRangeByScore(key string, opt ZRangeBy) *StringSliceCmd
@ -1468,6 +1469,12 @@ func (c *cmdable) ZRemRangeByScore(key, min, max string) *IntCmd {
return cmd return cmd
} }
func (c *cmdable) ZRemRangeByLex(key, min, max string) *IntCmd {
cmd := NewIntCmd("zremrangebylex", key, min, max)
c.process(cmd)
return cmd
}
func (c *cmdable) ZRevRange(key string, start, stop int64) *StringSliceCmd { func (c *cmdable) ZRevRange(key string, start, stop int64) *StringSliceCmd {
cmd := NewStringSliceCmd("zrevrange", key, start, stop) cmd := NewStringSliceCmd("zrevrange", key, start, stop)
c.process(cmd) c.process(cmd)

View File

@ -2429,6 +2429,33 @@ var _ = Describe("Commands", func() {
Expect(val).To(Equal([]redis.Z{{2, "two"}, {3, "three"}})) Expect(val).To(Equal([]redis.Z{{2, "two"}, {3, "three"}}))
}) })
It("should ZRemRangeByLex", func() {
zz := []redis.Z{
{0, "aaaa"},
{0, "b"},
{0, "c"},
{0, "d"},
{0, "e"},
{0, "foo"},
{0, "zap"},
{0, "zip"},
{0, "ALPHA"},
{0, "alpha"},
}
for _, z := range zz {
err := client.ZAdd("zset", z).Err()
Expect(err).NotTo(HaveOccurred())
}
n, err := client.ZRemRangeByLex("zset", "[alpha", "[omega").Result()
Expect(err).NotTo(HaveOccurred())
Expect(n).To(Equal(int64(6)))
vals, err := client.ZRange("zset", 0, -1).Result()
Expect(err).NotTo(HaveOccurred())
Expect(vals).To(Equal([]string{"ALPHA", "aaaa", "zap", "zip"}))
})
It("should ZRevRange", func() { It("should ZRevRange", func() {
zAdd := client.ZAdd("zset", redis.Z{1, "one"}) zAdd := client.ZAdd("zset", redis.Z{1, "one"})
Expect(zAdd.Err()).NotTo(HaveOccurred()) Expect(zAdd.Err()).NotTo(HaveOccurred())