+#if HAVE_HIREDIS
+ if (c->redis_c)
+ redisFree(c->redis_c);
+#endif
+}
+
+#if HAVE_LIBMEMCACHED
+static memcached_st *create_memcached(const char *conf,
+ int *expire_search, int *expire_record)
+{
+ char **darray;
+ int i, num;
+ memcached_st *mc = memcached_create(0);
+ NMEM nmem = nmem_create();
+ memcached_return_t rc;
+
+ nmem_strsplit_blank(nmem, conf, &darray, &num);
+ for (i = 0; mc && i < num; i++)
+ {
+ if (!yaz_strncasecmp(darray[i], "--SERVER=", 9))
+ {
+ char *host = darray[i] + 9;
+ char *port = strchr(host, ':');
+ char *weight = strstr(host, "/?");
+ if (port)
+ *port++ = '\0';
+ if (weight)
+ {
+ *weight = '\0';
+ weight += 2;
+ }
+ rc = memcached_server_add(mc, host, port ? atoi(port) : 11211);
+ yaz_log(YLOG_LOG, "memcached_server_add host=%s rc=%u %s",
+ host, (unsigned) rc, memcached_strerror(mc, rc));
+ if (rc != MEMCACHED_SUCCESS)
+ {
+ memcached_free(mc);
+ mc = 0;
+ }
+ }
+ else if (!yaz_strncasecmp(darray[i], "--EXPIRE=", 9))
+ {
+ *expire_search = atoi(darray[i] + 9);
+ *expire_record = 600 + *expire_search;
+ }
+ else
+ {
+ /* bad directive */
+ memcached_free(mc);
+ mc = 0;
+ }
+ }
+ nmem_destroy(nmem);
+ return mc;
+}
+#endif
+
+#if HAVE_HIREDIS
+static redisContext *create_redis(const char *conf,
+ int *expire_search, int *expire_record)
+{
+ 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);
+ }
+ else if (!yaz_strncasecmp(darray[i], "--EXPIRE=", 9))
+ {
+ *expire_search = atoi(darray[i] + 9);
+ *expire_record = 600 + *expire_search;
+ }
+ }
+ nmem_destroy(nmem);
+ return context;