我是libmemcached的新手,在memcached_set行面临以下问题,如果有人有解决方案,请帮助我。显示错误:无法存储密钥:getaddrinfo或getnameinfo HOSTNAME LOOKUP FAILURE。我能够使用win32 API LoadLibrary和GetProcAddress调用libmemcached.dll方法。
#include "..\libmemcached-1.0\memcached.h"
int main()
{
typedef memcached_st*(__cdecl *MYPROC)(memcached_st*);
typedef memcached_server_list_st(__cdecl *mem_server_lis_app)(memcached_server_list_st, const char *, in_port_t, memcached_return_t *);
typedef memcached_return_t(__cdecl *memc_server_push)(memcached_st *, const memcached_server_list_st);
typedef const char* (__cdecl *memcached_err)(const memcached_st *, memcached_return_t );
typedef memcached_return_t(__cdecl *memcach_set)(memcached_st *ptr, const char *key, size_t key_length, const char *, size_t, time_t, uint32_t);
struct memcached_server_st *servers = NULL;
struct memcached_st *memc=NULL;
memcached_return_t rc;
char *key = (char*)"keystring";
char *value = (char*)"keyvalue";
char *retrieved_value;
size_t value_length;
uint32_t flags;
HINSTANCE hinstLib;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
hinstLib = LoadLibrary(TEXT("libmemcached.dll"));
if (hinstLib != NULL)
{
MYPROC ProcAdd;
ProcAdd = (MYPROC)GetProcAddress(hinstLib, "memcached_create");
if (NULL != ProcAdd)
{
fRunTimeLinkSuccess = TRUE;
memc = (ProcAdd)(NULL);
}
mem_server_lis_app mem_ser_lis_app;
mem_ser_lis_app = (mem_server_lis_app)GetProcAddress(hinstLib, "memcached_server_list_append");
if (NULL != mem_ser_lis_app)
{
servers = mem_ser_lis_app(servers, "127.0.0.1", 11211, &rc);
}
memc_server_push memc_serv_push;
memc_serv_push = (memc_server_push)GetProcAddress(hinstLib, "memcached_server_push");
if (NULL != memc_serv_push)
{
rc = memc_serv_push(memc, servers);
}
memcached_err err;
err= (memcached_err)GetProcAddress(hinstLib, "memcached_strerror");
if (rc == MEMCACHED_SUCCESS)
fprintf(stderr, "Added server successfully\n");
else
fprintf(stderr, "Couldn't add server: %s\n", err(memc, rc));
memcach_set memcachSet;
memcachSet= (memcach_set)GetProcAddress(hinstLib, "memcached_set");
rc = memcachSet(memc, key, strlen(key), value, strlen(value), (time_t)0, (uint32_t)0);
if (rc == MEMCACHED_SUCCESS)
fprintf(stderr, "Key stored successfully\n");
else
fprintf(stderr, "Couldn't store key: %s\n", err(memc, rc));
}
fFreeResult = FreeLibrary(hinstLib);
return 0;
}