HGET fix for integer encoded field against zipmap encoded hash

This commit is contained in:
antirez 2010-03-16 18:44:37 +01:00
parent 23d8214891
commit 164ee59564
2 changed files with 65 additions and 1 deletions

View File

@ -5870,14 +5870,18 @@ static void hgetCommand(redisClient *c) {
unsigned char *zm = o->ptr;
unsigned char *val;
unsigned int vlen;
robj *field;
if (zipmapGet(zm,c->argv[2]->ptr,sdslen(c->argv[2]->ptr), &val,&vlen)) {
field = getDecodedObject(c->argv[2]);
if (zipmapGet(zm,field->ptr,sdslen(field->ptr), &val,&vlen)) {
addReplySds(c,sdscatprintf(sdsempty(),"$%u\r\n", vlen));
addReplySds(c,sdsnewlen(val,vlen));
addReply(c,shared.crlf);
decrRefCount(field);
return;
} else {
addReply(c,shared.nullbulk);
decrRefCount(field);
return;
}
} else {

View File

@ -1520,6 +1520,66 @@ proc main {server port} {
$r zrange zset 0 -1
} {min c a b d max}
test {HSET/HLEN - Small hash creation} {
array set smallhash {}
for {set i 0} {$i < 8} {incr i} {
set key [randstring 0 8 alpha]
set val [randstring 0 8 alpha]
if {[info exists smallhash($key)]} {
incr i -1
continue
}
$r hset smallhash $key $val
set smallhash($key) $val
}
list [$r hlen smallhash]
} {8}
test {Is the small hash encoded with a zipmap?} {
$r debug object smallhash
} {*zipmap*}
test {HSET/HLEN - Big hash creation} {
array set bighash {}
for {set i 0} {$i < 1024} {incr i} {
set key [randstring 0 8 alpha]
set val [randstring 0 8 alpha]
if {[info exists bighash($key)]} {
incr i -1
continue
}
$r hset bighash $key $val
set bighash($key) $val
}
list [$r hlen bighash]
} {1024}
test {Is the big hash encoded with a zipmap?} {
$r debug object bighash
} {*hashtable*}
test {HGET against the small hash} {
set err {}
foreach k [array names smallhash *] {
if {$smallhash($k) ne [$r hget smallhash $k]} {
set err "$smallhash($k) != [$r hget smallhash $k]"
break
}
}
set _ $err
} {}
test {HGET against the big hash} {
set err {}
foreach k [array names bighash *] {
if {$bighash($k) ne [$r hget bighash $k]} {
set err "$bighash($k) != [$r hget bighash $k]"
break
}
}
set _ $err
} {}
test {EXPIRE - don't set timeouts multiple times} {
$r set x foobar
set v1 [$r expire x 5]