Skip to content

Commit

Permalink
Merge pull request #21 from whiteforestzx/add-set-args-method
Browse files Browse the repository at this point in the history
Add SetArgs method
  • Loading branch information
nvorobev authored Dec 6, 2023
2 parents 13c5318 + b70db7b commit 6d4c712
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,14 @@ func (p *Pool) SetRange(ctx context.Context, key string, offset int64, value str
return conn.SetRange(ctx, key, offset, value)
}

func (p *Pool) SetArgs(ctx context.Context, key string, value interface{}, a redis.SetArgs) *redis.StatusCmd {
conn, err := p.connFactory.getMasterConn(key)
if err != nil {
return newErrorStatusCmd(err)
}
return conn.SetArgs(ctx, key, value, a)
}

func (p *Pool) StrLen(ctx context.Context, key string) *redis.IntCmd {
conn, err := p.connFactory.getSlaveConn(key)
if err != nil {
Expand Down
11 changes: 10 additions & 1 deletion pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,16 @@ var _ = Describe("Pool", func() {
}
})

It("setargs", func() {
key := "setargs_key"
for _, pool := range pools {
Expect(pool.SetArgs(ctx, key, "bar", redis.SetArgs{Mode: "XX"}).Val()).To(Equal(""))
Expect(pool.SetArgs(ctx, key, "bar", redis.SetArgs{}).Val()).To(Equal("OK"))
Expect(pool.SetArgs(ctx, key, "bar", redis.SetArgs{Mode: "NX"}).Val()).To(Equal(""))
_, _ = pool.Del(ctx, key)
}
})

It("setrange", func() {
key := "setrange_key"
for _, pool := range pools {
Expand Down Expand Up @@ -1191,7 +1201,6 @@ var _ = Describe("Pool", func() {
}
})


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

0 comments on commit 6d4c712

Please sign in to comment.