Skip to content

Commit

Permalink
resolved bitcount cmd bug (OpenAtomFoundation#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
hero-heng authored Feb 4, 2024
1 parent 9aad2bc commit 0436f90
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/cmd_kv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
33 changes: 17 additions & 16 deletions tests/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down

0 comments on commit 0436f90

Please sign in to comment.