Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
ce7bef07
Commit
ce7bef07
authored
Apr 08, 2009
by
antirez
Browse files
RANDOMKEY issue 26 fixed, generic test + regression added
parent
05557f6d
Changes
2
Show whitespace changes
Inline
Side-by-side
redis.c
View file @
ce7bef07
...
...
@@ -2237,9 +2237,10 @@ static void randomkeyCommand(redisClient *c) {
while
(
1
)
{
de
=
dictGetRandomKey
(
c
->
db
->
dict
);
if
(
expireIfNeeded
(
c
->
db
,
dictGetEntryKey
(
de
))
==
0
)
break
;
if
(
!
de
||
expireIfNeeded
(
c
->
db
,
dictGetEntryKey
(
de
))
==
0
)
break
;
}
if
(
de
==
NULL
)
{
addReply
(
c
,
shared
.
plus
);
addReply
(
c
,
shared
.
crlf
);
}
else
{
addReply
(
c
,
shared
.
plus
);
...
...
test-redis.tcl
View file @
ce7bef07
...
...
@@ -588,6 +588,29 @@ proc main {server port} {
$r mget foo baazz bar myset
}
{
BAR
{}
FOO
{}}
test
{
RANDOMKEY
}
{
$r flushall
$r set foo x
$r set bar y
set foo_seen 0
set bar_seen 0
for
{
set i 0
}
{
$i
< 100
}
{
incr i
}
{
set rkey
[
$r
randomkey
]
if
{
$rkey
eq
{
foo
}}
{
set foo_seen 1
}
if
{
$rkey
eq
{
bar
}}
{
set bar_seen 1
}
}
list $foo_seen $bar_seen
}
{
1 1
}
test
{
RANDOMKEY against empty DB
}
{
$r flushall
$r randomkey
}
{}
# Leave the user with a clean DB before to exit
test
{
FLUSHALL
}
{
$r flushall
...
...
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