From 83390f55e5b78a1618a81528993bdb7a0c259980 Mon Sep 17 00:00:00 2001 From: antirez Date: Tue, 27 Feb 2018 16:44:39 +0100 Subject: [PATCH] expireIfNeeded() needed a top comment documenting the behavior. --- src/db.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/db.c b/src/db.c index e98a9fae3..21840d0c9 100644 --- a/src/db.c +++ b/src/db.c @@ -1094,6 +1094,25 @@ void propagateExpire(redisDb *db, robj *key, int lazy) { decrRefCount(argv[1]); } +/* 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 + * it still exists in the database. The main way this function is called + * is via lookupKey*() family of functions. + * + * The behavior of the function depends on the replication role of the + * instance, because slave instances do not expire keys, they wait + * for DELs from the master for consistency matters. However even + * slaves will try to have a coherent return value for the function, + * so that read commands executed in the slave side will be able to + * behave like if the key is expired even if still present (because the + * master has yet to propagate the DEL). + * + * In masters as a side effect of finding a key which is expired, such + * key will be evicted from the database. Also this may trigger the + * propagation of a DEL/UNLINK command in AOF / replication stream. + * + * The return value of the function is 0 if the key is still valid, + * otherwise the function returns 1 if the key is expired. */ int expireIfNeeded(redisDb *db, robj *key) { mstime_t when = getExpire(db,key); mstime_t now;