libmemcached man page

libmemcached — Introducing the C Client Library for memcached


#include <libmemcached/memcached.h>

Compile and link with -lmemcached


libMemcached is an open source C/C++ client library and tools for the memcached server (http://memcached.org/). It has been designed to be light on memory usage, thread safe, and provide full access to server side methods.

libMemcached was designed to provide the greatest number of options to use Memcached. Some of the features provided:

Asynchronous and Synchronous Transport Support.
Consistent Hashing and Distribution.
Tunable Hashing algorithm to match keys.
Access to large object support.
Local replication.
A complete reference guide and documentation to the API.
Tools to Manage your Memcached networks.


"Memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load." http://memcached.org/

libmemcached is a small, thread-safe client library for the memcached protocol. The code has all been written to allow for both web and embedded usage. It handles the work behind routing individual keys to specific servers specified by the developer (and values are matched based on server order as supplied by the user). It implements a modular and consistent method of object distribution.

There are multiple implemented routing and hashing methods. See the memcached_behavior_set() manpage for more information.

All operations are performed against a memcached_st structure. These structures can either be dynamically allocated or statically allocated and then initialized by memcached_create(). Functions have been written in order to encapsulate the memcached_st. It is not recommended that you operate directly against the structure.

Nearly all functions return a memcached_return_t value. This value can be translated to a printable string with memcached_strerror.

Objects are stored on servers by hashing keys. The hash value maps the key to a particular server. All clients understand how this hashing works, so it is possibly to reliably both push data to a server and retrieve data from a server.

Group keys can be optionally used to group sets of objects with servers.

Namespaces are supported, and can be used to partition caches so that multiple applications can use the same memcached servers.

memcached_st structures are thread-safe, but each thread must contain its own structure (that is, if you want to share these among threads you must provide your own locking). No global variables are used in this library.

If you are working with GNU autotools you will want to add the following to your COPYING to properly include libmemcached in your application.


Some features of the library must be enabled through memcached_behavior_set().

Hope you enjoy it!


A number of constants have been provided for in the library.

The default port used by memcached(3).
Default maximum size of a key (which includes the null pointer). Master keys have no limit, this only applies to keys used for storage.
Default size of key (which includes the null pointer).
This is the "stride" used in the consistent hash used between replicas.
Maximum allowed size of the hostname.
String value of libmemcached version such as "1.23.4"
Hex value of the version number. "0x00048000" This can be used for comparing versions based on number.
Maximum length allowed for namespacing of a key.

Threads and Processes

When using threads or forked processes it is important to keep one instance of memcached_st per process or thread. Without creating your own locking structures you can not share a single memcached_st. However, you can call memcached_quit() on a memcached_st and then use the resulting cloned structure.


To find out more information please check: http://libmemcached.org/

See Also

memcached(1) libmemcached_examples(3) libmemcached(1) memcat(1) memcp(1) memflush(1) memrm(1) memslap(1) memstat(1) memcached_fetch(3) memcached_replace(3) memcached_server_list_free(3) libmemcached_examples(3) memcached_clone(3) memcached_free(3) memcached_server_add(3) memcached_server_push(3) memcached_add(3) memcached_get(3) memcached_server_count(3) memcached_create(3) memcached_increment(3) memcached_server_list(3) memcached_set(3) memcached_decrement(3) memcached_mget(3) memcached_server_list_append(3) memcached_strerror(3) memcached_delete(3) memcached_quit(3) memcached_server_list_count(3) memcached_verbosity(3) memcached_server_add_unix_socket(3) memcached_result_create(3) memcached_result_free(3) memcached_result_key_value(3) memcached_result_key_length(3) memcached_result_value(3) memcached_result_length(3) memcached_result_flags(3) memcached_result_cas(3) memcached_result_st(3) memcached_append(3) memcached_prepend(3) memcached_fetch_result(3) memerror(1) memcached_get_by_key(3) memcached_mget_by_key(3) memcached_delete_by_key(3) memcached_fetch_execute(3) memcached_callback_get(3) memcached_callback_set(3) memcached_version(3) memcached_lib_version(3) memcached_result_set_value(3) memcached_dump(3) memdump(1) memcached_set_memory_allocators(3) memcached_get_memory_allocators(3) memcached_get_user_data(3) memcached_set_user_data(3)


Brian Aker

Referenced By

libmemcached_check_configuration(3), libmemcached_configuration(3), libmemcachedutil(3), memaslap(1), memcached(3), memcached_add(3), memcached_add_by_key(3), memcached_analyze(3), memcached_behavior_get(3), memcached_behavior_set(3), memcached_callback_get(3), memcached_callback_set(3), memcached_cas(3), memcached_cas_by_key(3), memcached_clone(3), memcached_create(3), memcached_decrement(3), memcached_decrement_with_initial(3), memcached_delete(3), memcached_delete_by_key(3), memcached_destroy_sasl_auth_data(3), memcached_dump(3), memcached_exist(3), memcached_exist_by_key(3), memcached_fetch(3), memcached_fetch_execute(3), memcached_fetch_result(3), memcached_flush_buffers(3), memcached_free(3), memcached_generate_hash(3), memcached_generate_hash_value(3), memcached_get(3), memcached_get_by_key(3), memcached_get_memory_allocators(3), memcached_get_sasl_callbacks(3), memcached_get_user_data(3), memcached_increment(3), memcached_increment_with_initial(3), memcached_last_error_message(3), memcached_lib_version(3), memcached_mget(3), memcached_mget_by_key(3), memcached_mget_execute(3), memcached_mget_execute_by_key(3), memcached_pool(3), memcached_pool_behavior_get(3), memcached_pool_behavior_set(3), memcached_pool_create(3), memcached_pool_destroy(3), memcached_pool_fetch(3), memcached_pool_pop(3), memcached_pool_push(3), memcached_pool_release(3), memcached_pool_st(3), memcached_quit(3), memcached_replace(3), memcached_replace_by_key(3), memcached_sasl_set_auth_data(3), memcached_server_add(3), memcached_server_count(3), memcached_server_cursor(3), memcached_server_list(3), memcached_server_list_append(3), memcached_server_list_count(3), memcached_server_list_free(3), memcached_server_push(3), memcached_servers_parse(3), memcached_set(3), memcached_set_by_key(3), memcached_set_memory_allocators(3), memcached_set_sasl_callbacks(3), memcached_set_user_data(3), memcached_stat(3), memcached_stat_execute(3), memcached_stat_get_keys(3), memcached_stat_get_value(3), memcached_stat_servername(3), memcached_strerror(3), memcached_touch(3), memcached_touch_by_key(3), memcached_verbosity(3), memcached_version(3), memcapable(1), memcat(1), memcp(1), memdump(1), memerror(1), memexist(1), memflush(1), memparse(1), memping(1), memrm(1), memslap(1), memstat(1), memtouch(1).

Explore man page connections for libmemcached(3).

libmemcached 1.0.18 February 09, 2014