Hello,

thanks for testing, indeed it was an extra declaration left over. Can you try with the new patch attached?

Cheers,
Daniel

On 2/17/12 11:10 AM, Andrew Pogrebennyk wrote:
Hi Daniel,

On 02/17/2012 10:47 AM, Daniel-Constantin Mierla wrote:
I made a patch for server reconnect -- I had no access to a computer
with redis lib installed for the moment, hopefully it compiles. If you
can try and tell the result, it would be great, I can commit then.
I may be able to test this patch as well. Currently compilations bails
out on attempt to redeclare redisc_reconnect_server function parameter:

CC (gcc) [M ndb_redis.so]               ndb_redis_mod.o
CC (gcc) [M ndb_redis.so]               redis_client.o
redis_client.c: In function ‘redisc_reconnect_server’:
redis_client.c:206:19: error: ‘rsrv’ redeclared as different kind of symbol
redis_client.c:202:46: note: previous definition of ‘rsrv’ was here
make[1]: *** [redis_client.o] Error 1
make: *** [modules] Error 1

_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users

--
Daniel-Constantin Mierla -- http://www.asipto.com
http://linkedin.com/in/miconda -- http://twitter.com/miconda

diff --git a/modules/ndb_redis/redis_client.c b/modules/ndb_redis/redis_client.c
index 9f4ffc4..eccab2b 100644
--- a/modules/ndb_redis/redis_client.c
+++ b/modules/ndb_redis/redis_client.c
@@ -199,6 +199,61 @@ redisc_server_t *redisc_get_server(str *name)
 /**
  *
  */
+int redisc_reconnect_server(redisc_server_t *rsrv)
+{
+       char *addr;
+       unsigned int port, db;
+       param_t *pit = NULL;
+       struct timeval tv;
+
+       tv.tv_sec = 1;
+       tv.tv_usec = 0;
+       addr = "127.0.0.1";
+       port = 6379;
+       db = 0;
+       for (pit = rsrv->attrs; pit; pit=pit->next)
+       {
+               if(pit->name.len==4 && strncmp(pit->name.s, "addr", 4)==0) {
+                       addr = pit->body.s;
+                       addr[pit->body.len] = '\0';
+               } else if(pit->name.len==4 && strncmp(pit->name.s, "port", 
4)==0) {
+                       if(str2int(&pit->body, &port) < 0)
+                               port = 6379;
+               } else if(pit->name.len==2 && strncmp(pit->name.s, "db", 2)==0) 
{
+                       if(str2int(&pit->body, &db) < 0)
+                               db = 0;
+               }
+       }
+       if(rsrv->ctxRedis!=NULL) {
+               rsrv->ctxRedis = NULL;
+               redisFree(rsrv->ctxRedis);
+       }
+
+       rsrv->ctxRedis = redisConnectWithTimeout(addr, port, tv);
+       if(!rsrv->ctxRedis)
+               goto err;
+       if (rsrv->ctxRedis->err)
+               goto err2;
+       if (redisCommandNR(rsrv->ctxRedis, "PING"))
+               goto err2;
+       if (redisCommandNR(rsrv->ctxRedis, "SELECT %i", db))
+               goto err2;
+
+       return 0;
+
+err2:
+       LM_ERR("error communicating with redis server [%.*s] (%s:%d/%d): %s\n",
+               rsrv->sname->len, rsrv->sname->s, addr, port, db, 
rsrv->ctxRedis->errstr);
+       return -1;
+err:
+       LM_ERR("failed to connect to redis server [%.*s] (%s:%d/%d)\n",
+               rsrv->sname->len, rsrv->sname->s, addr, port, db);
+       return -1;
+}
+
+/**
+ *
+ */
 int redisc_exec(str *srv, str *cmd, str *argv1, str *argv2, str *argv3,
                str *res)
 {
@@ -237,6 +292,14 @@ int redisc_exec(str *srv, str *cmd, str *argv1, str 
*argv2, str *argv3,
        c = cmd->s[cmd->len];
        cmd->s[cmd->len] = '\0';
        rpl->rplRedis = redisCommand(rsrv->ctxRedis, cmd->s);
+       if(rpl->rplRedis == NULL)
+       {
+               /* null reply, reconnect and try again */
+               if(redisc_reconnect_server(rsrv)==0)
+               {
+                       rpl->rplRedis = redisCommand(rsrv->ctxRedis, cmd->s);
+               }
+       }
        cmd->s[cmd->len] = c;
        return 0;
 }
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users

Reply via email to