1, installation memcached
~$ wget http://memcached.googlecode.com/files/memcached-1.2.8.tar.gz.
$ tar xvzf lmemcached-1.2.8.tar.gz
$ cdlmemcached-1.2.8
$./configure
$ Make
$ sudo make install
Start server (allocate 512 MB of memory, monitor 11211port):
./memcached-m 512-p 11211-VV
2. 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/.
3, libmemcached simple test use
#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;}
Installation and test of libmemcached