首页 > 代码库 > libmemcached的安装及测试
libmemcached的安装及测试
1、下载安装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简单测试使用
$ 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简单测试使用
1 #include <iostream>
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
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
libmemcached的安装及测试
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。