Skip to content

Commit 36d8c6e

Browse files
committed
- Fix SETEX check during Redis (re)initialization.
1 parent 60fd77b commit 36d8c6e

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

cachedb/redis.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct redis_moddata {
6161
struct timeval command_timeout; /* timeout for commands */
6262
struct timeval connect_timeout; /* timeout for connect */
6363
int logical_db; /* the redis logical database to use */
64+
int setex_available; /* if the SETEX command is supported */
6465
};
6566

6667
static redisReply* redis_command(struct module_env*, struct cachedb_env*,
@@ -199,9 +200,7 @@ redis_init(struct module_env* env, struct cachedb_env* cachedb_env)
199200
"SETEX __UNBOUND_REDIS_CHECK__ 1 none", NULL, 0);
200201
if(!rep) {
201202
/** init failed, no response from redis server*/
202-
log_err("redis_init: failed to init redis, the "
203-
"redis-expire-records option requires the SETEX command "
204-
"(redis >= 2.0.0)");
203+
goto setex_fail;
205204
}
206205
redis_reply_type = rep->type;
207206
freeReplyObject(rep);
@@ -210,13 +209,17 @@ redis_init(struct module_env* env, struct cachedb_env* cachedb_env)
210209
break;
211210
default:
212211
/** init failed, setex command not supported */
213-
log_err("redis_init: failed to init redis, the "
214-
"redis-expire-records option requires the SETEX command "
215-
"(redis >= 2.0.0)");
212+
goto setex_fail;
216213
}
214+
moddata->setex_available = 1;
217215
}
218216
return 1;
219217

218+
setex_fail:
219+
log_err("redis_init: failure during redis_init, the "
220+
"redis-expire-records option requires the SETEX command "
221+
"(redis >= 2.0.0)");
222+
return 1;
220223
fail:
221224
moddata_clean(&moddata);
222225
return 0;
@@ -347,7 +350,10 @@ redis_store(struct module_env* env, struct cachedb_env* cachedb_env,
347350
{
348351
redisReply* rep;
349352
int n;
350-
int set_ttl = (env->cfg->redis_expire_records &&
353+
struct redis_moddata* moddata = (struct redis_moddata*)
354+
cachedb_env->backend_data;
355+
int set_ttl = (moddata->setex_available &&
356+
env->cfg->redis_expire_records &&
351357
(!env->cfg->serve_expired || env->cfg->serve_expired_ttl > 0));
352358
/* Supported commands:
353359
* - "SET " + key + " %b"

0 commit comments

Comments
 (0)