libmemcached的安装及测试
$ wget http://launchpad.net/libmemcached/1.0/0.44/+download/libmemcached-0.44.tar.gz
$ tar xvzf libmemcached-0.44tar.gz
$ cd libmemcached-0.44
$ ./configure
$ make
$ sudo make install
libmemcached 默认安装在/usr/local/,头文件安装在/usr/local/include/libmemcachde/,动态库默认安装在/usr/local/lib/下。
2、libmemcached简单测试使用
2 #include <string>
3 #include <libmemcached/memcached.h>
4
5 using namespace std;
6
7 int main(int argc,char *argv[])
8 {
9 //connect server
10 memcached_st *memc;
11 memcached_return rc;
12 memcached_server_st *server;
13 time_t expiration;
14 uint32_t flags;
15
16 memc = memcached_create(NULL);
17 server = memcached_server_list_append(NULL,"localhost",11211,&rc);
18 rc=memcached_server_push(memc,server);
19 memcached_server_list_free(server);
20
21 string key = "key";
22 string value = "value";
23 size_t value_length = value.length();
24 size_t key_length = key.length();
25
26
27 //Save data
28 rc=memcached_set(memc,key.c_str(),key.length(),value.c_str(),value.length(),expiration,flags);
29 if(rc==MEMCACHED_SUCCESS)
30 {
31 cout<<"Save data:"<<value<<" sucessful!"<<endl;
32 }
33
34 //Get data
35 char* result = memcached_get(memc,key.c_str(),key_length,&value_length,&flags,&rc);
36 if(rc == MEMCACHED_SUCCESS)
37 {
38 cout<<"Get value:"<<result<<" sucessful!"<<endl;
39 }
40
41 //Delete data
42 rc=memcached_delete(memc,key.c_str(),key_length,expiration);
43 if(rc==MEMCACHED_SUCCESS)
44 {
45 cout<<"Delete key:"<<key<<" sucessful!"<<endl;
46 }
47
48 //free
49 memcached_free(memc);
50 return 0;
51 }
52
53
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。