Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
164ee595
Commit
164ee595
authored
Mar 16, 2010
by
antirez
Browse files
HGET fix for integer encoded field against zipmap encoded hash
parent
23d82148
Changes
2
Hide whitespace changes
Inline
Side-by-side
redis.c
View file @
164ee595
...
...
@@ -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 {
...
...
test-redis.tcl
View file @
164ee595
...
...
@@ -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
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment