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
c41183e4
Commit
c41183e4
authored
Feb 28, 2023
by
Vitaly Arbuzov
Browse files
Fix RANDOMKEY bug
parent
f3e96854
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/db.c
View file @
c41183e4
...
@@ -363,19 +363,19 @@ void setKey(client *c, redisDb *db, robj *key, robj *val, int flags) {
...
@@ -363,19 +363,19 @@ void setKey(client *c, redisDb *db, robj *key, robj *val, int flags) {
robj
*
dbRandomKey
(
redisDb
*
db
)
{
robj
*
dbRandomKey
(
redisDb
*
db
)
{
dictEntry
*
de
;
dictEntry
*
de
;
int
maxtries
=
100
;
int
maxtries
=
100
;
dict
*
randomDict
=
getRandomDict
(
db
);
int
allvolatile
=
dbSize
(
db
)
==
dictSize
(
db
->
expires
);
while
(
1
)
{
while
(
1
)
{
sds
key
;
sds
key
;
robj
*
keyobj
;
robj
*
keyobj
;
dict
*
randomDict
=
getRandomDict
(
db
);
de
=
dictGetFairRandomKey
(
randomDict
);
de
=
dictGetFairRandomKey
(
randomDict
);
if
(
de
==
NULL
)
return
NULL
;
// TODO consider other non-empty slot buckets.
if
(
de
==
NULL
)
return
NULL
;
// TODO consider other non-empty slot buckets.
key
=
dictGetKey
(
de
);
key
=
dictGetKey
(
de
);
keyobj
=
createStringObject
(
key
,
sdslen
(
key
));
keyobj
=
createStringObject
(
key
,
sdslen
(
key
));
if
(
dictFind
(
db
->
expires
,
key
))
{
if
(
dictFind
(
db
->
expires
,
key
))
{
if
(
server
.
masterhost
&&
--
maxtries
==
0
)
{
if
(
allvolatile
&&
server
.
masterhost
&&
--
maxtries
==
0
)
{
/* If the DB is composed only of keys with an expire set,
/* If the DB is composed only of keys with an expire set,
* it could happen that all the keys are already logically
* it could happen that all the keys are already logically
* expired in the slave, so the function cannot stop because
* expired in the slave, so the function cannot stop because
...
...
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