From fa0623a9b5fb6c36f3dd87356c811af0b2445df8 Mon Sep 17 00:00:00 2001 From: Talkabout Date: Sun, 29 Mar 2020 23:53:01 +0200 Subject: [PATCH] honor 'server_expired_ttl' in redis --- cachedb/redis.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cachedb/redis.c b/cachedb/redis.c index fdc6716eb..db4b8f2c3 100644 --- a/cachedb/redis.c +++ b/cachedb/redis.c @@ -47,6 +47,7 @@ #include "util/alloc.h" #include "util/config_file.h" #include "sldns/sbuffer.h" +#include #ifdef USE_REDIS #include "hiredis/hiredis.h" @@ -254,8 +255,13 @@ redis_store(struct module_env* env, struct cachedb_env* cachedb_env, redisReply* rep; int n; int size; + bool set_ttl = !env->cfg->serve_expired || env->cfg->serve_expired_ttl > 0; - if (env->cfg->serve_expired) { + if (env->cfg->serve_expired_ttl > 0) { + ttl += env->cfg->serve_expired_ttl; + } + + if (!set_ttl) { size = 4+(CACHEDB_HASHSIZE/8)*2+3+1; } else { @@ -264,10 +270,10 @@ redis_store(struct module_env* env, struct cachedb_env* cachedb_env, char cmdbuf[size]; /* "SET " + key + " %b EX " + ttl */ - if (env->cfg->serve_expired) { + if (!set_ttl) { verbose(VERB_ALGO, "redis_store %s (%d bytes)", key, (int)data_len); /* build command to set to a binary safe string */ - n = snprintf(cmdbuf, sizeof(cmdbuf), "SET %s %%b EX %d", key, ttl); + n = snprintf(cmdbuf, sizeof(cmdbuf), "SET %s %%b", key); } else { verbose(VERB_ALGO, "redis_store %s (%d bytes) with ttl %d", key, (int)data_len, ttl); -- 2.47.3