This commit is contained in:
Vitah Lin 2025-05-13 21:56:43 +08:00 committed by GitHub
commit 4a84d410d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 9 deletions

View File

@ -926,8 +926,10 @@ int hashTypeSet(redisDb *db, robj *o, sds field, sds value, int flags) {
}
o->ptr = zl;
/* Check if the listpack needs to be converted to a hash table */
if (hashTypeLength(o, 0) > server.hash_max_listpack_entries)
/* Check if the listpack needs to be converted to a hash table.
* We do not subtract expired field here, if there is no new field inserted,
* we also skip recomputing the listpack element count, avoiding unnecessary overhead. */
if (!update && hashTypeLength(o, 0) > server.hash_max_listpack_entries)
hashTypeConvert(o, OBJ_ENCODING_HT, &db->hexpires);
} else if (o->encoding == OBJ_ENCODING_LISTPACK_EX) {
unsigned char *fptr = NULL, *vptr = NULL, *tptr = NULL;
@ -961,14 +963,15 @@ int hashTypeSet(redisDb *db, robj *o, sds field, sds value, int flags) {
}
}
if (!update)
if (!update) {
listpackExAddNew(o, field, sdslen(field), value, sdslen(value),
HASH_LP_NO_TTL);
/* Check if the listpack needs to be converted to a hash table */
if (hashTypeLength(o, 0) > server.hash_max_listpack_entries)
hashTypeConvert(o, OBJ_ENCODING_HT, &db->hexpires);
/* Check if the listpack needs to be converted to a hash table.
* We do not subtract expired field here, if there is no new field inserted,
* we also skip recomputing the listpack element count, avoiding unnecessary overhead. */
if (hashTypeLength(o, 0) > server.hash_max_listpack_entries)
hashTypeConvert(o, OBJ_ENCODING_HT, &db->hexpires);
}
} else if (o->encoding == OBJ_ENCODING_HT) {
dict *ht = o->ptr;
dictEntry *de;
@ -1002,7 +1005,7 @@ int hashTypeSet(redisDb *db, robj *o, sds field, sds value, int flags) {
serverPanic("Unknown hash encoding");
}
/* Free SDS strings we did not referenced elsewhere if the flags
/* Free SDS strings we did not reference elsewhere if the flags
* want this function to be responsible. */
if (flags & HASH_SET_TAKE_FIELD && field) sdsfree(field);
if (flags & HASH_SET_TAKE_VALUE && value) sdsfree(value);