日期:2014-05-16 浏览次数:20619 次
#include <unistd.h>
#include <libmemcached/memcached.h>
#include <string.h>
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
#include <time.h>
int main(int argc ,char ** argv)
{
memcached_st * ms;
ms=memcached_create(NULL);
time_t expiration;
uint32_t flags;
memcached_return rc;
memcached_server_st * server;
//conncet to the server
server=memcached_server_list_append(NULL,"localhost",11211,&rc);
memcached_server_push(ms,server);
memcached_server_list_free(server);
char key[]="key";
char value[]="value";
size_t keylength=sizeof(key);
size_t valuelength=sizeof(value);
printf("before set data keylength:%d valuelength:%d\n",keylength,valuelength);
//save data
rc=memcached_set(ms,key,keylength-1,value,valuelength-1,expiration,flags);
if(rc==MEMCACHED_SUCCESS)
printf("save data successful!\n");
//get data
char * result=memcached_get(ms,key,valuelength-1,&valuelength,&flags,&rc);
if(rc==MEMCACHED_SUCCESS)
printf("get value:%s\n",result);
//delete data
rc=memcached_delete(ms,key,keylength-1,expiration);
if(rc==MEMCACHED_SUCCESS)
printf("delete key:%s\n",key);
//free
memcached_free(ms);
return 0;
}
#include <libmemcached/memcached.h>
#include <string>
#include <iostream>
using namespace std;
int main(int argc ,char ** argv)
{
memcached_st * ms;
ms=memcached_create(NULL);