Browse Source

Merge pull request #121 from giavac/master

Optionally init ndb_redis when redis is not available
vhernando 10 years ago
parent
commit
398f2c12d9

+ 22 - 6
modules/ndb_redis/README

@@ -32,6 +32,7 @@ Vicente Hernando
         3. Parameters
 
               3.1. server (str)
+              3.2. init_without_redis (integer)
 
         4. Functions
 
@@ -41,8 +42,9 @@ Vicente Hernando
    List of Examples
 
    1.1. Set server parameter
-   1.2. redis_cmd usage
-   1.3. redis_free usage
+   1.2. Set init_without_redis parameter
+   1.3. redis_cmd usage
+   1.4. redis_free usage
 
 Chapter 1. Admin Guide
 
@@ -57,6 +59,7 @@ Chapter 1. Admin Guide
    3. Parameters
 
         3.1. server (str)
+        3.2. init_without_redis (integer)
 
    4. Functions
 
@@ -91,6 +94,7 @@ Chapter 1. Admin Guide
 3. Parameters
 
    3.1. server (str)
+   3.2. init_without_redis (integer)
 
 3.1. server (str)
 
@@ -113,13 +117,25 @@ Chapter 1. Admin Guide
    Example 1.1. Set server parameter
 ...
 modparam("ndb_redis", "server", "name=srvN;addr=127.0.0.1;port=6379;db=1")
-modparam("ndb_redis", "server", "name=srvX;addr=127.0.0.2;port=6379;db=4;pass=my
-password")
+modparam("ndb_redis", "server", "name=srvX;addr=127.0.0.2;port=6379;db=4;pass=m
+ypassword")
 
 # Unix domain socket
 modparam("ndb_redis", "server", "name=srvY;unix=/tmp/redis.sock;db=3")
 ...
 
+3.2. init_without_redis (integer)
+
+   If set to 1, the module will correctly initialize even if redis is not
+   available at start up.
+
+   Default value is “0”.
+
+   Example 1.2. Set init_without_redis parameter
+...
+modparam("ndb_redis", "init_without_redis", 1)
+...
+
 4. Functions
 
    4.1. redis_cmd(srvname, command, ..., replyid)
@@ -148,7 +164,7 @@ modparam("ndb_redis", "server", "name=srvY;unix=/tmp/redis.sock;db=3")
      * value[n] - returns value of the nth element. value - returns null
        for an array. You need to get each element by index.
 
-   Example 1.2. redis_cmd usage
+   Example 1.3. redis_cmd usage
 ...
 if(redis_cmd("srvN", "INCR cnt", "r")) {
     # success - the incremented value is in $redis(r=>value)
@@ -189,7 +205,7 @@ if(redis_cmd("srvN", "HMGET foo_key field1 field3", "r")) {
    function. When ndb_redis module closes, all pending replies are freed
    automatically.
 
-   Example 1.3. redis_free usage
+   Example 1.4. redis_free usage
 ...
 After a redis command call:
         redis_cmd("srvN", "INCR cnt", "r");

+ 19 - 0
modules/ndb_redis/doc/ndb_redis_admin.xml

@@ -93,6 +93,25 @@ modparam("ndb_redis", "server", "name=srvY;unix=/tmp/redis.sock;db=3")
 </programlisting>
 		</example>
 	</section>
+	<section id="ndb_redis.p.init_without_redis">
+		<title><varname>init_without_redis</varname> (integer)</title>
+		<para>
+			If set to 1, the module will correctly initialize even if redis is not available at start up.
+		</para>
+		<para>
+		<emphasis>
+			Default value is <quote>0</quote>.
+		</emphasis>
+		</para>
+		<example>
+			<title>Set <varname>init_without_redis</varname> parameter</title>
+			<programlisting format="linespecific">
+...
+modparam("ndb_redis", "init_without_redis", 1)
+...
+			</programlisting>
+		</example>
+	</section>
 	</section>
 
 	<section>

+ 11 - 2
modules/ndb_redis/ndb_redis_mod.c

@@ -42,6 +42,7 @@ MODULE_VERSION
 /** parameters */
 
 int redis_srv_param(modparam_t type, void *val);
+int init_without_redis = 0;
 static int w_redis_cmd3(struct sip_msg* msg, char* ssrv, char* scmd,
 		char* sres);
 static int w_redis_cmd4(struct sip_msg* msg, char* ssrv, char* scmd,
@@ -84,6 +85,7 @@ static cmd_export_t cmds[]={
 
 static param_export_t params[]={
 	{"server",         PARAM_STRING|USE_FUNC_PARAM, (void*)redis_srv_param},
+	{"init_without_redis", INT_PARAM, &init_without_redis},
 	{0, 0, 0}
 };
 
@@ -113,8 +115,15 @@ static int child_init(int rank)
 
 	if(redisc_init()<0)
 	{
-		LM_ERR("failed to initialize redis connections\n");
-		return -1;
+		if (init_without_redis==1)
+		{
+			LM_WARN("failed to initialize redis connections, but initializing module anyway\n");
+			return 0;
+		}
+		else {
+			LM_ERR("failed to initialize redis connections\n");
+			return -1;
+		}
 	}
 	return 0;
 }