From 0436f9078f152789c7bc01392dcaae59f34e63e1 Mon Sep 17 00:00:00 2001 From: Henry Towne <57589133+hero-heng@users.noreply.github.com> Date: Sun, 4 Feb 2024 19:39:18 +0800 Subject: [PATCH] resolved bitcount cmd bug (#165) --- src/cmd_kv.cc | 2 +- tests/string_test.go | 33 +++++++++++++++++---------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/cmd_kv.cc b/src/cmd_kv.cc index 725b662f8..cedc899fd 100644 --- a/src/cmd_kv.cc +++ b/src/cmd_kv.cc @@ -177,7 +177,7 @@ void BitCountCmd::DoCmd(PClient* client) { return; } - s = PSTORE.GetBackend(client->GetCurrentDB())->BitCount(client->Key(), start_offset, end_offset, &count, false); + s = PSTORE.GetBackend(client->GetCurrentDB())->BitCount(client->Key(), start_offset, end_offset, &count, true); } if (s.ok() || s.IsNotFound()) { diff --git a/tests/string_test.go b/tests/string_test.go index 48ac30c27..e722891b6 100644 --- a/tests/string_test.go +++ b/tests/string_test.go @@ -167,27 +167,28 @@ var _ = Describe("String", Ordered, func() { }) It("BitCount", func() { - r, e := client.Set(ctx, DefaultKey, DefaultValue, 0).Result() + r, e := client.Set(ctx, DefaultKey, "foobar", 0).Result() Expect(e).NotTo(HaveOccurred()) Expect(r).To(Equal(OK)) rBitCount, eBitCount := client.BitCount(ctx, DefaultKey, nil).Result() Expect(eBitCount).NotTo(HaveOccurred()) - Expect(rBitCount).To(Equal(int64(21))) - - // bitCount = client.BitCount(ctx, "testKeyBC", &redis.BitCount{ - // Start: 0, - // End: 0, - // }) - // Expect(bitCount.Err()).NotTo(HaveOccurred()) - // Expect(bitCount.Val()).To(Equal(int64(4))) - // - // bitCount = client.BitCount(ctx, "testKeyBC", &redis.BitCount{ - // Start: 1, - // End: 1, - // }) - // Expect(bitCount.Err()).NotTo(HaveOccurred()) - // Expect(bitCount.Val()).To(Equal(int64(6))) + Expect(rBitCount).To(Equal(int64(26))) + + bitCount := client.BitCount(ctx, DefaultKey, &redis.BitCount{ + Start: 0, + End: 0, + }) + Expect(bitCount.Err()).NotTo(HaveOccurred()) + Expect(bitCount.Val()).To(Equal(int64(4))) + + bitCount = client.BitCount(ctx, DefaultKey, &redis.BitCount{ + Start: 1, + End: 1, + }) + Expect(bitCount.Err()).NotTo(HaveOccurred()) + Expect(bitCount.Val()).To(Equal(int64(6))) + rDel, eDel := client.Del(ctx, DefaultKey).Result() Expect(eDel).NotTo(HaveOccurred()) Expect(rDel).To(Equal(int64(1)))