From a72177e73c50e47d0dcc6eb5c53fd14d1957082d Mon Sep 17 00:00:00 2001 From: Yorgos Thessalonikefs Date: Mon, 8 Sep 2025 14:49:12 +0200 Subject: [PATCH] - Update documentation for using "SET ... EX" in Redis. - Document max buffer sizes for Redis commands. --- cachedb/redis.c | 19 ++++++++++++++++--- doc/Changelog | 4 ++++ doc/unbound.conf.rst | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/cachedb/redis.c b/cachedb/redis.c index 80e24c78f..9383f1c85 100644 --- a/cachedb/redis.c +++ b/cachedb/redis.c @@ -392,7 +392,7 @@ redis_init(struct module_env* env, struct cachedb_env* cachedb_env) set_with_ex_fail: log_err("redis_init: failure during redis_init, the " "redis-expire-records option requires the SET with EX command " - "(redis >= 2.6.2)"); + "(redis >= 2.6.12)"); return 1; fail: moddata_clean(&moddata); @@ -508,7 +508,14 @@ redis_lookup(struct module_env* env, struct cachedb_env* cachedb_env, char* key, struct sldns_buffer* result_buffer) { redisReply* rep; - char cmdbuf[4+(CACHEDB_HASHSIZE/8)*2+1]; /* "GET " + key */ + /* Supported commands: + * - "GET " + key + */ +#define REDIS_LOOKUP_MAX_BUF_LEN \ + 4 /* "GET " */ \ + +(CACHEDB_HASHSIZE/8)*2 /* key hash */ \ + + 1 /* \0 */ + char cmdbuf[REDIS_LOOKUP_MAX_BUF_LEN]; int n; int ret = 0; @@ -568,7 +575,13 @@ redis_store(struct module_env* env, struct cachedb_env* cachedb_env, * older redis 2.0.0 was "SETEX " + key + " " + ttl + " %b" * - "EXPIRE " + key + " 0" */ - char cmdbuf[6+(CACHEDB_HASHSIZE/8)*2+11+3+1]; +#define REDIS_STORE_MAX_BUF_LEN \ + 7 /* "EXPIRE " */ \ + +(CACHEDB_HASHSIZE/8)*2 /* key hash */ \ + + 7 /* " %b EX " */ \ + + 20 /* ttl (uint64_t) */ \ + + 1 /* \0 */ + char cmdbuf[REDIS_STORE_MAX_BUF_LEN]; if (!set_ttl) { verbose(VERB_ALGO, "redis_store %s (%d bytes)", key, (int)data_len); diff --git a/doc/Changelog b/doc/Changelog index fd955ba89..ff995b16d 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,7 @@ +8 September 2025: Yorgos + - Update documentation for using "SET ... EX" in Redis. + - Document max buffer sizes for Redis commands. + 3 September 2025: Wouter - For #1328: make depend. diff --git a/doc/unbound.conf.rst b/doc/unbound.conf.rst index c6cc91387..ad8404e11 100644 --- a/doc/unbound.conf.rst +++ b/doc/unbound.conf.rst @@ -4495,7 +4495,7 @@ The following **cachedb:** options are specific to the ``redis`` backend. internally reverted to "no". .. note:: - Redis SETEX support is required for this option (Redis >= 2.0.0). + Redis "SET ... EX" support is required for this option (Redis >= 2.6.12). Default: no -- 2.47.3