mirror of
https://github.com/redis/go-redis.git
synced 2025-06-12 14:21:52 +03:00
@ -1691,6 +1691,62 @@ var _ = Describe("Commands", func() {
|
||||
Expect(lRange.Val()).To(Equal([]string{"two", "three"}))
|
||||
})
|
||||
|
||||
It("should LPos", func() {
|
||||
rPush := client.RPush(ctx, "list", "a")
|
||||
Expect(rPush.Err()).NotTo(HaveOccurred())
|
||||
rPush = client.RPush(ctx, "list", "b")
|
||||
Expect(rPush.Err()).NotTo(HaveOccurred())
|
||||
rPush = client.RPush(ctx, "list", "c")
|
||||
Expect(rPush.Err()).NotTo(HaveOccurred())
|
||||
rPush = client.RPush(ctx, "list", "b")
|
||||
Expect(rPush.Err()).NotTo(HaveOccurred())
|
||||
|
||||
lPos := client.LPos(ctx, "list", "b", redis.LPosArgs{})
|
||||
Expect(lPos.Err()).NotTo(HaveOccurred())
|
||||
Expect(lPos.Val()).To(Equal(int64(1)))
|
||||
|
||||
lPos = client.LPos(ctx, "list", "b", redis.LPosArgs{Rank: 2})
|
||||
Expect(lPos.Err()).NotTo(HaveOccurred())
|
||||
Expect(lPos.Val()).To(Equal(int64(3)))
|
||||
|
||||
lPos = client.LPos(ctx, "list", "b", redis.LPosArgs{Rank: -2})
|
||||
Expect(lPos.Err()).NotTo(HaveOccurred())
|
||||
Expect(lPos.Val()).To(Equal(int64(1)))
|
||||
|
||||
lPos = client.LPos(ctx, "list", "b", redis.LPosArgs{Rank: 2, MaxLen: 1})
|
||||
Expect(lPos.Err()).To(Equal(redis.Nil))
|
||||
|
||||
lPos = client.LPos(ctx, "list", "z", redis.LPosArgs{})
|
||||
Expect(lPos.Err()).To(Equal(redis.Nil))
|
||||
})
|
||||
|
||||
It("should LPosCount", func() {
|
||||
rPush := client.RPush(ctx, "list", "a")
|
||||
Expect(rPush.Err()).NotTo(HaveOccurred())
|
||||
rPush = client.RPush(ctx, "list", "b")
|
||||
Expect(rPush.Err()).NotTo(HaveOccurred())
|
||||
rPush = client.RPush(ctx, "list", "c")
|
||||
Expect(rPush.Err()).NotTo(HaveOccurred())
|
||||
rPush = client.RPush(ctx, "list", "b")
|
||||
Expect(rPush.Err()).NotTo(HaveOccurred())
|
||||
|
||||
lPos := client.LPosCount(ctx, "list", "b", 2, redis.LPosArgs{})
|
||||
Expect(lPos.Err()).NotTo(HaveOccurred())
|
||||
Expect(lPos.Val()).To(Equal([]int64{1, 3}))
|
||||
|
||||
lPos = client.LPosCount(ctx, "list", "b", 2, redis.LPosArgs{Rank: 2})
|
||||
Expect(lPos.Err()).NotTo(HaveOccurred())
|
||||
Expect(lPos.Val()).To(Equal([]int64{3}))
|
||||
|
||||
lPos = client.LPosCount(ctx, "list", "b", 1, redis.LPosArgs{Rank: 1, MaxLen: 1})
|
||||
Expect(lPos.Err()).NotTo(HaveOccurred())
|
||||
Expect(lPos.Val()).To(Equal([]int64{}))
|
||||
|
||||
lPos = client.LPosCount(ctx, "list", "b", 1, redis.LPosArgs{Rank: 1, MaxLen: 0})
|
||||
Expect(lPos.Err()).NotTo(HaveOccurred())
|
||||
Expect(lPos.Val()).To(Equal([]int64{1}))
|
||||
})
|
||||
|
||||
It("should LPush", func() {
|
||||
lPush := client.LPush(ctx, "list", "World")
|
||||
Expect(lPush.Err()).NotTo(HaveOccurred())
|
||||
|
Reference in New Issue
Block a user