Add the count option to the rpop command(fix #1813) (#1815)

This commit is contained in:
monkey92t 2021-07-11 18:27:48 +08:00 committed by GitHub
parent c1b63a6703
commit 3caf52bceb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -190,6 +190,7 @@ type Cmdable interface {
LSet(ctx context.Context, key string, index int64, value interface{}) *StatusCmd LSet(ctx context.Context, key string, index int64, value interface{}) *StatusCmd
LTrim(ctx context.Context, key string, start, stop int64) *StatusCmd LTrim(ctx context.Context, key string, start, stop int64) *StatusCmd
RPop(ctx context.Context, key string) *StringCmd RPop(ctx context.Context, key string) *StringCmd
RPopCount(ctx context.Context, key string, count int) *StringSliceCmd
RPopLPush(ctx context.Context, source, destination string) *StringCmd RPopLPush(ctx context.Context, source, destination string) *StringCmd
RPush(ctx context.Context, key string, values ...interface{}) *IntCmd RPush(ctx context.Context, key string, values ...interface{}) *IntCmd
RPushX(ctx context.Context, key string, values ...interface{}) *IntCmd RPushX(ctx context.Context, key string, values ...interface{}) *IntCmd
@ -1451,6 +1452,12 @@ func (c cmdable) RPop(ctx context.Context, key string) *StringCmd {
return cmd return cmd
} }
func (c cmdable) RPopCount(ctx context.Context, key string, count int) *StringSliceCmd {
cmd := NewStringSliceCmd(ctx, "rpop", key, count)
_ = c(ctx, cmd)
return cmd
}
func (c cmdable) RPopLPush(ctx context.Context, source, destination string) *StringCmd { func (c cmdable) RPopLPush(ctx context.Context, source, destination string) *StringCmd {
cmd := NewStringCmd(ctx, "rpoplpush", source, destination) cmd := NewStringCmd(ctx, "rpoplpush", source, destination)
_ = c(ctx, cmd) _ = c(ctx, cmd)

View File

@ -2268,6 +2268,20 @@ var _ = Describe("Commands", func() {
Expect(lRange.Val()).To(Equal([]string{"one", "two"})) Expect(lRange.Val()).To(Equal([]string{"one", "two"}))
}) })
It("should RPopCount", func() {
rPush := client.RPush(ctx, "list", "one", "two", "three", "four")
Expect(rPush.Err()).NotTo(HaveOccurred())
Expect(rPush.Val()).To(Equal(int64(4)))
rPopCount := client.RPopCount(ctx, "list", 2)
Expect(rPopCount.Err()).NotTo(HaveOccurred())
Expect(rPopCount.Val()).To(Equal([]string{"four", "three"}))
lRange := client.LRange(ctx, "list", 0, -1)
Expect(lRange.Err()).NotTo(HaveOccurred())
Expect(lRange.Val()).To(Equal([]string{"one", "two"}))
})
It("should RPopLPush", func() { It("should RPopLPush", func() {
rPush := client.RPush(ctx, "list", "one") rPush := client.RPush(ctx, "list", "one")
Expect(rPush.Err()).NotTo(HaveOccurred()) Expect(rPush.Err()).NotTo(HaveOccurred())