ZOOM: no memcached/redis hack. Options for redis context
[yaz-moved-to-github.git] / src / zoom-memcached.c
index 828dca6..def2ac9 100644 (file)
@@ -99,6 +99,34 @@ static memcached_st *yaz_memcached_wrap(const char *conf)
 }
 #endif
 
+#if HAVE_HIREDIS
+static redisContext *create_redis(const char *conf)
+{
+    char **darray;
+    int i, num;
+    NMEM nmem = nmem_create();
+    redisContext *context = 0;
+
+    nmem_strsplit_blank(nmem, conf, &darray, &num);
+    for (i = 0; i < num; i++)
+    {
+        if (!yaz_strncasecmp(darray[i], "--SERVER=", 9))
+        {
+            struct timeval timeout = { 1, 500000 }; /* 1.5 seconds */
+            char *host = darray[i] + 9;
+            char *port = strchr(host, ':');
+            if (port)
+                *port++ = '\0';
+            context = redisConnectWithTimeout(host,
+                                              port ? atoi(port) : 6379,
+                                              timeout);
+        }
+    }
+    nmem_destroy(nmem);
+    return context;
+}
+#endif
+
 int ZOOM_memcached_configure(ZOOM_connection c)
 {
     const char *val;
@@ -121,9 +149,7 @@ int ZOOM_memcached_configure(ZOOM_connection c)
     if (val && *val)
     {
 #if HAVE_HIREDIS
-        struct timeval timeout = { 1, 500000 }; /* 1.5 seconds */
-
-        c->redis_c = redisConnectWithTimeout(val, 6379, timeout);
+        c->redis_c = create_redis(val);
         if (c->redis_c == 0 || c->redis_c->err)
         {
             ZOOM_set_error(c, ZOOM_ERROR_MEMCACHED,