Oracle 5.0 Reference Manual page 1381

Table of Contents

Advertisement

15.6.3.3. Using
libmemcached
The
libmemcached
basis for a number of different additional API implementations, including Perl, Python and Ruby.
Understanding the core
The C library is the most comprehensive interface library for
operational systems not always exposed in interfaces not based on the
The different functions can be divided up according to their basic operation. In addition to functions
that interface to the core API, a number of utility functions provide extended functionality, such as
appending and prepending data.
To build and install libmemcached, download the
then build and install:
shell> tar xjf libmemcached-0.21.tar.gz
shell> cd libmemcached-0.21
shell> ./configure
shell> make
shell> make install
On many Linux operating systems, you can install the corresponding
the usual yum, apt-get, or similar commands.
To build an application that uses the library, first set the list of servers. Either directly manipulate the
servers configured within the main
and then add this list to the
example. Once the server list has been set, you can call the functions to store or retrieve data. A
simple application for setting a preset value to
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <libmemcached/memcached.h>
int main(int argc, char *argv[])
{
memcached_server_st *servers = NULL;
memcached_st *memc;
memcached_return rc;
char *key= "keystring";
char *value= "keyvalue";
memcached_server_st *memcached_servers_parse (char *server_strings);
memc= memcached_create(NULL);
servers= memcached_server_list_append(servers, "localhost", 11211, &rc);
rc= memcached_server_push(memc, servers);
if (rc == MEMCACHED_SUCCESS)
fprintf(stderr,"Added server successfully\n");
else
fprintf(stderr,"Couldn't add server: %s\n",memcached_strerror(memc, rc));
rc= memcached_set(memc, key, strlen(key), value, strlen(value), (time_t)0, (uint32_t)0);
if (rc == MEMCACHED_SUCCESS)
fprintf(stderr,"Key stored successfully\n");
else
fprintf(stderr,"Couldn't store key: %s\n",memcached_strerror(memc, rc));
return 0;
}
To test the success of an operation, use the return value, or populated result code, for a given function.
The value is always set to
use the
memcached_strerror()
Developing a
memcached
with C and C++
library provides both C and C++ interfaces to
functions can help when using these other interfaces.
libmemcached
memcached_st
memcached_st
MEMCACHED_SUCCESS
function to translate the result code into a printable string.
1361
Application
memcached
memcached
libmemcached
structure, or separately populate a list of servers,
structure. The latter method is used in the following
is provided here:
localhost
if the operation succeeded. In the event of a failure,
and is also the
and provides functions and
library.
libmemcached
package, run configure, and
package through
libmemcached

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents