Skip to content

Commit

Permalink
fix: Change the maximum range of setbit's offset to fit redis (#2995)
Browse files Browse the repository at this point in the history
* Change the maximum range of setbit's offset to fit redis

---------

Co-authored-by: wuxianrong <[email protected]>
  • Loading branch information
2 people authored and brother-jin committed Feb 11, 2025
1 parent b92c779 commit f0bea9a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ set(ZSTD_INCLUDE_DIR ${INSTALL_INCLUDEDIR})
ExternalProject_Add(fmt
DEPENDS
URL
https://github.com/fmtlib/fmt/archive/refs/tags/7.1.0.tar.gz
https://github.com/fmtlib/fmt/archive/refs/tags/10.2.1.tar.gz
URL_HASH
MD5=32af902636d373641f4ef9032fc65b3a
MD5=dc09168c94f90ea890257995f2c497a5
DOWNLOAD_NO_PROGRESS
1
UPDATE_COMMAND
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ var _ = Describe("String Commands", func() {
Expect(getBit.Err()).NotTo(HaveOccurred())
Expect(getBit.Val()).To(Equal(int64(0)))
})

It("should GetRange", func() {
set := client.Set(ctx, "key", "This is a string", 0)
Expect(set.Err()).NotTo(HaveOccurred())
Expand Down
40 changes: 40 additions & 0 deletions tests/unit/type/bitops.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,46 @@ start_server {tags {"bitops"}} {
r get s
} "\x55\xff\x00\xaa"

test {SetBit and GetBit with large offset} {
set max_offset [expr {2**32 - 1}]
set invalid_offset [expr {2**32}]

r setbit large_key $max_offset 1
set result [r getbit large_key $max_offset]
set invalid_result [catch {r setbit large_key $invalid_offset 1} err]

list $result $invalid_result $err
} {1 1 {ERR bit offset is not an integer or out of range}}

test {BITCOUNT with large offset} {
r setbit count_key 0 1
r setbit count_key 100 1
r setbit count_key [expr {2**32 - 1}] 1

set total_count [r bitcount count_key]
set range_count [r bitcount count_key 0 12]

list $total_count $range_count
} {3 2}

test {BITPOS with large offset} {
r setbit pos_key [expr {2**32 - 1}] 1
set first_one [r bitpos pos_key 1]
set first_zero [r bitpos pos_key 0]
list $first_one $first_zero
} {4294967295 0}

test {BITOP operations} {
r setbit key1 0 1
r setbit key2 [expr {2**32 - 1}] 1
r bitop or result_key key1 key2

set result_bit1 [r getbit result_key 0]
set result_bit2 [r getbit result_key [expr {2**32 - 1}]]

list $result_bit1 $result_bit2
} {1 1}

test {BITOP AND|OR|XOR don't change the string with single input key} {
r set a "\x01\x02\xff"
r bitop and res1 a
Expand Down
2 changes: 1 addition & 1 deletion tools/manifest_generator/include/pika_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ const std::string kInnerReplOk = "ok";
const std::string kInnerReplWait = "wait";

const unsigned int kMaxBitOpInputKey = 12800;
const int kMaxBitOpInputBit = 21;
const int kMaxBitOpInputBit = 32;
/*
* db sync
*/
Expand Down

0 comments on commit f0bea9a

Please sign in to comment.