diff options
author | luvine <35490781+luvine@users.noreply.github.com> | 2021-06-30 17:14:11 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-30 12:14:11 +0300 |
commit | 4278c45c913ccd615a7fd13c8463de79b699c4e1 (patch) | |
tree | 17076cf5a73c4e12656ff85583a783f4dbca2c48 /src/t_hash.c | |
parent | 1d5aa37d681ce3d841bdb631953956fe567993e4 (diff) | |
download | redis-4278c45c913ccd615a7fd13c8463de79b699c4e1.tar.gz |
HSETNX can lead coding type change even when skipped due to NX (#4615)
1. Add one key-value pair to myhash, which the length of key and value both less than hash-max-ziplist-value, for example:
>hset myhash key value
2. Then execute the following command
>hsetnx myhash key value1 (the length greater than hash-max-ziplist-value)
3. This will add nothing, but the code type of "myhash" changed from ziplist to dict even there are only one key-value pair in "myhash", and both of them less than hash-max-ziplist-value.
Diffstat (limited to 'src/t_hash.c')
-rw-r--r-- | src/t_hash.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/t_hash.c b/src/t_hash.c index b9faebe94..865145807 100644 --- a/src/t_hash.c +++ b/src/t_hash.c @@ -641,11 +641,11 @@ void hashTypeRandomElement(robj *hashobj, unsigned long hashsize, ziplistEntry * void hsetnxCommand(client *c) { robj *o; if ((o = hashTypeLookupWriteOrCreate(c,c->argv[1])) == NULL) return; - hashTypeTryConversion(o,c->argv,2,3); if (hashTypeExists(o, c->argv[2]->ptr)) { addReply(c, shared.czero); } else { + hashTypeTryConversion(o,c->argv,2,3); hashTypeSet(o,c->argv[2]->ptr,c->argv[3]->ptr,HASH_SET_COPY); addReply(c, shared.cone); signalModifiedKey(c,c->db,c->argv[1]); |