1. Download and install 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 is installed by default in/usr/local/, the header file is installed in/usr/local/include/libmemcachde/, and the dynamic library is installed by default under/usr/local/lib/.
2, libmemcached simple test use
1#include <iostream>
2#include <string>
3#include <libmemcached/memcached.h>
4
5usingnamespaceStd
6
7 intMainintargcChar*argv[])
8{
9//Connect Server
TenMemcached_st *MEMC;
OneMemcached_return RC;
AMemcached_server_st *server;
-time_t expiration;
-uint32_t flags;
the
-MEMC = Memcached_create (NULL);
-Server = Memcached_server_list_append (NULL, "localhost", 11211,&RC);
-Rc=memcached_server_push (Memc,server);
+Memcached_server_list_free (server);
-
+stringKey = "Key";
AstringValue = "value";
atsize_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);
in if(rc==memcached_success)
-{
tocout<< "Save data:" <<value<< "sucessful!" <<endl;
+}
-
the//Get Data
*Char* result = Memcached_get (Memc,key.c_str (), KEY_LENGTH,&VALUE_LENGTH,&FLAGS,&RC);
$if(rc = = memcached_success)
Panax Notoginseng{
-cout<< "Get value:" <<result<< "sucessful!" <<endl;
the}
+
A//Delete Data
theRc=memcached_delete (Memc,key.c_str (), key_length,expiration);
+if(rc==memcached_success)
-{
$cout<< "Delete key:" <<key<< "sucessful!" <<endl;
$}
-
-// Free
theMemcached_free (MEMC);
- return0;
Wuyi}
the
-
Installation and testing of libmemcached