mirror of
https://github.com/fluencelabs/redis
synced 2025-06-12 08:41:21 +00:00
Enhance RESTORE with RDBv9 new features
RESTORE now supports: 1. Setting LRU/LFU 2. Absolute-time TTL Other related changes: 1. RDB loading will not override LRU bits when RDB file does not contain the LRU opcode. 2. RDB loading will not set LRU/LFU bits if the server's maxmemory-policy does not match.
This commit is contained in:
@ -4835,15 +4835,39 @@ void dumpCommand(client *c) {
|
||||
|
||||
/* RESTORE key ttl serialized-value [REPLACE] */
|
||||
void restoreCommand(client *c) {
|
||||
long long ttl;
|
||||
long long ttl, lfu_freq = -1, lru_idle = -1, lru_clock;
|
||||
rio payload;
|
||||
int j, type, replace = 0;
|
||||
int j, type, replace = 0, absttl = 0;
|
||||
robj *obj;
|
||||
|
||||
/* Parse additional options */
|
||||
for (j = 4; j < c->argc; j++) {
|
||||
int additional = c->argc-j-1;
|
||||
if (!strcasecmp(c->argv[j]->ptr,"replace")) {
|
||||
replace = 1;
|
||||
} else if (!strcasecmp(c->argv[j]->ptr,"absttl")) {
|
||||
absttl = 1;
|
||||
} else if (!strcasecmp(c->argv[j]->ptr,"idletime") && additional >= 1 &&
|
||||
lfu_freq == -1)
|
||||
{
|
||||
if (getLongLongFromObjectOrReply(c,c->argv[j+1],&lru_idle,NULL)
|
||||
!= C_OK) return;
|
||||
if (lru_idle < 0) {
|
||||
addReplyError(c,"Invalid IDLETIME value, must be >= 0");
|
||||
return;
|
||||
}
|
||||
lru_clock = LRU_CLOCK();
|
||||
j++; /* Consume additional arg. */
|
||||
} else if (!strcasecmp(c->argv[j]->ptr,"freq") && additional >= 1 &&
|
||||
lru_idle == -1)
|
||||
{
|
||||
if (getLongLongFromObjectOrReply(c,c->argv[j+1],&lfu_freq,NULL)
|
||||
!= C_OK) return;
|
||||
if (lfu_freq < 0 || lfu_freq > 255) {
|
||||
addReplyError(c,"Invalid FREQ value, must be >= 0 and <= 255");
|
||||
return;
|
||||
}
|
||||
j++; /* Consume additional arg. */
|
||||
} else {
|
||||
addReply(c,shared.syntaxerr);
|
||||
return;
|
||||
@ -4884,7 +4908,11 @@ void restoreCommand(client *c) {
|
||||
|
||||
/* Create the key and set the TTL if any */
|
||||
dbAdd(c->db,c->argv[1],obj);
|
||||
if (ttl) setExpire(c,c->db,c->argv[1],mstime()+ttl);
|
||||
if (ttl) {
|
||||
if (!absttl) ttl+=mstime();
|
||||
setExpire(c,c->db,c->argv[1],ttl);
|
||||
}
|
||||
objectSetLRUOrLFU(obj,lfu_freq,lru_idle,lru_clock);
|
||||
signalModifiedKey(c->db,c->argv[1]);
|
||||
addReply(c,shared.ok);
|
||||
server.dirty++;
|
||||
|
Reference in New Issue
Block a user