Skip to content

Commit 1d7bf20

Browse files
soloestoyantirez
authored andcommitted
AOF: append origin SET if no expire option
1 parent 676445a commit 1d7bf20

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/aof.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -611,19 +611,24 @@ void feedAppendOnlyFile(struct redisCommand *cmd, int dictid, robj **argv, int a
611611
} else if (cmd->proc == setCommand && argc > 3) {
612612
int i;
613613
robj *exarg = NULL, *pxarg = NULL;
614-
/* Translate SET [EX seconds][PX milliseconds] to SET and PEXPIREAT */
615-
buf = catAppendOnlyGenericCommand(buf,3,argv);
616614
for (i = 3; i < argc; i ++) {
617615
if (!strcasecmp(argv[i]->ptr, "ex")) exarg = argv[i+1];
618616
if (!strcasecmp(argv[i]->ptr, "px")) pxarg = argv[i+1];
619617
}
620618
serverAssert(!(exarg && pxarg));
621-
if (exarg)
622-
buf = catAppendOnlyExpireAtCommand(buf,server.expireCommand,argv[1],
623-
exarg);
624-
if (pxarg)
625-
buf = catAppendOnlyExpireAtCommand(buf,server.pexpireCommand,argv[1],
626-
pxarg);
619+
620+
if (exarg || pxarg) {
621+
/* Translate SET [EX seconds][PX milliseconds] to SET and PEXPIREAT */
622+
buf = catAppendOnlyGenericCommand(buf,3,argv);
623+
if (exarg)
624+
buf = catAppendOnlyExpireAtCommand(buf,server.expireCommand,argv[1],
625+
exarg);
626+
if (pxarg)
627+
buf = catAppendOnlyExpireAtCommand(buf,server.pexpireCommand,argv[1],
628+
pxarg);
629+
} else {
630+
buf = catAppendOnlyGenericCommand(buf,argc,argv);
631+
}
627632
} else {
628633
/* All the other commands don't need translation or need the
629634
* same translation already operated in the command vector

tests/unit/expire.tcl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,14 @@ start_server {tags {"expire"}} {
232232
set ttl [r ttl foo]
233233
assert {$ttl <= 100 && $ttl > 90}
234234
}
235+
236+
test {SET - use KEEPTTL option, TTL should not be removed after loadaof} {
237+
r config set appendonly yes
238+
r set foo bar EX 100
239+
r set foo bar2 KEEPTTL
240+
after 2000
241+
r debug loadaof
242+
set ttl [r ttl foo]
243+
assert {$ttl <= 98 && $ttl > 90}
244+
}
235245
}

0 commit comments

Comments
 (0)