Implement the EXPIREMEMBERAT command
Former-commit-id: 203e341bf4427723903d8d3de03af2f0ef043a3f
This commit is contained in:
parent
650085d61a
commit
ac243ae4bf
@ -139,22 +139,8 @@ int parseUnitString(const char *sz)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void expireMemberCommand(client *c)
|
void expireMemberCore(client *c, robj *key, robj *subkey, long long basetime, long long when, int unit)
|
||||||
{
|
{
|
||||||
long long when;
|
|
||||||
if (getLongLongFromObjectOrReply(c, c->argv[3], &when, NULL) != C_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (c->argc > 5) {
|
|
||||||
addReplyError(c, "Invalid number of arguments");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int unit = UNIT_SECONDS;
|
|
||||||
if (c->argc == 5) {
|
|
||||||
unit = parseUnitString(szFromObj(c->argv[4]));
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (unit)
|
switch (unit)
|
||||||
{
|
{
|
||||||
case UNIT_SECONDS:
|
case UNIT_SECONDS:
|
||||||
@ -167,7 +153,7 @@ void expireMemberCommand(client *c)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
when += mstime();
|
when += basetime;
|
||||||
|
|
||||||
/* No key, return zero. */
|
/* No key, return zero. */
|
||||||
dictEntry *de = dictFind(c->db->pdict, szFromObj(c->argv[1]));
|
dictEntry *de = dictFind(c->db->pdict, szFromObj(c->argv[1]));
|
||||||
@ -194,6 +180,35 @@ void expireMemberCommand(client *c)
|
|||||||
addReply(c, shared.ok);
|
addReply(c, shared.ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void expireMemberCommand(client *c)
|
||||||
|
{
|
||||||
|
long long when;
|
||||||
|
if (getLongLongFromObjectOrReply(c, c->argv[3], &when, NULL) != C_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (c->argc > 5) {
|
||||||
|
addReplyError(c, "Invalid number of arguments");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int unit = UNIT_SECONDS;
|
||||||
|
if (c->argc == 5) {
|
||||||
|
unit = parseUnitString(szFromObj(c->argv[4]));
|
||||||
|
}
|
||||||
|
|
||||||
|
expireMemberCore(c, c->argv[1], c->argv[2], mstime(), when, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
void expireMemberAtCommand(client *c)
|
||||||
|
{
|
||||||
|
long long when;
|
||||||
|
if (getLongLongFromObjectOrReply(c, c->argv[3], &when, NULL) != C_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
expireMemberCore(c, c->argv[1], c->argv[2], 0, when, UNIT_SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Try to expire a few timed out keys. The algorithm used is adaptive and
|
/* Try to expire a few timed out keys. The algorithm used is adaptive and
|
||||||
* will use few CPU cycles if there are few expiring keys, otherwise
|
* will use few CPU cycles if there are few expiring keys, otherwise
|
||||||
* it will get more aggressive to avoid that too much memory is used by
|
* it will get more aggressive to avoid that too much memory is used by
|
||||||
|
@ -346,6 +346,9 @@ struct commandHelp {
|
|||||||
{ "EXPIREMEMBER",
|
{ "EXPIREMEMBER",
|
||||||
"key subkey delay [Unit: s,ms]",
|
"key subkey delay [Unit: s,ms]",
|
||||||
"set a subkey's time to live in seconds (or milliseconds)"},
|
"set a subkey's time to live in seconds (or milliseconds)"},
|
||||||
|
{ "EXPIREMEMBERAT",
|
||||||
|
"key subkey timestamp",
|
||||||
|
"Set the expiration for a subkey as a UNIX timestamp"},
|
||||||
{ "FLUSHALL",
|
{ "FLUSHALL",
|
||||||
"[ASYNC]",
|
"[ASYNC]",
|
||||||
"Remove all keys from all databases",
|
"Remove all keys from all databases",
|
||||||
|
@ -626,6 +626,10 @@ struct redisCommand redisCommandTable[] = {
|
|||||||
{"expiremember", expireMemberCommand, -4,
|
{"expiremember", expireMemberCommand, -4,
|
||||||
"write fast @keyspace",
|
"write fast @keyspace",
|
||||||
0,NULL,1,1,1,0,0,0},
|
0,NULL,1,1,1,0,0,0},
|
||||||
|
|
||||||
|
{"expirememberat", expireMemberAtCommand, 4,
|
||||||
|
"write fast @keyspace",
|
||||||
|
0,NULL,1,1,1,0,0,0},
|
||||||
|
|
||||||
{"pexpire",pexpireCommand,3,
|
{"pexpire",pexpireCommand,3,
|
||||||
"write fast @keyspace",
|
"write fast @keyspace",
|
||||||
|
@ -2628,6 +2628,7 @@ void monitorCommand(client *c);
|
|||||||
void expireCommand(client *c);
|
void expireCommand(client *c);
|
||||||
void expireatCommand(client *c);
|
void expireatCommand(client *c);
|
||||||
void expireMemberCommand(client *c);
|
void expireMemberCommand(client *c);
|
||||||
|
void expireMemberAtCommand(client *c);
|
||||||
void pexpireCommand(client *c);
|
void pexpireCommand(client *c);
|
||||||
void pexpireatCommand(client *c);
|
void pexpireatCommand(client *c);
|
||||||
void getsetCommand(client *c);
|
void getsetCommand(client *c);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user