Skip to content

Commit

Permalink
avoid check field expiration on hmset command
Browse files Browse the repository at this point in the history
  • Loading branch information
jjz921024 committed Jan 10, 2025
1 parent b6b9473 commit 473db0c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/storage/redis_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ rocksdb::Status Database::MDel(engine::Context &ctx, const std::vector<Slice> &k
redis::Hash hash_db(storage_, namespace_);
if (hash_db.ExistValidField(ctx, slice_keys[i], hash_metadata)) {
if (!s.ok()) return s;
*deleted_cnt += 1;
*deleted_cnt += 1;
}
} else {
*deleted_cnt += 1;
Expand Down
7 changes: 6 additions & 1 deletion src/types/redis_hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,13 @@ rocksdb::Status Hash::MSet(engine::Context &ctx, const Slice &user_key, const st
*added_cnt = 0;
std::string ns_key = AppendNamespacePrefix(user_key);

std::string raw_value;
auto s = Database::GetRawMetadata(ctx, ns_key, &raw_value);
if (!s.ok() && !s.IsNotFound()) return s;

Slice rest = raw_value;
HashMetadata metadata;
rocksdb::Status s = GetMetadata(ctx, ns_key, &metadata);
s = ParseMetadataWithStats({kRedisHash}, &rest, &metadata);
if (!s.ok() && !s.IsNotFound()) return s;

// For avoid affect existing data, we only encode ttl of field
Expand Down
2 changes: 1 addition & 1 deletion tests/gocase/unit/type/hash/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ func TestHashFieldExpiration(t *testing.T) {
require.Equal(t, int64(0), rdb.HDel(ctx, "hfe-key", "f1").Val())
})

t.Run("HFE perist a field of hash", func(t *testing.T) {
t.Run("HFE persist a field of hash", func(t *testing.T) {
require.NoError(t, rdb.Del(ctx, "hfe-key").Err())
require.Equal(t, true, rdb.HMSet(ctx, "hfe-key", "f1", "v1", "f2", "v2").Val())
rdb.Do(ctx, "HPEXPIRE", "hfe-key", 100, "FIELDS", 1, "f1")
Expand Down

0 comments on commit 473db0c

Please sign in to comment.