X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fzoom-memcached.c;h=fbdc886d85b6afe6e4cbeaf5516ebd3173af463d;hp=36546e3aa3923509e35b3cc1f1c9299ddd790ad6;hb=e2b8bf88befb43e4a189ce3e659c595e5b3af7dc;hpb=aee5f339aa17154788cd15bc3c373992e7f34de6 diff --git a/src/zoom-memcached.c b/src/zoom-memcached.c index 36546e3..fbdc886 100644 --- a/src/zoom-memcached.c +++ b/src/zoom-memcached.c @@ -20,16 +20,17 @@ #include #include -#if HAVE_LIBMEMCACHED_MEMCACHED_H -#if HAVE_MEMCACHED_RETURN_T +#if HAVE_LIBMEMCACHED +#if LIBMEMCACHED_VERSION_HEX >= 0x01000000 +#define HAVE_MEMCACHED_FUNC 1 #else -typedef memcached_return memcached_return_t; +#define HAVE_MEMCACHED_FUNC 0 #endif #endif void ZOOM_memcached_init(ZOOM_connection c) { -#if HAVE_LIBMEMCACHED_MEMCACHED_H +#if HAVE_LIBMEMCACHED c->mc_st = 0; #endif #if HAVE_HIREDIS @@ -39,7 +40,7 @@ void ZOOM_memcached_init(ZOOM_connection c) void ZOOM_memcached_destroy(ZOOM_connection c) { -#if HAVE_LIBMEMCACHED_MEMCACHED_H +#if HAVE_LIBMEMCACHED if (c->mc_st) memcached_free(c->mc_st); #endif @@ -49,7 +50,7 @@ void ZOOM_memcached_destroy(ZOOM_connection c) #endif } -#if HAVE_LIBMEMCACHED_MEMCACHED_H +#if HAVE_LIBMEMCACHED /* memcached wrapper.. Because memcached function do not exist in older libs */ static memcached_st *yaz_memcached_wrap(const char *conf) { @@ -115,15 +116,8 @@ static redisContext *create_redis(const char *conf) 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); @@ -144,7 +138,7 @@ int ZOOM_memcached_configure(ZOOM_connection c) c->redis_c = 0; } #endif -#if HAVE_LIBMEMCACHED_MEMCACHED_H +#if HAVE_LIBMEMCACHED if (c->mc_st) { memcached_free(c->mc_st); @@ -156,9 +150,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, @@ -174,7 +166,7 @@ int ZOOM_memcached_configure(ZOOM_connection c) val = ZOOM_options_get(c->options, "memcached"); if (val && *val) { -#if HAVE_LIBMEMCACHED_MEMCACHED_H +#if HAVE_LIBMEMCACHED c->mc_st = yaz_memcached_wrap(val); if (!c->mc_st) { @@ -184,19 +176,9 @@ 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; } @@ -293,7 +275,7 @@ void ZOOM_memcached_search(ZOOM_connection c, ZOOM_resultset resultset) freeReplyObject(reply); } #endif -#if HAVE_LIBMEMCACHED_MEMCACHED_H +#if HAVE_LIBMEMCACHED if (c->mc_st && resultset->live_set == 0) { size_t v_len; @@ -377,7 +359,7 @@ void ZOOM_memcached_hitcount(ZOOM_connection c, ZOOM_resultset resultset, odr_destroy(odr); } #endif -#if HAVE_LIBMEMCACHED_MEMCACHED_H +#if HAVE_LIBMEMCACHED if (c->mc_st && resultset->live_set == 0) { uint32_t flags = 0; @@ -471,7 +453,7 @@ void ZOOM_memcached_add(ZOOM_resultset r, Z_NamePlusRecord *npr, wrbuf_destroy(rec_sha1); } #endif -#if HAVE_LIBMEMCACHED_MEMCACHED_H +#if HAVE_LIBMEMCACHED if (r->connection->mc_st && !diag && npr->which == Z_NamePlusRecord_databaseRecord) { @@ -580,7 +562,7 @@ Z_NamePlusRecord *ZOOM_memcached_lookup(ZOOM_resultset r, int pos, freeReplyObject(reply1); } #endif -#if HAVE_LIBMEMCACHED_MEMCACHED_H +#if HAVE_LIBMEMCACHED if (r->connection && r->connection->mc_st) { WRBUF k = wrbuf_alloc();