mirror of
https://github.com/redis/go-redis.git
synced 2025-07-19 11:43:14 +03:00
feat(bitop): add support for the new bitop operations (#3409)
* Add support for new bitop operations * chore(ci): Add 8.2 pre build for CI * feat(info): add new client info keys * fixed tests * added godocs for bitop commands --------- Co-authored-by: Nedyalko Dyakov <nedyalko.dyakov@gmail.com> Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com>
This commit is contained in:
@ -1469,6 +1469,82 @@ var _ = Describe("Commands", func() {
|
||||
Expect(get.Val()).To(Equal("\xf0"))
|
||||
})
|
||||
|
||||
It("should BitOpDiff", Label("NonRedisEnterprise"), func() {
|
||||
SkipBeforeRedisVersion(8.2, "BITOP DIFF is available since Redis 8.2")
|
||||
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() {
|
||||
SkipBeforeRedisVersion(8.2, "BITOP DIFF is available since Redis 8.2")
|
||||
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("\x00"))
|
||||
})
|
||||
|
||||
It("should BitOpAndOr", Label("NonRedisEnterprise"), func() {
|
||||
SkipBeforeRedisVersion(8.2, "BITOP ANDOR is available since Redis 8.2")
|
||||
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("\x0f"))
|
||||
})
|
||||
|
||||
It("should BitOpOne", Label("NonRedisEnterprise"), func() {
|
||||
SkipBeforeRedisVersion(8.2, "BITOP ONE is available since Redis 8.2")
|
||||
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() {
|
||||
set := client.Set(ctx, "key1", "\x00", 0)
|
||||
Expect(set.Err()).NotTo(HaveOccurred())
|
||||
|
Reference in New Issue
Block a user