Skip to content

Commit 8f0fbd2

Browse files
authored
fix #1754 (#1756)
1 parent 31495ac commit 8f0fbd2

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

commands.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ type Cmdable interface {
179179
LInsertAfter(ctx context.Context, key string, pivot, value interface{}) *IntCmd
180180
LLen(ctx context.Context, key string) *IntCmd
181181
LPop(ctx context.Context, key string) *StringCmd
182+
LPopCount(ctx context.Context, key string, count int) *StringSliceCmd
182183
LPos(ctx context.Context, key string, value string, args LPosArgs) *IntCmd
183184
LPosCount(ctx context.Context, key string, value string, count int64, args LPosArgs) *IntSliceCmd
184185
LPush(ctx context.Context, key string, values ...interface{}) *IntCmd
@@ -1314,6 +1315,12 @@ func (c cmdable) LPop(ctx context.Context, key string) *StringCmd {
13141315
return cmd
13151316
}
13161317

1318+
func (c cmdable) LPopCount(ctx context.Context, key string, count int) *StringSliceCmd {
1319+
cmd := NewStringSliceCmd(ctx, "lpop", key, count)
1320+
_ = c(ctx, cmd)
1321+
return cmd
1322+
}
1323+
13171324
type LPosArgs struct {
13181325
Rank, MaxLen int64
13191326
}

commands_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,6 +2050,25 @@ var _ = Describe("Commands", func() {
20502050
Expect(lRange.Val()).To(Equal([]string{"two", "three"}))
20512051
})
20522052

2053+
It("should LPopCount", func() {
2054+
rPush := client.RPush(ctx, "list", "one")
2055+
Expect(rPush.Err()).NotTo(HaveOccurred())
2056+
rPush = client.RPush(ctx, "list", "two")
2057+
Expect(rPush.Err()).NotTo(HaveOccurred())
2058+
rPush = client.RPush(ctx, "list", "three")
2059+
Expect(rPush.Err()).NotTo(HaveOccurred())
2060+
rPush = client.RPush(ctx, "list", "four")
2061+
Expect(rPush.Err()).NotTo(HaveOccurred())
2062+
2063+
lPopCount := client.LPopCount(ctx, "list", 2)
2064+
Expect(lPopCount.Err()).NotTo(HaveOccurred())
2065+
Expect(lPopCount.Val()).To(Equal([]string{"one", "two"}))
2066+
2067+
lRange := client.LRange(ctx, "list", 0, -1)
2068+
Expect(lRange.Err()).NotTo(HaveOccurred())
2069+
Expect(lRange.Val()).To(Equal([]string{"three", "four"}))
2070+
})
2071+
20532072
It("should LPos", func() {
20542073
rPush := client.RPush(ctx, "list", "a")
20552074
Expect(rPush.Err()).NotTo(HaveOccurred())

0 commit comments

Comments
 (0)