[sr-dev] git:master:c886a9b0: ndb_redis: add flush_db_on_reconnect parameter

Claudiu Boriga paul.boriga at 1and1.ro
Wed May 10 06:43:50 CEST 2017


Module: kamailio
Branch: master
Commit: c886a9b0578a190f23a1084317cfecc3238a0007
URL: https://github.com/kamailio/kamailio/commit/c886a9b0578a190f23a1084317cfecc3238a0007

Author: Claudiu Boriga <paul.boriga at 1and1.ro>
Committer: Claudiu Boriga <paul.boriga at 1and1.ro>
Date: 2017-05-09T15:02:45+03:00

ndb_redis: add flush_db_on_reconnect parameter

---

Modified: src/modules/ndb_redis/doc/ndb_redis_admin.xml
Modified: src/modules/ndb_redis/ndb_redis_mod.c
Modified: src/modules/ndb_redis/redis_client.c

---

Diff:  https://github.com/kamailio/kamailio/commit/c886a9b0578a190f23a1084317cfecc3238a0007.diff
Patch: https://github.com/kamailio/kamailio/commit/c886a9b0578a190f23a1084317cfecc3238a0007.patch

---

diff --git a/src/modules/ndb_redis/doc/ndb_redis_admin.xml b/src/modules/ndb_redis/doc/ndb_redis_admin.xml
index e7dc381..e72fb51 100644
--- a/src/modules/ndb_redis/doc/ndb_redis_admin.xml
+++ b/src/modules/ndb_redis/doc/ndb_redis_admin.xml
@@ -239,6 +239,38 @@ modparam("ndb_redis", "disable_time", 30)
 			</programlisting>
 		</example>
 	</section>
+	<section id="ndb_redis.p.flush_db_on_reconnect">
+		<title><varname>flush_db_on_reconnect</varname> (integer)</title>
+		<para>
+			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. 
+		</para>
+		<para>
+			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. 
+		</para>
+		<para>
+			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.
+		</para>
+		<para>
+		<emphasis>
+			Default value is <quote>0</quote> (disabled).
+		</emphasis>
+		</para>
+		<example>
+			<title>Set <varname>flush_db_on_reconnect</varname> parameter</title>
+			<programlisting format="linespecific">
+...
+modparam("ndb_redis", "flush_db_on_reconnect", 1)
+...
+			</programlisting>
+		</example>
+	</section>
 	</section>
 
 	<section>
diff --git a/src/modules/ndb_redis/ndb_redis_mod.c b/src/modules/ndb_redis/ndb_redis_mod.c
index 6e43849..2cac1fb 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 9fb7791..4683133 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:




More information about the sr-dev mailing list