Skip to content

Commit

Permalink
ndb_redis: add flush_db_on_reconnect parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudiu Boriga committed May 9, 2017
1 parent 358cf95 commit c886a9b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/modules/ndb_redis/doc/ndb_redis_admin.xml
Expand Up @@ -235,6 +235,38 @@ modparam("ndb_redis", "allowed_timeouts", 3)
...
modparam("ndb_redis", "allowed_timeouts", 0)
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>
Expand Down
2 changes: 2 additions & 0 deletions src/modules/ndb_redis/ndb_redis_mod.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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}
};

Expand Down
5 changes: 4 additions & 1 deletion src/modules/ndb_redis/redis_client.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit c886a9b

Please sign in to comment.