Skip to content

Commit

Permalink
Merge pull request #20 from almorgv/master
Browse files Browse the repository at this point in the history
Add ZAddGT and ZAddLT commands
  • Loading branch information
nvorobev authored Dec 4, 2023
2 parents bb57f1d + 6173932 commit 13c5318
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,22 @@ func (p *Pool) ZAddXX(ctx context.Context, key string, members ...redis.Z) *redi
return conn.ZAddXX(ctx, key, members...)
}

func (p *Pool) ZAddGT(ctx context.Context, key string, members ...redis.Z) *redis.IntCmd {
conn, err := p.connFactory.getMasterConn(key)
if err != nil {
return newErrorIntCmd(err)
}
return conn.ZAddGT(ctx, key, members...)
}

func (p *Pool) ZAddLT(ctx context.Context, key string, members ...redis.Z) *redis.IntCmd {
conn, err := p.connFactory.getMasterConn(key)
if err != nil {
return newErrorIntCmd(err)
}
return conn.ZAddLT(ctx, key, members...)
}

func (p *Pool) ZAddCh(ctx context.Context, key string, members ...*redis.Z) *redis.IntCmd {
conn, err := p.connFactory.getMasterConn(key)
if err != nil {
Expand Down
61 changes: 61 additions & 0 deletions pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,67 @@ var _ = Describe("Pool", func() {
}
})


It("ZAddGT", func() {
for _, pool := range pools {
_, err := pool.ZAddGT(ctx, "key", redis.Z{
Score: 2,
Member: "one",
}).Result()
Expect(err).NotTo(HaveOccurred())

_, err = pool.ZAddGT(ctx, "key", redis.Z{
Score: 1,
Member: "one",
}).Result()
Expect(err).NotTo(HaveOccurred())

score, err := pool.ZScore(ctx, "key", "one").Result()
Expect(err).NotTo(HaveOccurred())
Expect(score).To(Equal(float64(2)))

_, err = pool.ZAddGT(ctx, "key", redis.Z{
Score: 3,
Member: "one",
}).Result()
Expect(err).NotTo(HaveOccurred())

score, err = pool.ZScore(ctx, "key", "one").Result()
Expect(err).NotTo(HaveOccurred())
Expect(score).To(Equal(float64(3)))
}
})

It("ZAddLT", func() {
for _, pool := range pools {
_, err := pool.ZAddLT(ctx, "key", redis.Z{
Score: 2,
Member: "one",
}).Result()
Expect(err).NotTo(HaveOccurred())

_, err = pool.ZAddLT(ctx, "key", redis.Z{
Score: 3,
Member: "one",
}).Result()
Expect(err).NotTo(HaveOccurred())

score, err := pool.ZScore(ctx, "key", "one").Result()
Expect(err).NotTo(HaveOccurred())
Expect(score).To(Equal(float64(2)))

_, err = pool.ZAddLT(ctx, "key", redis.Z{
Score: 1,
Member: "one",
}).Result()
Expect(err).NotTo(HaveOccurred())

score, err = pool.ZScore(ctx, "key", "one").Result()
Expect(err).NotTo(HaveOccurred())
Expect(score).To(Equal(float64(1)))
}
})

It("ZAddCh", func() {
for _, pool := range pools {
_, err := pool.ZAdd(ctx, "key", redis.Z{
Expand Down

0 comments on commit 13c5318

Please sign in to comment.