Add basic BITFIELD support

This commit is contained in:
Vladimir Mihailenco 2019-06-26 14:45:38 +03:00
parent 4a3dbb3251
commit bbe0a59db3
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 BitOpXor(destKey string, keys ...string) *IntCmd
BitOpNot(destKey string, key string) *IntCmd BitOpNot(destKey string, key string) *IntCmd
BitPos(key string, bit int64, pos ...int64) *IntCmd BitPos(key string, bit int64, pos ...int64) *IntCmd
BitField(key string, args ...interface{}) *IntSliceCmd
Decr(key string) *IntCmd Decr(key string) *IntCmd
DecrBy(key string, decrement int64) *IntCmd DecrBy(key string, decrement int64) *IntCmd
Get(key string) *StringCmd Get(key string) *StringCmd
@ -724,6 +725,16 @@ func (c cmdable) BitPos(key string, bit int64, pos ...int64) *IntCmd {
return cmd 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 { func (c cmdable) Decr(key string) *IntCmd {
cmd := NewIntCmd("decr", key) cmd := NewIntCmd("decr", key)
c(cmd) c(cmd)

View File

@ -968,6 +968,12 @@ var _ = Describe("Commands", func() {
Expect(pos).To(Equal(int64(-1))) 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() { It("should Decr", func() {
set := client.Set("key", "10", 0) set := client.Set("key", "10", 0)
Expect(set.Err()).NotTo(HaveOccurred()) Expect(set.Err()).NotTo(HaveOccurred())