Module: sip-router
Branch: master
Commit: b7a1ba89ce9d8a310b9b0151f6535d612dbc9057
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=b7a1ba8…
Author: Vicente Hernando <vhernando(a)systemonenoc.com>
Committer: Vicente Hernando <vhernando(a)systemonenoc.com>
Date: Wed Aug 29 12:45:40 2012 -0400
ndb_redis: redisc_exec_argv function
---
modules/ndb_redis/redis_client.c | 55 ++++++++++++++++++++++++++++++++++++++
modules/ndb_redis/redis_client.h | 7 +++++
2 files changed, 62 insertions(+), 0 deletions(-)
diff --git a/modules/ndb_redis/redis_client.c b/modules/ndb_redis/redis_client.c
index 0bf2c37..5248135 100644
--- a/modules/ndb_redis/redis_client.c
+++ b/modules/ndb_redis/redis_client.c
@@ -379,6 +379,61 @@ error_exec:
}
/**
+ * Executes a redis command.
+ * Command is coded using a vector of strings, and a vector of lenghts.
+ *
+ * @param rsrv Pointer to a redis_server_t structure.
+ * @param argc number of elements in the command vector.
+ * @param argv vector of zero terminated strings forming the command.
+ * @param argvlen vector of command string lenghts or NULL.
+ * @return redisReply structure or NULL if there was an error.
+ */
+void * redisc_exec_argv(redisc_server_t *rsrv, int argc, const char **argv, const size_t
*argvlen)
+{
+ redisReply *res=NULL;
+
+ if(rsrv==NULL || rsrv->ctxRedis==NULL)
+ {
+ LM_ERR("no redis context found for server %.*s\n",
+ rsrv->sname->len, rsrv->sname->s);
+ return NULL;
+ }
+ if(argc<=0)
+ {
+ LM_ERR("invalid parameters\n");
+ return NULL;
+ }
+ if(argv==NULL || *argv==NULL)
+ {
+ LM_ERR("invalid parameters\n");
+ return NULL;
+ }
+ res = redisCommandArgv(rsrv->ctxRedis, argc, argv, argvlen);
+ if(res)
+ {
+ return res;
+ }
+
+ /* null reply, reconnect and try again */
+ if(rsrv->ctxRedis->err)
+ {
+ LM_ERR("Redis error: %s\n", rsrv->ctxRedis->errstr);
+ }
+ if(redisc_reconnect_server(rsrv)==0)
+ {
+ res = redisCommandArgv(rsrv->ctxRedis, argc, argv, argvlen);
+ }
+ else
+ {
+ LM_ERR("Unable to reconnect to server: %.*s\n",
+ rsrv->sname->len, rsrv->sname->s);
+ return NULL;
+ }
+
+ return res;
+}
+
+/**
*
*/
redisc_reply_t *redisc_get_reply(str *name)
diff --git a/modules/ndb_redis/redis_client.h b/modules/ndb_redis/redis_client.h
index 8aebe77..805c6fd 100644
--- a/modules/ndb_redis/redis_client.h
+++ b/modules/ndb_redis/redis_client.h
@@ -58,6 +58,13 @@ typedef struct redisc_pv {
gparam_t pos; /* Array element position. */
} redisc_pv_t;
+/* Server related functions */
+redisc_server_t* redisc_get_server(str *name);
+int redisc_reconnect_server(redisc_server_t *rsrv);
+
+/* Command related functions */
+int redisc_exec(str *srv, str *res, str *cmd, ...);
+void* redisc_exec_argv(redisc_server_t *rsrv, int argc, const char **argv, const size_t
*argvlen);
redisc_reply_t *redisc_get_reply(str *name);
int redisc_free_reply(str *name);
#endif