C++客户端:libmemcached客户端介绍:
https://launchpad.net/libmemcached?spm=a2c4g.11186623.2.5.bGUAw2
安装SASL相关环境:yuminstall-ycyrus-sasl-plaincyrus-saslcyrus-sasl-develcyrus-sasl-liblibmemcached安装:
wgethttps://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gztar-xvflibmemcached-1.0.18.tar.gzcdlibmemcached-1.0.18./configure--enable-saslmake#defineIP"ip"#definePORTport//默认为11211intmain(intargc,charargv[]){//connectservermemcached_stmemc;memcached_returnrc;memcached_server_stserver;time_texpiration=0;uint32_tflags;memc=memcached_create(NULL);server=memcached_server_list_append(NULL,IP,PORT,rc=memcached_server_push(memc,server);memcached_server_list_free(server);stringkey="Key";stringvalue="Value";size_tvalue_length=value.length();size_tkey_length=key.length();rc=memcached_set(memc,key.c_str(),key.length(),value.c_str(),value.length(),expiration,flags);if(rc==MEMCACHED_SUCCESS){cout<<"savekey:"< C++示例代码2(密码访问): #include#include#includeusingnamespacestd;#defineIP"ip"#definePORTport//默认为11211#defineUSERNAME"username"#definePASSWORD"password"intmain(intargc,charargv[]){memcached_stmemc;memcached_returnrc;memcached_server_stserver;time_texpiration=0;uint32_tflags;memc=memcached_create(NULL);server=memcached_server_list_append(NULL,IP,PORT,sasl_client_init(NULL);rc=memcached_set_sasl_auth_data(memc,USERNAME,PASSWORD);if(rc!=MEMCACHED_SUCCESS){cout
代码编译链接:g++-olibmemcachedlibmemcached.cpp-lmemcached-std=c++0x-lpthread-lsasl2
<"savekey:"<
发表评论