HDEL fix, an optimization for comparison of objects in hash table lookups when they are integer encoding

This commit is contained in:
antirez 2010-03-17 19:26:53 +01:00
parent a4c507866c
commit 2a1198b4c4
2 changed files with 16 additions and 2 deletions

11
redis.c
View File

@ -1005,6 +1005,10 @@ static int dictEncObjKeyCompare(void *privdata, const void *key1,
robj *o1 = (robj*) key1, *o2 = (robj*) key2;
int cmp;
if (o1->encoding == REDIS_ENCODING_INT &&
o2->encoding == REDIS_ENCODING_INT &&
o1->ptr == o2->ptr) return 0;
o1 = getDecodedObject(o1);
o2 = getDecodedObject(o2);
cmp = sdsDictKeyCompare(privdata,o1->ptr,o2->ptr);
@ -5943,9 +5947,12 @@ static void hdelCommand(redisClient *c) {
checkType(c,o,REDIS_HASH)) return;
if (o->encoding == REDIS_ENCODING_ZIPMAP) {
robj *field = getDecodedObject(c->argv[2]);
o->ptr = zipmapDel((unsigned char*) o->ptr,
(unsigned char*) c->argv[2]->ptr,
sdslen(c->argv[2]->ptr), &deleted);
(unsigned char*) field->ptr,
sdslen(field->ptr), &deleted);
decrRefCount(field);
} else {
deleted = dictDelete((dict*)o->ptr,c->argv[2]) == DICT_OK;
}

View File

@ -125,6 +125,7 @@ proc randomKey {} {
proc createComplexDataset {r ops} {
for {set j 0} {$j < $ops} {incr j} {
set k [randomKey]
set f [randomValue]
set v [randomValue]
randpath {
set d [expr {rand()}]
@ -150,6 +151,8 @@ proc createComplexDataset {r ops} {
$r sadd $k $v
} {
$r zadd $k $d $v
} {
$r hset $k $f $v
}
set t [$r type $k]
}
@ -173,6 +176,10 @@ proc createComplexDataset {r ops} {
randpath {$r zadd $k $d $v} \
{$r zrem $k $v}
}
{hash} {
randpath {$r hset $k $f $v} \
{$r hdel $k $f}
}
}
}
}