Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9ee29c2
fixing test issue
yairgott Aug 12, 2025
a9fc017
fixing test issue
yairgott Aug 12, 2025
7dae1e6
addressing unittest issues
yairgott Aug 12, 2025
5d4c16a
addressing unittest issues
yairgott Aug 12, 2025
f826960
addressing lint
yairgott Aug 12, 2025
78b90bb
addressing comments
yairgott Aug 15, 2025
6f7f990
renaming, bug fixing and adding unittests
yairgott Aug 19, 2025
848fd6d
unittest fix
yairgott Aug 19, 2025
a7a1537
cosmetic change
yairgott Aug 19, 2025
06b6cfc
fixing module tests
yairgott Aug 19, 2025
c8a7aac
Merge remote-tracking branch 'upstream/unstable' into hash_shared
yairgott Aug 20, 2025
356891d
fixing comments
yairgott Aug 20, 2025
6913e21
addressing code review comments
Sep 5, 2025
82ef7bd
addressing lint
Sep 5, 2025
48193e8
addressing unit test failure
Sep 5, 2025
38aae4a
Update src/t_hash.c
yairgott Sep 9, 2025
5f65be7
Update src/t_hash.c
yairgott Sep 9, 2025
8224ea6
Update src/server.h
yairgott Sep 9, 2025
ed86fa0
Update src/entry.c
yairgott Sep 9, 2025
6d5a45e
addressing comments
Sep 9, 2025
2aea44d
addressing code review comments
Sep 9, 2025
37a006c
fixing module test
Sep 10, 2025
b97667a
addressing code review comments
Sep 16, 2025
bf6d7c7
addressing code review comments
Sep 17, 2025
ce0e3a9
addressing review comments
Nov 19, 2025
96a4530
Update src/entry.c
yairgott Nov 19, 2025
a0f541d
addressing review comments
Nov 20, 2025
90ac405
Merge branch 'unstable' into hash_shared
yairgott Nov 20, 2025
2569ea2
fixing rebase issues
Nov 20, 2025
2423aa6
lint fixes
Nov 20, 2025
f03c9ad
lint fixes
Nov 20, 2025
f2f7f80
fixing the test module hash_stringref initialization
Nov 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/aof.c
Original file line number Diff line number Diff line change
Expand Up @@ -1955,8 +1955,9 @@ static int rioWriteHashIteratorCursor(rio *r, hashTypeIterator *hi, int what) {
else
return rioWriteBulkLongLong(r, vll);
} else if (hi->encoding == OBJ_ENCODING_HASHTABLE) {
sds value = hashTypeCurrentFromHashTable(hi, what);
return rioWriteBulkString(r, value, sdslen(value));
size_t len;
char *value = hashTypeCurrentFromHashTable(hi, what, &len);
return rioWriteBulkString(r, value, len);
}

