当前位置: 首页 > 图灵资讯 > 技术篇> libmemcached的安装及测试

libmemcached的安装及测试

来源:图灵教育
时间:2023-05-29 14:02:12

1、安装memcached安装

~$ wget http://memcached.googlecode.com/files/memcached-1.2.8.tar.gz.

$ tar xvzf lmemcached-1.2.8.tar.gz lmemcached-1.2.8$ ./configure$ make$ sudo make install

启动服务器(分配512兆内存,监控11211端口):

./memcached -m 512 -p 11211 -vv

2、下载安装libmemcached

$ wget https://www.tulingxueyuan.cn/d/file/p/20230529/ybtr031vbsg.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/下。

3、使用libmemcached简单测试

#include <iostream>#include <string>#include <libmemcached/memcached.h>using namespace std;int main(int argc, char *argv[]){    //connect server    memcached_st *memc;    memcached_return rc;    memcached_server_st *server;    time_t expiration = 0;    uint32_t  flags = 0;    memc = memcached_create(NULL);    server = memcached_server_list_append(NULL, "localhost", 11211, &rc);    rc = memcached_server_push(memc, server);    memcached_server_list_free(server);    string key = "key";    string value = "value";    size_t value_length = value.length();    size_t key_length = key.length();    //Save data    rc = memcached_set(memc, key.c_str(), key.length(), value.c_str(), value.length(), expiration, flags);    if (rc == MEMCACHED_SUCCESS)    {        cout << "Save data:" << value << " sucessful!" << endl;    }    //Get data    char* result = memcached_get(memc, key.c_str(), key_length, &value_length, &flags, &rc);    if (rc == MEMCACHED_SUCCESS)    {        cout << "Get value:" << result << " sucessful!" << endl;    }    //Delete data    rc = memcached_delete(memc, key.c_str(), key_length, expiration);    if (rc == MEMCACHED_SUCCESS)    {        cout << "Delete key:" << key << " sucessful!" << endl;    }    //free    memcached_free(memc);    return 0;}

上一篇:

JVM

下一篇:

继承中字符类成员变量的调用