Skip to content

Commit 3caf52b

Browse files
authored
Add the count option to the rpop command(fix redis#1813) (redis#1815)
1 parent c1b63a6 commit 3caf52b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

commands.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ type Cmdable interface {
190190
LSet(ctx context.Context, key string, index int64, value interface{}) *StatusCmd
191191
LTrim(ctx context.Context, key string, start, stop int64) *StatusCmd
192192
RPop(ctx context.Context, key string) *StringCmd
193+
RPopCount(ctx context.Context, key string, count int) *StringSliceCmd
193194
RPopLPush(ctx context.Context, source, destination string) *StringCmd
194195
RPush(ctx context.Context, key string, values ...interface{}) *IntCmd
195196
RPushX(ctx context.Context, key string, values ...interface{}) *IntCmd
@@ -1451,6 +1452,12 @@ func (c cmdable) RPop(ctx context.Context, key string) *StringCmd {
14511452
return cmd
14521453
}
14531454

1455+
func (c cmdable) RPopCount(ctx context.Context, key string, count int) *StringSliceCmd {
1456+
cmd := NewStringSliceCmd(ctx, "rpop", key, count)
1457+
_ = c(ctx, cmd)
1458+
return cmd
1459+
}
1460+
14541461
func (c cmdable) RPopLPush(ctx context.Context, source, destination string) *StringCmd {
14551462
cmd := NewStringCmd(ctx, "rpoplpush", source, destination)
14561463
_ = c(ctx, cmd)

commands_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,6 +2268,20 @@ var _ = Describe("Commands", func() {
22682268
Expect(lRange.Val()).To(Equal([]string{"one", "two"}))
22692269
})
22702270

2271+
It("should RPopCount", func() {
2272+
rPush := client.RPush(ctx, "list", "one", "two", "three", "four")
2273+
Expect(rPush.Err()).NotTo(HaveOccurred())
2274+
Expect(rPush.Val()).To(Equal(int64(4)))
2275+
2276+
rPopCount := client.RPopCount(ctx, "list", 2)
2277+
Expect(rPopCount.Err()).NotTo(HaveOccurred())
2278+
Expect(rPopCount.Val()).To(Equal([]string{"four", "three"}))
2279+
2280+
lRange := client.LRange(ctx, "list", 0, -1)
2281+
Expect(lRange.Err()).NotTo(HaveOccurred())
2282+
Expect(lRange.Val()).To(Equal([]string{"one", "two"}))
2283+
})
2284+
22712285
It("should RPopLPush", func() {
22722286
rPush := client.RPush(ctx, "list", "one")
22732287
Expect(rPush.Err()).NotTo(HaveOccurred())

0 commit comments

Comments
 (0)