summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSalvatore Sanfilippo <antirez@gmail.com>2020-06-08 11:02:00 +0200
committerGitHub <noreply@github.com>2020-06-08 11:02:00 +0200
commit265a7e7ec7d6b632a3efae3b6d1f1349ca790633 (patch)
tree4e18dfde93fc02baea40490f80ea2f30405eeaa3
parentcfffda83fbad7d0428670512e56818e742306049 (diff)
parent5d0774d62f4904db0ea0593c773a280ddc718d83 (diff)
downloadredis-265a7e7ec7d6b632a3efae3b6d1f1349ca790633.tar.gz
Merge pull request #7357 from soloestoy/bugfix-aof-keepttl
AOF: append origin SET if no expire option
-rw-r--r--src/aof.c21
-rw-r--r--tests/unit/expire.tcl10
2 files changed, 23 insertions, 8 deletions
diff --git a/src/aof.c b/src/aof.c
index 02409abe6..6f8e53712 100644
--- a/src/aof.c
+++ b/src/aof.c
@@ -611,19 +611,24 @@ void feedAppendOnlyFile(struct redisCommand *cmd, int dictid, robj **argv, int a
} else if (cmd->proc == setCommand && argc > 3) {
int i;
robj *exarg = NULL, *pxarg = NULL;
- /* Translate SET [EX seconds][PX milliseconds] to SET and PEXPIREAT */
- buf = catAppendOnlyGenericCommand(buf,3,argv);
for (i = 3; i < argc; i ++) {
if (!strcasecmp(argv[i]->ptr, "ex")) exarg = argv[i+1];
if (!strcasecmp(argv[i]->ptr, "px")) pxarg = argv[i+1];
}
serverAssert(!(exarg && pxarg));
- if (exarg)
- buf = catAppendOnlyExpireAtCommand(buf,server.expireCommand,argv[1],
- exarg);
- if (pxarg)
- buf = catAppendOnlyExpireAtCommand(buf,server.pexpireCommand,argv[1],
- pxarg);
+
+ if (exarg || pxarg) {
+ /* Translate SET [EX seconds][PX milliseconds] to SET and PEXPIREAT */
+ buf = catAppendOnlyGenericCommand(buf,3,argv);
+ if (exarg)
+ buf = catAppendOnlyExpireAtCommand(buf,server.expireCommand,argv[1],
+ exarg);
+ if (pxarg)
+ buf = catAppendOnlyExpireAtCommand(buf,server.pexpireCommand,argv[1],
+ pxarg);
+ } else {
+ buf = catAppendOnlyGenericCommand(buf,argc,argv);
+ }
} else {
/* All the other commands don't need translation or need the
* same translation already operated in the command vector
diff --git a/tests/unit/expire.tcl b/tests/unit/expire.tcl
index 11fb82ef0..52d174d75 100644
--- a/tests/unit/expire.tcl
+++ b/tests/unit/expire.tcl
@@ -232,4 +232,14 @@ start_server {tags {"expire"}} {
set ttl [r ttl foo]
assert {$ttl <= 100 && $ttl > 90}
}
+
+ test {SET - use KEEPTTL option, TTL should not be removed after loadaof} {
+ r config set appendonly yes
+ r set foo bar EX 100
+ r set foo bar2 KEEPTTL
+ after 2000
+ r debug loadaof
+ set ttl [r ttl foo]
+ assert {$ttl <= 98 && $ttl > 90}
+ }
}