Unverified Commit 4278c45c authored by luvine's avatar luvine Committed by GitHub
Browse files

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.
parent 1d5aa37d
...@@ -641,11 +641,11 @@ void hashTypeRandomElement(robj *hashobj, unsigned long hashsize, ziplistEntry * ...@@ -641,11 +641,11 @@ void hashTypeRandomElement(robj *hashobj, unsigned long hashsize, ziplistEntry *
void hsetnxCommand(client *c) { void hsetnxCommand(client *c) {
robj *o; robj *o;
if ((o = hashTypeLookupWriteOrCreate(c,c->argv[1])) == NULL) return; if ((o = hashTypeLookupWriteOrCreate(c,c->argv[1])) == NULL) return;
hashTypeTryConversion(o,c->argv,2,3);
if (hashTypeExists(o, c->argv[2]->ptr)) { if (hashTypeExists(o, c->argv[2]->ptr)) {
addReply(c, shared.czero); addReply(c, shared.czero);
} else { } else {
hashTypeTryConversion(o,c->argv,2,3);
hashTypeSet(o,c->argv[2]->ptr,c->argv[3]->ptr,HASH_SET_COPY); hashTypeSet(o,c->argv[2]->ptr,c->argv[3]->ptr,HASH_SET_COPY);
addReply(c, shared.cone); addReply(c, shared.cone);
signalModifiedKey(c,c->db,c->argv[1]); signalModifiedKey(c,c->db,c->argv[1]);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment