Skip to content

Commit

Permalink
fix: fix ExpectedStale error when expired type is string (OpenAtomFou…
Browse files Browse the repository at this point in the history
  • Loading branch information
wangshao1 authored May 29, 2024
1 parent bd54c1e commit 48dd05a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/storage/src/redis.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,19 +406,16 @@ class Redis {
auto meta_type = static_cast<enum DataType>(static_cast<uint8_t>(meta_value[0]));
if (meta_type == DataType::kZSets || meta_type == DataType::kSets || meta_type == DataType::kHashes) {
ParsedBaseMetaValue parsed_meta_value(meta_value);
if (parsed_meta_value.IsStale() || parsed_meta_value.Count() == 0) {
return true;
}
return (parsed_meta_value.IsStale() || parsed_meta_value.Count() == 0);
} else if (meta_type == DataType::kLists) {
ParsedListsMetaValue parsed_lists_meta_value(meta_value);
if (parsed_lists_meta_value.IsStale() || parsed_lists_meta_value.Count() == 0) {
return true;
}
return (parsed_lists_meta_value.IsStale() || parsed_lists_meta_value.Count() == 0);
} else if (meta_type == DataType::kStrings) {
ParsedStringsValue parsed_strings_value(meta_value);
return parsed_strings_value.IsStale();
} else if (meta_type == DataType::kStreams) {
StreamMetaValue stream_meta_value;
if (stream_meta_value.length() == 0) {
return true;
}
return stream_meta_value.length() == 0;
}
return false;
}
Expand Down
9 changes: 9 additions & 0 deletions src/storage/tests/hashes_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,15 @@ TEST_F(HashesTest, HSetTest) {
s = db.HGet("GP3_HSET_KEY", "HSET_TEST_NEW_FIELD", &value);
ASSERT_TRUE(s.ok());
ASSERT_EQ(value, "HSET_TEST_NEW_VALUE");

// ***************** Group 4 Test *****************
// hset after string type key expires, should success
s = db.Setex("GP4_HSET_KEY", "STRING_VALUE_WITH_TTL", 1);
ASSERT_TRUE(s.ok());
std::this_thread::sleep_for(std::chrono::milliseconds(2100));
s = db.HSet("GP4_HSET_KEY", "HSET_TEST_NEW_FIELD", "HSET_TEST_NEW_VALUE", &ret);
ASSERT_TRUE(s.ok());
ASSERT_EQ(ret, 1);
}

// HSetnx
Expand Down

0 comments on commit 48dd05a

Please sign in to comment.