serverPanic("Unknown hash encoding");
Expand All @@ -1974,7 +1975,8 @@ int rewriteHashObject(rio *r, robj *key, robj *o) {
while (hashTypeNext(&hi) != C_ERR) {
long long expiry = entryGetExpiry(hi.next);
sds field = entryGetField(hi.next);
sds value = entryGetValue(hi.next);
size_t value_len;
char *value = entryGetValue(hi.next, &value_len);
if (rioWriteBulkCount(r, '*', 8) == 0) return 0;
if (rioWriteBulkString(r, "HSETEX", 6) == 0) return 0;
if (rioWriteBulkObject(r, key) == 0) return 0;
Expand All @@ -1983,7 +1985,7 @@ int rewriteHashObject(rio *r, robj *key, robj *o) {
if (rioWriteBulkString(r, "FIELDS", 6) == 0) return 0;
if (rioWriteBulkLongLong(r, 1) == 0) return 0;
if (rioWriteBulkString(r, field, sdslen(field)) == 0) return 0;
if (rioWriteBulkString(r, value, sdslen(value)) == 0) return 0;
if (rioWriteBulkString(r, value, value_len) == 0) return 0;
volatile_items++;
}
hashTypeResetIterator(&hi);
Expand Down
45 changes: 25 additions & 20 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,12 @@ int objectTypeCompare(robj *o, long long target) {
return 1;
}

static void addScanDataItem(vector *result, const char *buf, size_t len) {
stringRef *item = vectorPush(result);
item->buf = buf;
item->len = len;
}

/* Hashtable scan callback used by scanCallback when scanning the keyspace. */
void keysScanCallback(void *privdata, void *entry, int didx) {
scanData *data = (scanData *)privdata;
Expand Down Expand Up @@ -1031,15 +1037,14 @@ void keysScanCallback(void *privdata, void *entry, int didx) {
}

/* Keep this key. */
sds *item = vectorPush(data->result);
*item = key;
addScanDataItem(data->result, (const char *)key, sdslen(key));
}

/* This callback is used by scanGenericCommand in order to collect elements
* returned by the dictionary iterator into a list. */
void hashtableScanCallback(void *privdata, void *entry) {
scanData *data = (scanData *)privdata;
sds val = NULL;
stringRef val = {NULL, 0};
sds key = NULL;

robj *o = data->o;
Expand All @@ -1059,7 +1064,7 @@ void hashtableScanCallback(void *privdata, void *entry) {
} else if (o->type == OBJ_HASH) {
key = entryGetField(entry);
if (!data->only_keys) {
val = entryGetValue(entry);
val.buf = entryGetValue(entry, &val.len);
}
} else {
serverPanic("Type not handled in hashtable SCAN callback.");
Expand All @@ -1081,15 +1086,15 @@ void hashtableScanCallback(void *privdata, void *entry) {
if (!data->only_keys) {
char buf[MAX_LONG_DOUBLE_CHARS];
int len = ld2string(buf, sizeof(buf), node->score, LD_STR_AUTO);
val = sdsnewlen(buf, len);
sds tmp = sdsnewlen(buf, len);
val.buf = (const char *)tmp;
val.len = sdslen(tmp);
}
}

sds *item = vectorPush(data->result);
*item = key;
if (val) {
item = vectorPush(data->result);
*item = val;
addScanDataItem(data->result, (const char *)key, sdslen(key));
if (val.buf) {
addScanDataItem(data->result, val.buf, val.len);
}
}

Expand Down Expand Up @@ -1244,7 +1249,7 @@ void scanGenericCommand(client *c, robj *o, unsigned long long cursor) {
/* scanning ZSET allocates temporary strings even though it's a dict */
free_callback = sdsfree;
}
vectorInit(&result, SCAN_VECTOR_INITIAL_ALLOC, sizeof(sds));
vectorInit(&result, SCAN_VECTOR_INITIAL_ALLOC, sizeof(stringRef));

/* For main hash table scan or scannable data structure. */
if (!o || ht) {
Expand Down Expand Up @@ -1305,8 +1310,8 @@ void scanGenericCommand(client *c, robj *o, unsigned long long cursor) {
if (use_pattern && !stringmatchlen(pat, sdslen(pat), key, len, 0)) {
continue;
}
sds *item = vectorPush(&result);
*item = sdsnewlen(key, len);
sds item = sdsnewlen(key, len);
addScanDataItem(&result, (const char *)item, sdslen(item));
}
setTypeReleaseIterator(si);
cursor = 0;
Expand All @@ -1326,13 +1331,13 @@ void scanGenericCommand(client *c, robj *o, unsigned long long cursor) {
continue;
}
/* add key object */
sds *item = vectorPush(&result);
*item = sdsnewlen(str, len);
sds item = sdsnewlen(str, len);
addScanDataItem(&result, (const char *)item, sdslen(item));
/* add value object */
if (!only_keys) {
str = lpGet(p, &len, intbuf);
item = vectorPush(&result);
*item = sdsnewlen(str, len);
item = sdsnewlen(str, len);
addScanDataItem(&result, (const char *)item, sdslen(item));
}
p = lpNext(o->ptr, p);
}
Expand All @@ -1347,10 +1352,10 @@ void scanGenericCommand(client *c, robj *o, unsigned long long cursor) {

addReplyArrayLen(c, vectorLen(&result));
for (uint32_t i = 0; i < vectorLen(&result); i++) {
sds *key = vectorGet(&result, i);
addReplyBulkCBuffer(c, *key, sdslen(*key));
stringRef *key = vectorGet(&result, i);
addReplyBulkCBuffer(c, key->buf, key->len);
if (free_callback) {
free_callback(*key);
free_callback((sds)(key->buf));
}
}

Expand Down
Loading
Loading