mirror of https://mirror.osredm.com/root/redis.git
Merge a2dfe4ea12
into ebf19e4c92
This commit is contained in:
commit
74f8fcce7d
21
src/t_hash.c
21
src/t_hash.c
|
@ -930,8 +930,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;
|
||||
|
@ -965,14 +967,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;
|
||||
|
@ -1006,7 +1009,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);
|
||||
|
|
|
@ -19,12 +19,14 @@ start_server {tags {"modules"}} {
|
|||
} {{f1 v1} {f2 v2}}
|
||||
|
||||
test {Module scan hash listpack with int value} {
|
||||
r del hh1
|
||||
r hmset hh1 f1 1
|
||||
assert_encoding listpack hh1
|
||||
lsort [r scan.scan_key hh1]
|
||||
} {{f1 1}}
|
||||
|
||||
test {Module scan hash listpack with hexpire} {
|
||||
r del hh
|
||||
r debug set-active-expire 0
|
||||
r hmset hh f1 v1 f2 v2 f3 v3
|
||||
r hexpire hh 100000 fields 1 f1
|
||||
|
@ -37,6 +39,8 @@ start_server {tags {"modules"}} {
|
|||
} {{f1 v1} {f2 v2}} {needs:debug}
|
||||
|
||||
test {Module scan hash dict} {
|
||||
r del hh
|
||||
r hset hh f1 v1 f2 v2
|
||||
r config set hash-max-ziplist-entries 2
|
||||
r hmset hh f3 v3
|
||||
assert_encoding hashtable hh
|
||||
|
@ -72,6 +76,8 @@ start_server {tags {"modules"}} {
|
|||
} {{f1 1} {f2 2}}
|
||||
|
||||
test {Module scan zset skiplist} {
|
||||
r del zz
|
||||
r zadd zz 1 f1 2 f2
|
||||
r config set zset-max-ziplist-entries 2
|
||||
r zadd zz 3 f3
|
||||
assert_encoding skiplist zz
|
||||
|
@ -79,12 +85,15 @@ start_server {tags {"modules"}} {
|
|||
} {{f1 1} {f2 2} {f3 3}}
|
||||
|
||||
test {Module scan set intset} {
|
||||
r del ss
|
||||
r sadd ss 1 2
|
||||
assert_encoding intset ss
|
||||
lsort [r scan.scan_key ss]
|
||||
} {{1 {}} {2 {}}}
|
||||
|
||||
test {Module scan set dict} {
|
||||
r del ss
|
||||
r sadd ss 1 2
|
||||
r config set set-max-intset-entries 2
|
||||
r sadd ss 3
|
||||
assert_encoding hashtable ss
|
||||
|
|
Loading…
Reference in New Issue