From: Adam Dickmeiss Date: Wed, 11 Jun 2014 12:18:12 +0000 (+0200) Subject: Honor memcached options= --server=localhost as redis conf X-Git-Tag: v5.2.0~19 X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=commitdiff_plain;h=aee5f339aa17154788cd15bc3c373992e7f34de6 Honor memcached options= --server=localhost as redis conf This is only done where YAZ is without libmemcached support. --- diff --git a/src/zoom-memcached.c b/src/zoom-memcached.c index 828dca6..36546e3 100644 --- a/src/zoom-memcached.c +++ b/src/zoom-memcached.c @@ -99,6 +99,41 @@ 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, ':'); + char *weight = strstr(host, "/?"); + if (port) + *port++ = '\0'; + if (weight) + { + *weight = '\0'; + weight += 2; + } + + context = redisConnectWithTimeout(host, + port ? atoi(port) : 6379, + timeout); + } + } + nmem_destroy(nmem); + return context; +} +#endif + int ZOOM_memcached_configure(ZOOM_connection c) { const char *val; @@ -149,9 +184,19 @@ int ZOOM_memcached_configure(ZOOM_connection c) } memcached_behavior_set(c->mc_st, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1); #else +#if HAVE_HIREDIS + c->redis_c = create_redis(val); + if (c->redis_c == 0 || c->redis_c->err) + { + ZOOM_set_error(c, ZOOM_ERROR_MEMCACHED, + "could not create redis"); + return -1; + } +#else ZOOM_set_error(c, ZOOM_ERROR_MEMCACHED, "not enabled"); return -1; #endif +#endif } return 0; }