summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2010-03-17 19:26:53 +0100
committerantirez <antirez@gmail.com>2010-03-17 19:26:53 +0100
commit2a1198b4c4fd07b5e560425432fa1b2bcdaca1a1 (patch)
tree43a50a8818e35c89f99c90a1fa25b3f35ecdb583
parenta4c507866cb091074458a0a48120a95339b350c4 (diff)
downloadredis-2a1198b4c4fd07b5e560425432fa1b2bcdaca1a1.tar.gz
HDEL fix, an optimization for comparison of objects in hash table lookups when they are integer encoding
-rw-r--r--redis.c11
-rw-r--r--test-redis.tcl7
2 files changed, 16 insertions, 2 deletions
diff --git a/redis.c b/redis.c
index c40b6eec8..ec971419f 100644
--- a/redis.c
+++ b/redis.c
@@ -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;
}
diff --git a/test-redis.tcl b/test-redis.tcl
index d7a4d7fd9..3dd03fd24 100644
--- a/test-redis.tcl
+++ b/test-redis.tcl
@@ -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}
+ }
}
}
}