diff options
author | Lu JJ <41555481+ncghost1@users.noreply.github.com> | 2022-04-06 02:45:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-05 21:45:45 +0300 |
commit | f110de4b239d23b8436fdc742a557103c5852aad (patch) | |
tree | 783dbaba323c1122d6c9d23867bef2adf10131df /src/t_hash.c | |
parent | 8a7049d36305d297a31ab14d7acab372a579f2ee (diff) | |
download | redis-f110de4b239d23b8436fdc742a557103c5852aad.tar.gz |
Fix the bug that caused hash encoding errors when using hincrbyfloat or hincrby commands (#10479)
Fixed a bug that used the `hincrbyfloat` or `hincrby` commands to make the field or value exceed the
`hash_max_listpack_value` but did not change the object encoding of the hash structure.
Add a length check for field and value, check the length of value first, if the length of value does not
exceed `hash_max_listpack_value` then check the length of field.
If the length of field or value is too long, it will reduce the efficiency of listpack, and the object encoding
will become hashtable after AOF restart, so this is also to keep the same before and after AOF restart.
Diffstat (limited to 'src/t_hash.c')
-rw-r--r-- | src/t_hash.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/t_hash.c b/src/t_hash.c index 92f5cb2b0..3f6d9528a 100644 --- a/src/t_hash.c +++ b/src/t_hash.c @@ -205,6 +205,14 @@ int hashTypeExists(robj *o, sds field) { int hashTypeSet(robj *o, sds field, sds value, int flags) { int update = 0; + /* Check if the field is too long for listpack, and convert before adding the item. + * This is needed for HINCRBY* case since in other commands this is handled early by + * hashTypeTryConversion, so this check will be a NOP. */ + if (o->encoding == OBJ_ENCODING_LISTPACK) { + if (sdslen(field) > server.hash_max_listpack_value || sdslen(value) > server.hash_max_listpack_value) + hashTypeConvert(o, OBJ_ENCODING_HT); + } + if (o->encoding == OBJ_ENCODING_LISTPACK) { unsigned char *zl, *fptr, *vptr; |