mirror of
https://github.com/redis/go-redis.git
synced 2025-07-18 00:20:57 +03:00
Add support for new bitop operations
This commit is contained in:
@ -12,6 +12,10 @@ type BitMapCmdable interface {
|
|||||||
BitOpAnd(ctx context.Context, destKey string, keys ...string) *IntCmd
|
BitOpAnd(ctx context.Context, destKey string, keys ...string) *IntCmd
|
||||||
BitOpOr(ctx context.Context, destKey string, keys ...string) *IntCmd
|
BitOpOr(ctx context.Context, destKey string, keys ...string) *IntCmd
|
||||||
BitOpXor(ctx context.Context, destKey string, keys ...string) *IntCmd
|
BitOpXor(ctx context.Context, destKey string, keys ...string) *IntCmd
|
||||||
|
BitOpDiff(ctx context.Context, destKey string, keys ...string) *IntCmd
|
||||||
|
BitOpDiff1(ctx context.Context, destKey string, keys ...string) *IntCmd
|
||||||
|
BitOpAndOr(ctx context.Context, destKey string, keys ...string) *IntCmd
|
||||||
|
BitOpOne(ctx context.Context, destKey string, keys ...string) *IntCmd
|
||||||
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
|
||||||
@ -90,6 +94,22 @@ func (c cmdable) BitOpXor(ctx context.Context, destKey string, keys ...string) *
|
|||||||
return c.bitOp(ctx, "xor", destKey, keys...)
|
return c.bitOp(ctx, "xor", destKey, keys...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c cmdable) BitOpDiff(ctx context.Context, destKey string, keys ...string) *IntCmd {
|
||||||
|
return c.bitOp(ctx, "diff", destKey, keys...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c cmdable) BitOpDiff1(ctx context.Context, destKey string, keys ...string) *IntCmd {
|
||||||
|
return c.bitOp(ctx, "diff1", destKey, keys...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c cmdable) BitOpAndOr(ctx context.Context, destKey string, keys ...string) *IntCmd {
|
||||||
|
return c.bitOp(ctx, "andor", destKey, keys...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c cmdable) BitOpOne(ctx context.Context, destKey string, keys ...string) *IntCmd {
|
||||||
|
return c.bitOp(ctx, "one", destKey, keys...)
|
||||||
|
}
|
||||||
|
|
||||||
func (c cmdable) BitOpNot(ctx context.Context, destKey string, key string) *IntCmd {
|
func (c cmdable) BitOpNot(ctx context.Context, destKey string, key string) *IntCmd {
|
||||||
return c.bitOp(ctx, "not", destKey, key)
|
return c.bitOp(ctx, "not", destKey, key)
|
||||||
}
|
}
|
||||||
|
@ -1469,6 +1469,78 @@ var _ = Describe("Commands", func() {
|
|||||||
Expect(get.Val()).To(Equal("\xf0"))
|
Expect(get.Val()).To(Equal("\xf0"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("should BitOpDiff", Label("NonRedisEnterprise"), func() {
|
||||||
|
set := client.Set(ctx, "key1", "\xff", 0)
|
||||||
|
Expect(set.Err()).NotTo(HaveOccurred())
|
||||||
|
Expect(set.Val()).To(Equal("OK"))
|
||||||
|
|
||||||
|
set = client.Set(ctx, "key2", "\x0f", 0)
|
||||||
|
Expect(set.Err()).NotTo(HaveOccurred())
|
||||||
|
Expect(set.Val()).To(Equal("OK"))
|
||||||
|
|
||||||
|
bitOpDiff := client.BitOpDiff(ctx, "dest", "key1", "key2")
|
||||||
|
Expect(bitOpDiff.Err()).NotTo(HaveOccurred())
|
||||||
|
Expect(bitOpDiff.Val()).To(Equal(int64(1)))
|
||||||
|
|
||||||
|
get := client.Get(ctx, "dest")
|
||||||
|
Expect(get.Err()).NotTo(HaveOccurred())
|
||||||
|
Expect(get.Val()).To(Equal("\xf0"))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should BitOpDiff1", Label("NonRedisEnterprise"), func() {
|
||||||
|
set := client.Set(ctx, "key1", "\xff", 0)
|
||||||
|
Expect(set.Err()).NotTo(HaveOccurred())
|
||||||
|
Expect(set.Val()).To(Equal("OK"))
|
||||||
|
|
||||||
|
set = client.Set(ctx, "key2", "\x0f", 0)
|
||||||
|
Expect(set.Err()).NotTo(HaveOccurred())
|
||||||
|
Expect(set.Val()).To(Equal("OK"))
|
||||||
|
|
||||||
|
bitOpDiff1 := client.BitOpDiff1(ctx, "dest", "key1", "key2")
|
||||||
|
Expect(bitOpDiff1.Err()).NotTo(HaveOccurred())
|
||||||
|
Expect(bitOpDiff1.Val()).To(Equal(int64(1)))
|
||||||
|
|
||||||
|
get := client.Get(ctx, "dest")
|
||||||
|
Expect(get.Err()).NotTo(HaveOccurred())
|
||||||
|
Expect(get.Val()).To(Equal("\xf0"))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should BitOpAndOr", Label("NonRedisEnterprise"), func() {
|
||||||
|
set := client.Set(ctx, "key1", "\xff", 0)
|
||||||
|
Expect(set.Err()).NotTo(HaveOccurred())
|
||||||
|
Expect(set.Val()).To(Equal("OK"))
|
||||||
|
|
||||||
|
set = client.Set(ctx, "key2", "\x0f", 0)
|
||||||
|
Expect(set.Err()).NotTo(HaveOccurred())
|
||||||
|
Expect(set.Val()).To(Equal("OK"))
|
||||||
|
|
||||||
|
bitOpAndOr := client.BitOpAndOr(ctx, "dest", "key1", "key2")
|
||||||
|
Expect(bitOpAndOr.Err()).NotTo(HaveOccurred())
|
||||||
|
Expect(bitOpAndOr.Val()).To(Equal(int64(1)))
|
||||||
|
|
||||||
|
get := client.Get(ctx, "dest")
|
||||||
|
Expect(get.Err()).NotTo(HaveOccurred())
|
||||||
|
Expect(get.Val()).To(Equal("\xf0"))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should BitOpOne", Label("NonRedisEnterprise"), func() {
|
||||||
|
set := client.Set(ctx, "key1", "\xff", 0)
|
||||||
|
Expect(set.Err()).NotTo(HaveOccurred())
|
||||||
|
Expect(set.Val()).To(Equal("OK"))
|
||||||
|
|
||||||
|
set = client.Set(ctx, "key2", "\x0f", 0)
|
||||||
|
Expect(set.Err()).NotTo(HaveOccurred())
|
||||||
|
Expect(set.Val()).To(Equal("OK"))
|
||||||
|
|
||||||
|
bitOpOne := client.BitOpOne(ctx, "dest", "key1", "key2")
|
||||||
|
Expect(bitOpOne.Err()).NotTo(HaveOccurred())
|
||||||
|
Expect(bitOpOne.Val()).To(Equal(int64(1)))
|
||||||
|
|
||||||
|
get := client.Get(ctx, "dest")
|
||||||
|
Expect(get.Err()).NotTo(HaveOccurred())
|
||||||
|
Expect(get.Val()).To(Equal("\xf0"))
|
||||||
|
})
|
||||||
|
|
||||||
It("should BitOpNot", Label("NonRedisEnterprise"), func() {
|
It("should BitOpNot", Label("NonRedisEnterprise"), func() {
|
||||||
set := client.Set(ctx, "key1", "\x00", 0)
|
set := client.Set(ctx, "key1", "\x00", 0)
|
||||||
Expect(set.Err()).NotTo(HaveOccurred())
|
Expect(set.Err()).NotTo(HaveOccurred())
|
||||||
|
Reference in New Issue
Block a user