mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 00:28:26 -05:00
do not delete expired keys in KEYS command
This commit is contained in:
parent
3f7bc5a5d2
commit
7ab9cba59b
61
src/db.c
61
src/db.c
@ -38,6 +38,8 @@
|
|||||||
* C-level DB API
|
* C-level DB API
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int keyIsExpired(redisDb *db, robj *key);
|
||||||
|
|
||||||
/* Update LFU when an object is accessed.
|
/* Update LFU when an object is accessed.
|
||||||
* Firstly, decrement the counter if the decrement time is reached.
|
* Firstly, decrement the counter if the decrement time is reached.
|
||||||
* Then logarithmically increment the counter, and update the access time. */
|
* Then logarithmically increment the counter, and update the access time. */
|
||||||
@ -543,7 +545,7 @@ void keysCommand(client *c) {
|
|||||||
|
|
||||||
if (allkeys || stringmatchlen(pattern,plen,key,sdslen(key),0)) {
|
if (allkeys || stringmatchlen(pattern,plen,key,sdslen(key),0)) {
|
||||||
keyobj = createStringObject(key,sdslen(key));
|
keyobj = createStringObject(key,sdslen(key));
|
||||||
if (expireIfNeeded(c->db,keyobj) == 0) {
|
if (!keyIsExpired(c->db,keyobj)) {
|
||||||
addReplyBulk(c,keyobj);
|
addReplyBulk(c,keyobj);
|
||||||
numkeys++;
|
numkeys++;
|
||||||
}
|
}
|
||||||
@ -1120,6 +1122,25 @@ void propagateExpire(redisDb *db, robj *key, int lazy) {
|
|||||||
decrRefCount(argv[1]);
|
decrRefCount(argv[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check if the key is expired. */
|
||||||
|
int keyIsExpired(redisDb *db, robj *key) {
|
||||||
|
mstime_t when = getExpire(db,key);
|
||||||
|
|
||||||
|
if (when < 0) return 0; /* No expire for this key */
|
||||||
|
|
||||||
|
/* Don't expire anything while loading. It will be done later. */
|
||||||
|
if (server.loading) return 0;
|
||||||
|
|
||||||
|
/* If we are in the context of a Lua script, we pretend that time is
|
||||||
|
* blocked to when the Lua script started. This way a key can expire
|
||||||
|
* only the first time it is accessed and not in the middle of the
|
||||||
|
* script execution, making propagation to slaves / AOF consistent.
|
||||||
|
* See issue #1525 on Github for more information. */
|
||||||
|
mstime_t now = server.lua_caller ? server.lua_time_start : mstime();
|
||||||
|
|
||||||
|
return now > when;
|
||||||
|
}
|
||||||
|
|
||||||
/* This function is called when we are going to perform some operation
|
/* This function is called when we are going to perform some operation
|
||||||
* in a given key, but such key may be already logically expired even if
|
* in a given key, but such key may be already logically expired even if
|
||||||
* it still exists in the database. The main way this function is called
|
* it still exists in the database. The main way this function is called
|
||||||
@ -1140,32 +1161,18 @@ void propagateExpire(redisDb *db, robj *key, int lazy) {
|
|||||||
* The return value of the function is 0 if the key is still valid,
|
* The return value of the function is 0 if the key is still valid,
|
||||||
* otherwise the function returns 1 if the key is expired. */
|
* otherwise the function returns 1 if the key is expired. */
|
||||||
int expireIfNeeded(redisDb *db, robj *key) {
|
int expireIfNeeded(redisDb *db, robj *key) {
|
||||||
mstime_t when = getExpire(db,key);
|
if (!keyIsExpired(db,key)) {
|
||||||
mstime_t now;
|
return 0;
|
||||||
|
} else if (server.masterhost != NULL) {
|
||||||
if (when < 0) return 0; /* No expire for this key */
|
/* If we are running in the context of a slave, return ASAP:
|
||||||
|
* the slave key expiration is controlled by the master that will
|
||||||
/* Don't expire anything while loading. It will be done later. */
|
* send us synthesized DEL operations for expired keys.
|
||||||
if (server.loading) return 0;
|
*
|
||||||
|
* Still we try to return the right information to the caller,
|
||||||
/* If we are in the context of a Lua script, we pretend that time is
|
* that is, 0 if we think the key should be still valid, 1 if
|
||||||
* blocked to when the Lua script started. This way a key can expire
|
* we think the key is expired at this time. */
|
||||||
* only the first time it is accessed and not in the middle of the
|
return 1;
|
||||||
* script execution, making propagation to slaves / AOF consistent.
|
}
|
||||||
* See issue #1525 on Github for more information. */
|
|
||||||
now = server.lua_caller ? server.lua_time_start : mstime();
|
|
||||||
|
|
||||||
/* If we are running in the context of a slave, return ASAP:
|
|
||||||
* the slave key expiration is controlled by the master that will
|
|
||||||
* send us synthesized DEL operations for expired keys.
|
|
||||||
*
|
|
||||||
* Still we try to return the right information to the caller,
|
|
||||||
* that is, 0 if we think the key should be still valid, 1 if
|
|
||||||
* we think the key is expired at this time. */
|
|
||||||
if (server.masterhost != NULL) return now > when;
|
|
||||||
|
|
||||||
/* Return when this key has not expired */
|
|
||||||
if (now <= when) return 0;
|
|
||||||
|
|
||||||
/* Delete the key */
|
/* Delete the key */
|
||||||
server.stat_expiredkeys++;
|
server.stat_expiredkeys++;
|
||||||
|
Loading…
Reference in New Issue
Block a user