Skip to content

Commit 6476f1a

Browse files
authored
Merge pull request redis#4068 from FreedomU007/unstable
Fix set with ex/px option when propagated to aof
2 parents ef446bf + 86e9f48 commit 6476f1a

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

src/aof.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,23 @@ void feedAppendOnlyFile(struct redisCommand *cmd, int dictid, robj **argv, int a
536536
buf = catAppendOnlyGenericCommand(buf,3,tmpargv);
537537
decrRefCount(tmpargv[0]);
538538
buf = catAppendOnlyExpireAtCommand(buf,cmd,argv[1],argv[2]);
539+
} else if (cmd->proc == setCommand && argc > 3) {
540+
int i;
541+
robj *exarg = NULL, *pxarg = NULL;
542+
/* Translate SET [EX seconds][PX milliseconds] to SET and PEXPIREAT */
543+
buf = catAppendOnlyGenericCommand(buf,3,argv);
544+
for (i = 3; i < argc; i ++) {
545+
if (!strcasecmp(argv[i]->ptr, "ex"))
546+
exarg = argv[i+1];
547+
548+
if (!strcasecmp(argv[i]->ptr, "px"))
549+
pxarg = argv[i+1];
550+
}
551+
serverAssert(!(exarg && pxarg));
552+
if (exarg)
553+
buf = catAppendOnlyExpireAtCommand(buf,server.expireCommand,argv[1],exarg);
554+
if (pxarg)
555+
buf = catAppendOnlyExpireAtCommand(buf,server.pexpireCommand,argv[1],pxarg);
539556
} else {
540557
/* All the other commands don't need translation or need the
541558
* same translation already operated in the command vector

src/server.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,8 @@ void initServerConfig(void) {
15001500
server.rpopCommand = lookupCommandByCString("rpop");
15011501
server.sremCommand = lookupCommandByCString("srem");
15021502
server.execCommand = lookupCommandByCString("exec");
1503+
server.expireCommand = lookupCommandByCString("expire");
1504+
server.pexpireCommand = lookupCommandByCString("pexpire");
15031505

15041506
/* Slow log */
15051507
server.slowlog_log_slower_than = CONFIG_DEFAULT_SLOWLOG_LOG_SLOWER_THAN;

src/server.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,8 @@ struct redisServer {
909909
off_t loading_process_events_interval_bytes;
910910
/* Fast pointers to often looked up command */
911911
struct redisCommand *delCommand, *multiCommand, *lpushCommand, *lpopCommand,
912-
*rpopCommand, *sremCommand, *execCommand;
912+
*rpopCommand, *sremCommand, *execCommand, *expireCommand,
913+
*pexpireCommand;
913914
/* Fields used only for stats */
914915
time_t stat_starttime; /* Server start time */
915916
long long stat_numcommands; /* Number of processed commands */

tests/unit/expire.tcl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,19 @@ start_server {tags {"expire"}} {
204204
catch {r expire foo ""} e
205205
set e
206206
} {*not an integer*}
207+
208+
test {SET - use EX/PX option, TTL should not be reseted after loadaof} {
209+
r config set appendonly yes
210+
r set foo bar EX 100
211+
after 2000
212+
r debug loadaof
213+
set ttl [r ttl foo]
214+
assert {$ttl <= 98 && $ttl > 90}
215+
216+
r set foo bar PX 100000
217+
after 2000
218+
r debug loadaof
219+
set ttl [r ttl foo]
220+
assert {$ttl <= 98 && $ttl > 90}
221+
}
207222
}

0 commit comments

Comments
 (0)