From 36cb9ca7bcfa8656eba08890ac048e31780a4038 Mon Sep 17 00:00:00 2001 From: Rain Valentine Date: Tue, 29 Oct 2024 22:10:51 +0000 Subject: [PATCH] missed updating a few spots Signed-off-by: Rain Valentine --- src/lazyfree.c | 6 +++--- src/module.c | 32 ++++++++++++++++++++++++++------ src/rdb.c | 4 ++-- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/lazyfree.c b/src/lazyfree.c index 6176b43440..1055d37043 100644 --- a/src/lazyfree.c +++ b/src/lazyfree.c @@ -116,9 +116,9 @@ size_t lazyfreeGetFreeEffort(robj *key, robj *obj, int dbid) { if (obj->type == OBJ_LIST && obj->encoding == OBJ_ENCODING_QUICKLIST) { quicklist *ql = obj->ptr; return ql->len; - } else if (obj->type == OBJ_SET && obj->encoding == OBJ_ENCODING_HT) { - dict *ht = obj->ptr; - return dictSize(ht); + } else if (obj->type == OBJ_SET && obj->encoding == OBJ_ENCODING_HASHSET) { + hashset *s = obj->ptr; + return hashsetSize(s); } else if (obj->type == OBJ_ZSET && obj->encoding == OBJ_ENCODING_SKIPLIST) { zset *zs = obj->ptr; return zs->zsl->length; diff --git a/src/module.c b/src/module.c index c83dcaae6b..461841a4a1 100644 --- a/src/module.c +++ b/src/module.c @@ -10995,20 +10995,20 @@ typedef struct { ValkeyModuleScanKeyCB fn; } ScanKeyCBData; -static void moduleScanKeyCallback(void *privdata, const dictEntry *de) { +static void moduleScanKeyDictCallback(void *privdata, const dictEntry *de) { ScanKeyCBData *data = privdata; sds key = dictGetKey(de); robj *o = data->key->value; robj *field = createStringObject(key, sdslen(key)); robj *value = NULL; - if (o->type == OBJ_SET) { - value = NULL; - } else if (o->type == OBJ_HASH) { + if (o->type == OBJ_HASH) { sds val = dictGetVal(de); value = createStringObject(val, sdslen(val)); } else if (o->type == OBJ_ZSET) { double *val = (double *)dictGetVal(de); value = createStringObjectFromLongDouble(*val, 0); + } else { + serverPanic("unexpected object type"); } data->fn(data->key, field, value, data->user_data); @@ -11016,6 +11016,18 @@ static void moduleScanKeyCallback(void *privdata, const dictEntry *de) { if (value) decrRefCount(value); } +static void moduleScanKeyHashsetCallback(void *privdata, void *element) { + ScanKeyCBData *data = privdata; + sds key = element; + robj *o = data->key->value; + robj *field = createStringObject(key, sdslen(key)); + + serverAssert(o->type == OBJ_SET); + + data->fn(data->key, field, NULL, data->user_data); + decrRefCount(field); +} + /* Scan api that allows a module to scan the elements in a hash, set or sorted set key * * Callback for scan implementation. @@ -11070,9 +11082,10 @@ int VM_ScanKey(ValkeyModuleKey *key, ValkeyModuleScanCursor *cursor, ValkeyModul return 0; } dict *ht = NULL; + hashset *s = NULL; robj *o = key->value; if (o->type == OBJ_SET) { - if (o->encoding == OBJ_ENCODING_HT) ht = o->ptr; + if (o->encoding == OBJ_ENCODING_HASHSET) s = o->ptr; } else if (o->type == OBJ_HASH) { if (o->encoding == OBJ_ENCODING_HT) ht = o->ptr; } else if (o->type == OBJ_ZSET) { @@ -11088,7 +11101,14 @@ int VM_ScanKey(ValkeyModuleKey *key, ValkeyModuleScanCursor *cursor, ValkeyModul int ret = 1; if (ht) { ScanKeyCBData data = {key, privdata, fn}; - cursor->cursor = dictScan(ht, cursor->cursor, moduleScanKeyCallback, &data); + cursor->cursor = dictScan(ht, cursor->cursor, moduleScanKeyDictCallback, &data); + if (cursor->cursor == 0) { + cursor->done = 1; + ret = 0; + } + } else if (s) { + ScanKeyCBData data = {key, privdata, fn}; + cursor->cursor = hashsetScan(s, cursor->cursor, moduleScanKeyHashsetCallback, &data, 0); if (cursor->cursor == 0) { cursor->done = 1; ret = 0; diff --git a/src/rdb.c b/src/rdb.c index 8d847b9d73..3dd2d59476 100644 --- a/src/rdb.c +++ b/src/rdb.c @@ -2348,7 +2348,7 @@ robj *rdbLoadObject(int rdbtype, rio *rdb, sds key, int dbid, int *error) { } o->type = OBJ_SET; o->encoding = OBJ_ENCODING_INTSET; - if (intsetLen(o->ptr) > server.set_max_intset_entries) setTypeConvert(o, OBJ_ENCODING_HT); + if (intsetLen(o->ptr) > server.set_max_intset_entries) setTypeConvert(o, OBJ_ENCODING_HASHSET); break; case RDB_TYPE_SET_LISTPACK: if (deep_integrity_validation) server.stat_dump_payload_sanitizations++; @@ -2368,7 +2368,7 @@ robj *rdbLoadObject(int rdbtype, rio *rdb, sds key, int dbid, int *error) { decrRefCount(o); goto emptykey; } - if (setTypeSize(o) > server.set_max_listpack_entries) setTypeConvert(o, OBJ_ENCODING_HT); + if (setTypeSize(o) > server.set_max_listpack_entries) setTypeConvert(o, OBJ_ENCODING_HASHSET); break; case RDB_TYPE_ZSET_ZIPLIST: { unsigned char *lp = lpNew(encoded_len);