This is an automated email from the ASF dual-hosted git repository.
hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new 1ed45bc4 fix(string): reset the value of expired key for SETRANGE cmd
(#2686)
1ed45bc4 is described below
commit 1ed45bc41e1f55cc76f405da605532390ca74491
Author: weimeng <[email protected]>
AuthorDate: Tue Dec 3 15:37:39 2024 +0800
fix(string): reset the value of expired key for SETRANGE cmd (#2686)
---
src/types/redis_string.cc | 6 +++---
tests/cppunit/types/string_test.cc | 9 +++++++++
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/types/redis_string.cc b/src/types/redis_string.cc
index 85a3a95d..a3d27492 100644
--- a/src/types/redis_string.cc
+++ b/src/types/redis_string.cc
@@ -65,7 +65,9 @@ rocksdb::Status String::getRawValue(engine::Context &ctx,
const std::string &ns_
Metadata metadata(kRedisNone, false);
Slice slice = *raw_value;
- return ParseMetadataWithStats({kRedisString}, &slice, &metadata);
+ s = ParseMetadataWithStats({kRedisString}, &slice, &metadata);
+ if (!s.ok()) raw_value->clear();
+ return s;
}
rocksdb::Status String::getValueAndExpire(engine::Context &ctx, const
std::string &ns_key, std::string *value,
@@ -329,7 +331,6 @@ rocksdb::Status String::IncrBy(engine::Context &ctx, const
std::string &user_key
if (!s.ok() && !s.IsNotFound()) return s;
if (s.IsNotFound()) {
Metadata metadata(kRedisString, false);
- raw_value.clear();
metadata.Encode(&raw_value);
}
@@ -368,7 +369,6 @@ rocksdb::Status String::IncrByFloat(engine::Context &ctx,
const std::string &use
if (s.IsNotFound()) {
Metadata metadata(kRedisString, false);
- raw_value.clear();
metadata.Encode(&raw_value);
}
size_t offset = Metadata::GetOffsetAfterExpire(raw_value[0]);
diff --git a/tests/cppunit/types/string_test.cc
b/tests/cppunit/types/string_test.cc
index 386aebb3..1b5c1a27 100644
--- a/tests/cppunit/types/string_test.cc
+++ b/tests/cppunit/types/string_test.cc
@@ -250,6 +250,15 @@ TEST_F(RedisStringTest, SetRange) {
string_->Get(*ctx_, key_, &value);
EXPECT_EQ(16, value.size());
auto s = string_->Del(*ctx_, key_);
+
+ string_->SetEX(*ctx_, key_, "test-value", 1);
+ sleep(2);
+ s = string_->Get(*ctx_, key_, &value);
+ EXPECT_TRUE(s.IsNotFound());
+ string_->SetRange(*ctx_, key_, 0, "12345", &ret);
+ EXPECT_EQ(5, ret);
+ string_->Get(*ctx_, key_, &value);
+ EXPECT_EQ("12345", value);
}
TEST_F(RedisStringTest, CAS) {