Quellcode durchsuchen

ndb_redis: redisc_exec_argv function

Vicente Hernando vor 13 Jahren
Ursprung
Commit
b7a1ba89ce
2 geänderte Dateien mit 62 neuen und 0 gelöschten Zeilen
  1. 55 0
      modules/ndb_redis/redis_client.c
  2. 7 0
      modules/ndb_redis/redis_client.h

+ 55 - 0
modules/ndb_redis/redis_client.c

@@ -378,6 +378,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;
+}
+
 /**
 /**
  *
  *
  */
  */

+ 7 - 0
modules/ndb_redis/redis_client.h

@@ -58,6 +58,13 @@ typedef struct redisc_pv {
 	gparam_t pos;  /* Array element position. */
 	gparam_t pos;  /* Array element position. */
 } redisc_pv_t;
 } 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);
 redisc_reply_t *redisc_get_reply(str *name);
 int redisc_free_reply(str *name);
 int redisc_free_reply(str *name);
 #endif
 #endif