Merge pull request #1068 from go-redis/fix/bit-field-basic

Add basic BITFIELD support
This commit is contained in:
Vladimir Mihailenco 2019-06-26 15:34:11 +03:00 committed by GitHub
commit a28bb0bd25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 439 additions and 481 deletions

File diff suppressed because it is too large Load Diff

View File

@ -98,6 +98,7 @@ type Cmdable interface {
BitOpXor(destKey string, keys ...string) *IntCmd
BitOpNot(destKey string, key string) *IntCmd
BitPos(key string, bit int64, pos ...int64) *IntCmd
BitField(key string, args ...interface{}) *IntSliceCmd
Decr(key string) *IntCmd
DecrBy(key string, decrement int64) *IntCmd
Get(key string) *StringCmd
@ -724,6 +725,16 @@ func (c cmdable) BitPos(key string, bit int64, pos ...int64) *IntCmd {
return cmd
}
func (c cmdable) BitField(key string, args ...interface{}) *IntSliceCmd {
a := make([]interface{}, 0, 2+len(args))
a = append(a, "bitfield")
a = append(a, key)
a = append(a, args...)
cmd := NewIntSliceCmd(a...)
c(cmd)
return cmd
}
func (c cmdable) Decr(key string) *IntCmd {
cmd := NewIntCmd("decr", key)
c(cmd)

View File

@ -968,6 +968,12 @@ var _ = Describe("Commands", func() {
Expect(pos).To(Equal(int64(-1)))
})
It("should BitField", func() {
nn, err := client.BitField("mykey", "INCRBY", "i5", 100, 1, "GET", "u4", 0).Result()
Expect(err).NotTo(HaveOccurred())
Expect(nn).To(Equal([]int64{1, 0}))
})
It("should Decr", func() {
set := client.Set("key", "10", 0)
Expect(set.Err()).NotTo(HaveOccurred())