Skip to content

Commit 5877c02

Browse files
committed
Fix PERSIST expired key resuscitation issue redis#4048.
1 parent e91b81c commit 5877c02

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/db.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ robj *lookupKeyReadWithFlags(redisDb *db, robj *key, int flags) {
9393

9494
if (expireIfNeeded(db,key) == 1) {
9595
/* Key expired. If we are in the context of a master, expireIfNeeded()
96-
* returns 0 only when the key does not exist at all, so it's save
96+
* returns 0 only when the key does not exist at all, so it's safe
9797
* to return NULL ASAP. */
9898
if (server.masterhost == NULL) return NULL;
9999

src/expire.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -477,18 +477,15 @@ void pttlCommand(client *c) {
477477

478478
/* PERSIST key */
479479
void persistCommand(client *c) {
480-
dictEntry *de;
481-
482-
de = dictFind(c->db->dict,c->argv[1]->ptr);
483-
if (de == NULL) {
484-
addReply(c,shared.czero);
485-
} else {
480+
if (lookupKeyWrite(c->db,c->argv[1])) {
486481
if (removeExpire(c->db,c->argv[1])) {
487482
addReply(c,shared.cone);
488483
server.dirty++;
489484
} else {
490485
addReply(c,shared.czero);
491486
}
487+
} else {
488+
addReply(c,shared.czero);
492489
}
493490
}
494491

0 commit comments

Comments
 (0)