Skip to content

Commit

Permalink
Make SetArgs available to Pipeliner
Browse files Browse the repository at this point in the history
SetArgs is amazing! It would be even more amazing to be able to use it
within a non-transactional Pipeline.
  • Loading branch information
lhchavez committed Mar 4, 2021
1 parent aaed549 commit 4ffcd9b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ type Cmdable interface {
MSet(ctx context.Context, values ...interface{}) *StatusCmd
MSetNX(ctx context.Context, values ...interface{}) *BoolCmd
Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *StatusCmd
SetArgs(ctx context.Context, key string, value interface{}, a SetArgs) *StatusCmd
SetEX(ctx context.Context, key string, value interface{}, expiration time.Duration) *StatusCmd
SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *BoolCmd
SetXX(ctx context.Context, key string, value interface{}, expiration time.Duration) *BoolCmd
Expand Down
17 changes: 17 additions & 0 deletions commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,23 @@ var _ = Describe("Commands", func() {
Expect(val).To(Equal("hello"))
})

It("should Pipelined SetArgs with Get and key exists", func() {
e := client.Set(ctx, "key", "hello", 0)
Expect(e.Err()).NotTo(HaveOccurred())

args := redis.SetArgs{
Get: true,
}

pipe := client.Pipeline()
setArgs := pipe.SetArgs(ctx, "key", "world", args)
_, err := pipe.Exec(ctx)
Expect(err).NotTo(HaveOccurred())

Expect(setArgs.Err()).NotTo(HaveOccurred())
Expect(setArgs.Val()).To(Equal("hello"))
})

It("should Set with expiration", func() {
err := client.Set(ctx, "key", "hello", 100*time.Millisecond).Err()
Expect(err).NotTo(HaveOccurred())
Expand Down

0 comments on commit 4ffcd9b

Please sign in to comment.