#include <yaz/log.h>
#include <yaz/diagbib1.h>
-#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
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
#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)
{
}
#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;
c->redis_c = 0;
}
#endif
-#if HAVE_LIBMEMCACHED_MEMCACHED_H
+#if HAVE_LIBMEMCACHED
if (c->mc_st)
{
memcached_free(c->mc_st);
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,
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)
{
ZOOM_connection_put_event(c, event);
resultset->live_set = 1;
}
- freeReplyObject(reply);
+ if (reply)
+ freeReplyObject(reply);
}
#endif
-#if HAVE_LIBMEMCACHED_MEMCACHED_H
+#if HAVE_LIBMEMCACHED
if (c->mc_st && resultset->live_set == 0)
{
size_t v_len;
odr_destroy(odr);
}
#endif
-#if HAVE_LIBMEMCACHED_MEMCACHED_H
+#if HAVE_LIBMEMCACHED
if (c->mc_st && resultset->live_set == 0)
{
uint32_t flags = 0;
wrbuf_destroy(rec_sha1);
}
#endif
-#if HAVE_LIBMEMCACHED_MEMCACHED_H
+#if HAVE_LIBMEMCACHED
if (r->connection->mc_st &&
!diag && npr->which == Z_NamePlusRecord_databaseRecord)
{
freeReplyObject(reply1);
}
#endif
-#if HAVE_LIBMEMCACHED_MEMCACHED_H
+#if HAVE_LIBMEMCACHED
if (r->connection && r->connection->mc_st)
{
WRBUF k = wrbuf_alloc();