mirror of https://github.com/go-redis/redis.git
upgrade bitfield cmd to `add multiple values` (#2648)
Co-authored-by: wangzheng1 <wangzheng1@yidian-inc.com> Co-authored-by: ofekshenawa <104765379+ofekshenawa@users.noreply.github.com>
This commit is contained in:
parent
71dd81cded
commit
1a7d2f4ad4
18
commands.go
18
commands.go
|
@ -238,7 +238,7 @@ type Cmdable interface {
|
||||||
BitOpNot(ctx context.Context, destKey string, key string) *IntCmd
|
BitOpNot(ctx context.Context, destKey string, key string) *IntCmd
|
||||||
BitPos(ctx context.Context, key string, bit int64, pos ...int64) *IntCmd
|
BitPos(ctx context.Context, key string, bit int64, pos ...int64) *IntCmd
|
||||||
BitPosSpan(ctx context.Context, key string, bit int8, start, end int64, span string) *IntCmd
|
BitPosSpan(ctx context.Context, key string, bit int8, start, end int64, span string) *IntCmd
|
||||||
BitField(ctx context.Context, key string, args ...interface{}) *IntSliceCmd
|
BitField(ctx context.Context, key string, values ...interface{}) *IntSliceCmd
|
||||||
|
|
||||||
Scan(ctx context.Context, cursor uint64, match string, count int64) *ScanCmd
|
Scan(ctx context.Context, cursor uint64, match string, count int64) *ScanCmd
|
||||||
ScanType(ctx context.Context, cursor uint64, match string, count int64, keyType string) *ScanCmd
|
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
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c cmdable) BitField(ctx context.Context, key string, args ...interface{}) *IntSliceCmd {
|
// BitField accepts multiple values:
|
||||||
a := make([]interface{}, 0, 2+len(args))
|
// - BitField("set", "i1", "offset1", "value1","cmd2", "type2", "offset2", "value2")
|
||||||
a = append(a, "bitfield")
|
// - BitField([]string{"cmd1", "type1", "offset1", "value1","cmd2", "type2", "offset2", "value2"})
|
||||||
a = append(a, key)
|
// - BitField([]interface{}{"cmd1", "type1", "offset1", "value1","cmd2", "type2", "offset2", "value2"})
|
||||||
a = append(a, args...)
|
func (c cmdable) BitField(ctx context.Context, key string, values ...interface{}) *IntSliceCmd {
|
||||||
cmd := NewIntSliceCmd(ctx, a...)
|
args := make([]interface{}, 2, 2+len(values))
|
||||||
|
args[0] = "bitfield"
|
||||||
|
args[1] = key
|
||||||
|
args = appendArgs(args, values)
|
||||||
|
cmd := NewIntSliceCmd(ctx, args...)
|
||||||
_ = c(ctx, cmd)
|
_ = c(ctx, cmd)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
|
@ -1253,6 +1253,10 @@ var _ = Describe("Commands", func() {
|
||||||
nn, err := client.BitField(ctx, "mykey", "INCRBY", "i5", 100, 1, "GET", "u4", 0).Result()
|
nn, err := client.BitField(ctx, "mykey", "INCRBY", "i5", 100, 1, "GET", "u4", 0).Result()
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(nn).To(Equal([]int64{1, 0}))
|
Expect(nn).To(Equal([]int64{1, 0}))
|
||||||
|
|
||||||
|
nn, err = client.BitField(ctx, "mykey", "set", "i1", 1, 1, "GET", "u4", 0).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(nn).To(Equal([]int64{0, 4}))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("should Decr", func() {
|
It("should Decr", func() {
|
||||||
|
|
Loading…
Reference in New Issue