Skip to content

Commit d287e23

Browse files
authored
Merge branch 'unstable' into unstable
2 parents 6e89302 + 963861d commit d287e23

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

src/commands/cmd_hash.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,17 +408,23 @@ class CommandHScan : public CommandSubkeyScanBase {
408408
std::vector<std::string> values;
409409
auto key_name = srv->GetKeyNameFromCursor(cursor_, CursorType::kTypeHash);
410410

411-
auto s = hash_db.Scan(ctx, key_, key_name, limit_, prefix_, &fields, &values);
411+
auto s = hash_db.Scan(ctx, key_, key_name, limit_, prefix_, &fields, no_values_ ? nullptr : &values);
412412
if (!s.ok() && !s.IsNotFound()) {
413413
return {Status::RedisExecErr, s.ToString()};
414414
}
415415

416416
auto cursor = GetNextCursor(srv, fields, CursorType::kTypeHash);
417417
std::vector<std::string> entries;
418-
entries.reserve(2 * fields.size());
418+
if (no_values_) {
419+
entries.reserve(fields.size());
420+
} else {
421+
entries.reserve(2 * fields.size());
422+
}
419423
for (size_t i = 0; i < fields.size(); i++) {
420424
entries.emplace_back(redis::BulkString(fields[i]));
421-
entries.emplace_back(redis::BulkString(values[i]));
425+
if (!no_values_) {
426+
entries.emplace_back(redis::BulkString(values[i]));
427+
}
422428
}
423429
*output = redis::Array({redis::BulkString(cursor), redis::Array(entries)});
424430
return Status::OK();

src/commands/scan_base.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class CommandScanBase : public Commander {
6464
} else {
6565
return {Status::RedisExecErr, "Invalid type"};
6666
}
67+
} else if (parser.EatEqICase("novalues")) {
68+
no_values_ = true;
6769
} else {
6870
return parser.InvalidSyntax();
6971
}
@@ -102,6 +104,7 @@ class CommandScanBase : public Commander {
102104
std::string suffix_glob_ = "*";
103105
int limit_ = 20;
104106
RedisType type_ = kRedisNone;
107+
bool no_values_ = false;
105108
};
106109

107110
class CommandSubkeyScanBase : public CommandScanBase {

tests/gocase/unit/type/hash/hash_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,23 @@ var testHash = func(t *testing.T, configs util.KvrocksServerConfigs) {
775775
require.Equal(t, "b", rdb.HGet(ctx, "hash", strings.Repeat("k", 336)).Val())
776776
})
777777

778+
t.Run("HSCAN without NOVALUES", func(t *testing.T) {
779+
rdb.Del(ctx, "langhash")
780+
rdb.HMSet(ctx, "langhash", []string{"lang1", "C++", "lang2", "JavaScript", "lang3", "Python", "lang4", "GoLanguage"})
781+
res, _, _ := rdb.HScan(ctx, "langhash", 0, "lang1", 0).Result()
782+
require.Equal(t, 2, len(res))
783+
require.Equal(t, "lang1", res[0])
784+
require.Equal(t, "C++", res[1])
785+
})
786+
787+
t.Run("HSCAN with NOVALUES", func(t *testing.T) {
788+
rdb.Del(ctx, "langhash")
789+
rdb.HMSet(ctx, "langhash", []string{"lang1", "C++", "lang2", "JavaScript", "lang3", "Python", "lang4", "GoLanguage"})
790+
res, _, _ := rdb.HScanNoValues(ctx, "langhash", 0, "lang1", 0).Result()
791+
require.Equal(t, 1, len(res))
792+
require.Equal(t, "lang1", res[0])
793+
})
794+
778795
for _, size := range []int64{10, 512} {
779796
t.Run(fmt.Sprintf("Hash fuzzing #1 - %d fields", size), func(t *testing.T) {
780797
for times := 0; times < 10; times++ {

0 commit comments

Comments
 (0)