From c886a9b0578a190f23a1084317cfecc3238a0007 Mon Sep 17 00:00:00 2001 From: Claudiu Boriga Date: Tue, 9 May 2017 15:02:45 +0300 Subject: [PATCH] ndb_redis: add flush_db_on_reconnect parameter --- src/modules/ndb_redis/doc/ndb_redis_admin.xml | 32 +++++++++++++++++++ src/modules/ndb_redis/ndb_redis_mod.c | 2 ++ src/modules/ndb_redis/redis_client.c | 5 ++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/modules/ndb_redis/doc/ndb_redis_admin.xml b/src/modules/ndb_redis/doc/ndb_redis_admin.xml index e7dc381038d..e72fb514fcb 100644 --- a/src/modules/ndb_redis/doc/ndb_redis_admin.xml +++ b/src/modules/ndb_redis/doc/ndb_redis_admin.xml @@ -235,6 +235,38 @@ modparam("ndb_redis", "allowed_timeouts", 3) ... modparam("ndb_redis", "allowed_timeouts", 0) modparam("ndb_redis", "disable_time", 30) +... + + + +
+ <varname>flush_db_on_reconnect</varname> (integer) + + If this is set to a non zero value, a "FLUSHALL" command is + issued after reconnecting to a REDIS server, to clear the + entire database. + + + When a command to a REDIS server fails, a reconnection + to that server is made, so with this parameter each failed + command will result in a flush of the database. + + + This is useful in scenarios when a REDIS server does not respond + to commands, but the commands might have been issued, and the + responses lost. If this leaves the data in the db in an uncertain + state, a flush might fix any issues that may occur. + + + + Default value is 0 (disabled). + + + + Set <varname>flush_db_on_reconnect</varname> parameter + +... +modparam("ndb_redis", "flush_db_on_reconnect", 1) ... diff --git a/src/modules/ndb_redis/ndb_redis_mod.c b/src/modules/ndb_redis/ndb_redis_mod.c index 6e4384937d2..2cac1fbbc37 100644 --- a/src/modules/ndb_redis/ndb_redis_mod.c +++ b/src/modules/ndb_redis/ndb_redis_mod.c @@ -50,6 +50,7 @@ int redis_cmd_timeout_param = 1000; int redis_cluster_param = 0; int redis_disable_time_param=0; int redis_allowed_timeouts_param=-1; +int redis_flush_db_on_reconnect_param=0; static int w_redis_cmd3(struct sip_msg* msg, char* ssrv, char* scmd, char* sres); @@ -124,6 +125,7 @@ static param_export_t params[]={ {"cluster", INT_PARAM, &redis_cluster_param}, {"disable_time", INT_PARAM, &redis_disable_time_param}, {"allowed_timeouts", INT_PARAM, &redis_allowed_timeouts_param}, + {"flush_db_on_reconnect", INT_PARAM, &redis_flush_db_on_reconnect_param}, {0, 0, 0} }; diff --git a/src/modules/ndb_redis/redis_client.c b/src/modules/ndb_redis/redis_client.c index 9fb7791162a..4683133e674 100644 --- a/src/modules/ndb_redis/redis_client.c +++ b/src/modules/ndb_redis/redis_client.c @@ -51,6 +51,7 @@ extern int redis_cmd_timeout_param; extern int redis_cluster_param; extern int redis_disable_time_param; extern int redis_allowed_timeouts_param; +extern int redis_flush_db_on_reconnect_param; /* backwards compatibility with hiredis < 0.12 */ #if (HIREDIS_MAJOR == 0) && (HIREDIS_MINOR < 12) @@ -374,7 +375,9 @@ int redisc_reconnect_server(redisc_server_t *rsrv) goto err2; if ((redis_cluster_param == 0) && redisCommandNR(rsrv->ctxRedis, "SELECT %i", db)) goto err2; - + if (redis_flush_db_on_reconnect_param) + if (redisCommandNR(rsrv->ctxRedis, "FLUSHALL")) + goto err2; return 0; err2: