Skip to content

Commit 1a7d2f4

Browse files
wzlovewangzheng1ofekshenawa
authored
upgrade bitfield cmd to add multiple values (#2648)
Co-authored-by: wangzheng1 <[email protected]> Co-authored-by: ofekshenawa <[email protected]>
1 parent 71dd81c commit 1a7d2f4

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

commands.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ type Cmdable interface {
238238
BitOpNot(ctx context.Context, destKey string, key string) *IntCmd
239239
BitPos(ctx context.Context, key string, bit int64, pos ...int64) *IntCmd
240240
BitPosSpan(ctx context.Context, key string, bit int8, start, end int64, span string) *IntCmd
241-
BitField(ctx context.Context, key string, args ...interface{}) *IntSliceCmd
241+
BitField(ctx context.Context, key string, values ...interface{}) *IntSliceCmd
242242

243243
Scan(ctx context.Context, cursor uint64, match string, count int64) *ScanCmd
244244
ScanType(ctx context.Context, cursor uint64, match string, count int64, keyType string) *ScanCmd
@@ -1369,12 +1369,16 @@ func (c cmdable) BitPosSpan(ctx context.Context, key string, bit int8, start, en
13691369
return cmd
13701370
}
13711371

1372-
func (c cmdable) BitField(ctx context.Context, key string, args ...interface{}) *IntSliceCmd {
1373-
a := make([]interface{}, 0, 2+len(args))
1374-
a = append(a, "bitfield")
1375-
a = append(a, key)
1376-
a = append(a, args...)
1377-
cmd := NewIntSliceCmd(ctx, a...)
1372+
// BitField accepts multiple values:
1373+
// - BitField("set", "i1", "offset1", "value1","cmd2", "type2", "offset2", "value2")
1374+
// - BitField([]string{"cmd1", "type1", "offset1", "value1","cmd2", "type2", "offset2", "value2"})
1375+
// - BitField([]interface{}{"cmd1", "type1", "offset1", "value1","cmd2", "type2", "offset2", "value2"})
1376+
func (c cmdable) BitField(ctx context.Context, key string, values ...interface{}) *IntSliceCmd {
1377+
args := make([]interface{}, 2, 2+len(values))
1378+
args[0] = "bitfield"
1379+
args[1] = key
1380+
args = appendArgs(args, values)
1381+
cmd := NewIntSliceCmd(ctx, args...)
13781382
_ = c(ctx, cmd)
13791383
return cmd
13801384
}

commands_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,10 @@ var _ = Describe("Commands", func() {
12531253
nn, err := client.BitField(ctx, "mykey", "INCRBY", "i5", 100, 1, "GET", "u4", 0).Result()
12541254
Expect(err).NotTo(HaveOccurred())
12551255
Expect(nn).To(Equal([]int64{1, 0}))
1256+
1257+
nn, err = client.BitField(ctx, "mykey", "set", "i1", 1, 1, "GET", "u4", 0).Result()
1258+
Expect(err).NotTo(HaveOccurred())
1259+
Expect(nn).To(Equal([]int64{0, 4}))
12561260
})
12571261

12581262
It("should Decr", func() {

0 commit comments

Comments
 (0)