@@ -61,6 +61,7 @@ struct redis_moddata {
61
61
struct timeval command_timeout ; /* timeout for commands */
62
62
struct timeval connect_timeout ; /* timeout for connect */
63
63
int logical_db ; /* the redis logical database to use */
64
+ int setex_available ; /* if the SETEX command is supported */
64
65
};
65
66
66
67
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)
199
200
"SETEX __UNBOUND_REDIS_CHECK__ 1 none" , NULL , 0 );
200
201
if (!rep ) {
201
202
/** 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 ;
205
204
}
206
205
redis_reply_type = rep -> type ;
207
206
freeReplyObject (rep );
@@ -210,13 +209,17 @@ redis_init(struct module_env* env, struct cachedb_env* cachedb_env)
210
209
break ;
211
210
default :
212
211
/** 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 ;
216
213
}
214
+ moddata -> setex_available = 1 ;
217
215
}
218
216
return 1 ;
219
217
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 ;
220
223
fail :
221
224
moddata_clean (& moddata );
222
225
return 0 ;
@@ -347,7 +350,10 @@ redis_store(struct module_env* env, struct cachedb_env* cachedb_env,
347
350
{
348
351
redisReply * rep ;
349
352
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 &&
351
357
(!env -> cfg -> serve_expired || env -> cfg -> serve_expired_ttl > 0 ));
352
358
/* Supported commands:
353
359
* - "SET " + key + " %b"
0 commit comments