mirror of
http://github.com/valkey-io/valkey
synced 2024-11-22 18:54:58 +00:00
RANDOMKEY issue 26 fixed, generic test + regression added
This commit is contained in:
parent
05557f6de7
commit
ce7bef0795
3
redis.c
3
redis.c
@ -2237,9 +2237,10 @@ static void randomkeyCommand(redisClient *c) {
|
|||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
de = dictGetRandomKey(c->db->dict);
|
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) {
|
if (de == NULL) {
|
||||||
|
addReply(c,shared.plus);
|
||||||
addReply(c,shared.crlf);
|
addReply(c,shared.crlf);
|
||||||
} else {
|
} else {
|
||||||
addReply(c,shared.plus);
|
addReply(c,shared.plus);
|
||||||
|
@ -588,6 +588,29 @@ proc main {server port} {
|
|||||||
$r mget foo baazz bar myset
|
$r mget foo baazz bar myset
|
||||||
} {BAR {} FOO {}}
|
} {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
|
# Leave the user with a clean DB before to exit
|
||||||
test {FLUSHALL} {
|
test {FLUSHALL} {
|
||||||
$r flushall
|
$r flushall
|
||||||
|
Loading…
Reference in New Issue
Block a user