|
Evo C++ Library v0.5.1
|
#include <evo/async/memcached_client.h>

Implements Memcached protocol for an async client.
Usage:
Classes | |
| struct | OnEvent |
| Base interface used as a shortcut that inherits all the non-error event interfaces: OnConnect, OnStore, OnIncrement, OnTouch, OnRemove, OnGet. More... | |
| struct | OnGet |
| Base interface for on_get() and on_get_end() events. More... | |
| struct | OnIncrement |
| Base interface for on_increment() event. More... | |
| struct | OnRemove |
| Base interface for on_remove() event. More... | |
| struct | OnStore |
| Base interface for on_store() event. More... | |
| struct | OnTouch |
| Base interface for on_touch() event. More... | |
Public Types | |
| typedef AsyncClient< MemcachedClient, impl_memc::ClientQueueItem > | Base |
| typedef MemcachedClient | ProtocolHandler |
| Derived protocol hander type (must inherit from AsyncClient) More... | |
| enum | State |
| Client state. More... | |
| typedef AsyncClient< MemcachedClient, impl_memc::ClientQueueItem > | This |
| This type More... | |
Public Member Functions | |
| MemcachedClient (SizeT max_queue_size=DEFAULT_QUEUE_SIZE, SizeT max_read_size=DEFAULT_MAX_READ) | |
| Constructor to initialize client. More... | |
| This & | attach_to (AsyncBase &parent) |
| Attach to a parent AsyncClient or AsyncServer and use the same event-loop as the parent. More... | |
| void | close () |
| Close connection. More... | |
| bool | connect_ip (const char *host, ushort port, int family=AF_INET) |
| Start IP connection. More... | |
| bool | decr (const SubString &key, uint64 count=1, OnIncrement *on_increment=NULL, OnError *on_error=NULL) |
| Send a request to decrement value for given key. More... | |
| bool | get (const SubString &key, OnGet &on_get, OnError *on_error=NULL, bool track_notfound=false, int64 *expire=NULL) |
| Send a request to get value for one or more keys. More... | |
| bool | get_cas (const SubString &key, OnGet &on_get, OnError *on_error=NULL, bool track_notfound=false, int64 *expire=NULL) |
| Send a request to get value for one or more keys for Compare-And-Swap. More... | |
| ulong | get_id () const |
| Get current client ID. More... | |
| State | get_state () const |
| Get current state. More... | |
| bool | get_touch (const SubString &key, int64 expire, OnGet &on_get, OnError *on_error=NULL, bool track_notfound=false) |
| Send a request to get value for one or more keys and touch (update) the stored expiration time. More... | |
| bool | get_touch_cas (const SubString &key, int64 expire, OnGet &on_get, OnError *on_error=NULL, bool track_notfound=false) |
| Send a request to get value for one or more keys for Compare-And-Swap and touch (update) the stored expiration time. More... | |
| bool | incr (const SubString &key, uint64 count=1, OnIncrement *on_increment=NULL, OnError *on_error=NULL) |
| Send a request to increment value for given key. More... | |
| bool | increment (const SubString &key, uint64 count=1, bool decrement=false, OnIncrement *on_increment=NULL, OnError *on_error=NULL) |
| Send a request to increment or decrement value for given key. More... | |
| bool | remove (const SubString &key, OnRemove *on_remove=NULL, OnError *on_error=NULL) |
| Send a request to delete key and value. More... | |
| bool | runlocal () |
| Run the event-loop locally in current thread until all pending requests are handled (client only). More... | |
| bool | set (const SubString &key, const SubString &value, uint32 flags=0, int64 expire=0, uint64 *cas_id=NULL, OnStore *on_store=NULL, OnError *on_error=NULL) |
| Send a request to set a key and value. More... | |
| bool | set (const SubString &key, const SubString &value, OnStore &on_store, OnError *on_error=NULL, uint32 flags=0, int64 expire=0, uint64 *cas_id=NULL) |
| Send a request to set a key and value. More... | |
| bool | set_add (const SubString &key, const SubString &value, uint32 flags=0, int64 expire=0, OnStore *on_store=NULL, OnError *on_error=NULL) |
| Send a request to add a new key and value and fail if key already exists. More... | |
| bool | set_append (const SubString &key, const SubString &value, OnStore *on_store=NULL, OnError *on_error=NULL) |
| Send a request to append to existing value for key. More... | |
| bool | set_cas (const SubString &key, const SubString &value, uint64 cas_id, OnStore &on_store, OnError *on_error=NULL, uint32 flags=0, int64 expire=0) |
| Send a request to set a key and value using Compare-And-Swap. More... | |
| virtual void | set_logger (LoggerBase *newlogger) |
| Set logger to use. More... | |
| This & | set_on_connect (OnConnect *cb) |
| Set general handler to call when a connection is established. More... | |
| This & | set_on_error (OnError *cb) |
| Set general handler to call when an unexpected error occurs. More... | |
| bool | set_prepend (const SubString &key, const SubString &value, OnStore *on_store=NULL, OnError *on_error=NULL) |
| Send a request to prepend to existing value for key. More... | |
| bool | set_replace (const SubString &key, const SubString &value, uint32 flags=0, int64 expire=0, OnStore *on_store=NULL, OnError *on_error=NULL) |
| Send a request to replace an existing value under key and fail if key doesn't exist. More... | |
| void | set_timeout (ulong read_timeout_ms=0, ulong write_timeout_ms=0) |
| Set read/write timeouts to use. More... | |
| bool | set_timer (OnTimer &on_timer, ulong msec) |
| Activate timer so it expires after given time elapses. More... | |
| bool | touch (const SubString &key, int64 expire, OnTouch *on_touch, OnError *on_error=NULL) |
| Send a request to touch (update) the expiration time for given key. More... | |
Static Public Member Functions | |
| static int64 | calc_expire_time (int64 seconds, int64 base=0) |
| Calculate memcached expiration time for given number of seconds from now. More... | |
Public Attributes | |
| LoggerPtr | logger |
| Logger for protocol and debug messages, set to enable logging – see set_logger() More... | |
Static Public Attributes | |
| static const size_t | DEFAULT_MAX_READ = 524288 |
| static const SizeT | DEFAULT_QUEUE_SIZE = 256 |
| static const size_t | MIN_INITIAL_READ = 0 |
Protected Member Functions | |
| void | init () |
| Initialize event-loop. More... | |
| void | init_attach (AsyncBase &parent) |
| Initialize and attach to a parent event-loop. More... | |
| bool | run_eventloop () |
| Run event loop and process all events and repeat until shutdown. More... | |
| bool | run_eventloop_once () |
| Run event loop with one pass and process all events. More... | |
Static Protected Member Functions | |
| static struct timeval * | get_timeout_ptr (struct timeval &out, ulong ms) |
| Get timeval struct pointer from timeout in milliseconds. More... | |
Protected Attributes | |
| AsyncBase * | child_base_ |
| Pointer to child in AsyncBase chain (always an AsyncClient), NULL for none. More... | |
| AsyncEventLoop * | evloop_ |
| Event loop pointer, either owned by this or a parent. More... | |
| bool | local_ |
| Whether event-loop is local (same thread), false if separate thread. More... | |
| AsyncBase * | parent_base_ |
| Pointer to parent in AsyncBase chain, NULL if this is the main parent (and owns evloop_ pointer) More... | |
| AtomicBufferQueue< QueueItem > | queue_ |
| Queue where each item represents an expected response from server. More... | |
| ulong | read_timeout_ms_ |
| Socket read timeout in milliseconds, 0 for none (never timeout) More... | |
| ulong | write_timeout_ms_ |
| Socket write timeout in milliseconds, 0 for none (never timeout) More... | |
Friends | |
| class | AsyncClient< MemcachedClient, QueueItem > |
| class | evo::AsyncBuffers |
| typedef AsyncClient<MemcachedClient, impl_memc::ClientQueueItem> Base |
|
inherited |
Derived protocol hander type (must inherit from AsyncClient)
|
inherited |
This type
|
inherited |
Client state.
|
inline |
Constructor to initialize client.
| max_queue_size | Max size for pending response queue |
| max_read_size | Max read buffer size, 0 for unlimited – this is used to limit the read buffer size |
Attach to a parent AsyncClient or AsyncServer and use the same event-loop as the parent.
connect*() method, otherwise this is ignored| parent | Parent to attach to |
|
inlinestatic |
Calculate memcached expiration time for given number of seconds from now.
| seconds | Number of seconds now for expiration time |
| base | Base timestamp to use, 0 for current time – only used if needed |
|
inlineinherited |
Close connection.
|
inlineinherited |
Start IP connection.
|
inline |
Send a request to decrement value for given key.
count argument will be nullon_increment=NULL then this sends a "noreply" request to tell the server not to respond to this command (reducing overhead)| key | Key to use – must not have any spaces |
| count | Count to decrement by |
| on_increment | OnIncrement handler to receive response event, NULL for none |
| on_error | OnError handler to use for unexpected errors (not used for normal fail response), NULL for none – ignored if on_increment=NULL |
|
inline |
Send a request to get value for one or more keys.
track_notfound to have the client build a list of keys not found, which is passed to OnGet::on_get_end()| key | Key(s) to get, multiple keys are space-separated |
| on_get | OnGet handler to receive response events |
| on_error | OnError handler to use for unexpected errors (not used for normal fail response), NULL for none |
| track_notfound | Whether to track keys not found (i.e. cache misses), true to enable logic that builds a list of keys not found (passed to OnGet::on_get_end()) – this adds some overhead |
| expire | Pointer to expiration time used to "touch" while getting the value by updating the expiration time, NULL to disable this
|
|
inline |
Send a request to get value for one or more keys for Compare-And-Swap.
cas_id, which can be passed to set_cas() or set() to complete the Compare-And-Swaptrack_notfound to have the client build a list of keys not found, which is passed to OnGet::on_get_end()| key | Key(s) to get, multiple keys are space-separated |
| on_get | OnGet handler to receive response events |
| on_error | OnError handler to use for unexpected errors (not used for normal fail response), NULL for none |
| track_notfound | Whether to track keys not found (i.e. cache misses), true to enable logic that builds a list of keys not found (passed to OnGet::on_get_end()) – this adds some overhead |
| expire | Pointer to expiration time used to "touch" while getting the value by updating the expiration time, NULL to disable this
|
|
inlineinherited |
Get current client ID.
|
inlineinherited |
Get current state.
|
inlinestaticprotectedinherited |
Get timeval struct pointer from timeout in milliseconds.
| out | Struct to store timeout |
| ms | Time in milliseconds to use |
out, or NULL if ms is 0
|
inline |
Send a request to get value for one or more keys and touch (update) the stored expiration time.
track_notfound to have the client build a list of keys not found, which is passed to OnGet::on_get_end()| key | Key(s) to get, multiple keys are space-separated |
| expire | New expiration time in seconds from now, 0 for no expiration, negative to expire now, or a value greater than 2592000 (30 days) means a Unix timestamp to expire on
|
| on_get | OnGet handler to receive response events |
| on_error | OnError handler to use for unexpected errors (not used for normal fail response), NULL for none |
| track_notfound | Whether to track keys not found (i.e. cache misses), true to enable logic that builds a list of keys not found (passed to OnGet::on_get_end()) – this adds some overhead |
|
inline |
Send a request to get value for one or more keys for Compare-And-Swap and touch (update) the stored expiration time.
track_notfound to have the client build a list of keys not found, which is passed to OnGet::on_get_end()| key | Key(s) to get, multiple keys are space-separated |
| expire | New expiration time in seconds from now, 0 for no expiration, negative to expire now, or a value greater than 2592000 (30 days) means a Unix timestamp to expire on
|
| on_get | OnGet handler to receive response events |
| on_error | OnError handler to use for unexpected errors (not used for normal fail response), NULL for none |
| track_notfound | Whether to track keys not found (i.e. cache misses), true to enable logic that builds a list of keys not found (passed to OnGet::on_get_end()) – this adds some overhead |
|
inline |
Send a request to increment value for given key.
count argument will be nullon_increment=NULL then this sends a "noreply" request to tell the server not to respond to this command (reducing overhead)| key | Key to use – must not have any spaces |
| count | Count to increment by |
| on_increment | OnIncrement handler to receive response event, NULL for none |
| on_error | OnError handler to use for unexpected errors (not used for normal fail response), NULL for none – ignored if on_increment=NULL |
|
inline |
Send a request to increment or decrement value for given key.
count argument will be nullon_increment=NULL then this sends a "noreply" request to tell the server not to respond to this command (reducing overhead)| key | Key to use – must not have any spaces |
| count | Count to increment or decrement by |
| decrement | Whether to decrement, false to increment |
| on_increment | OnIncrement handler to receive response event, NULL for none |
| on_error | OnError handler to use for unexpected errors (not used for normal fail response), NULL for none – ignored if on_increment=NULL |
|
inlineprotectedinherited |
Initialize event-loop.
|
inlineprotectedinherited |
Initialize and attach to a parent event-loop.
| parent | Parent AsyncBase to attach to |
|
inline |
Send a request to delete key and value.
on_remove=NULL then this sends a "noreply" request to tell the server not to respond to this command (reducing overhead)| key | Key to use – must not have any spaces |
| on_remove | OnRemove handler to receive response event, NULL for none |
| on_error | OnError handler to use for unexpected errors (not used for normal fail response), NULL for none – ignored if on_remove=NULL |
|
inlineprotectedinherited |
Run event loop and process all events and repeat until shutdown.
|
inlineprotectedinherited |
Run event loop with one pass and process all events.
|
inlineinherited |
Run the event-loop locally in current thread until all pending requests are handled (client only).
|
inline |
Send a request to set a key and value.
flags and expire time for that keyon_store=NULL then this sends a "noreply" request to tell the server not to respond to this command (reducing overhead)| key | Key to store under – must not have any spaces |
| value | New value to store |
| flags | User defined flags to store under key, 0 for none |
| expire | Expiration time in seconds from now, 0 for no expiration, negative to expire now, or a value greater than 2592000 (30 days) means a Unix timestamp to expire on
|
| cas_id | Pointer to Compare-And-Swap ID returned from get_cas() request, NULL if not doing Compare-And-Swap, otherwise this new value is stored unless:
|
| on_store | OnStore handler to receive response event, NULL for none |
| on_error | OnError handler to use for unexpected errors (not used for normal fail response), NULL for none – ignored if on_store=NULL |
|
inline |
Send a request to set a key and value.
flags and expire time for that key| key | Key to store under – must not have any spaces |
| value | New value to store |
| on_store | OnStore handler to receive response event |
| on_error | OnError handler to use for unexpected errors (not used for normal fail response), NULL for none |
| flags | User defined flags to store under key, 0 for none |
| expire | Expiration time in seconds from now, 0 for no expiration, negative to expire now, or a value greater than 2592000 (30 days) means a Unix timestamp to expire on
|
| cas_id | Pointer to Compare-And-Swap ID returned from get_cas() request, NULL if not doing Compare-And-Swap, otherwise this new value is stored unless:
|
|
inline |
Send a request to add a new key and value and fail if key already exists.
on_store=NULL then this sends a "noreply" request to tell the server not to respond to this command (reducing overhead)| key | Key to store under – must not have any spaces |
| value | New value to store |
| flags | User defined flags to store under key, 0 for none |
| expire | Expiration time in seconds from now, 0 for no expiration, negative to expire now, or a value greater than 2592000 (30 days) means a Unix timestamp to expire on
|
| on_store | OnStore handler to receive response event, NULL for none |
| on_error | OnError handler to use for unexpected errors (not used for normal fail response), NULL for none – ignored if on_store=NULL |
|
inline |
Send a request to append to existing value for key.
| key | Key to store under – must not have any spaces |
| value | New value to append to existing value |
| on_store | OnStore handler to receive response event |
| on_error | OnError handler to use for unexpected errors (not used for normal fail response), NULL for none |
|
inline |
Send a request to set a key and value using Compare-And-Swap.
flags and expire time for that keycas_id, then if needed this is used to replace that value (if it hasn't changed since)| key | Key to store under – must not have any spaces |
| value | New value to store |
| cas_id | Compare-And-Swap ID returned from get_cas() request, this new value is stored unless:
|
| on_store | OnStore handler to receive response event |
| on_error | OnError handler to use for unexpected errors (not used for normal fail response), NULL for none |
| flags | User defined flags to store under key, 0 for none |
| expire | Expiration time in seconds from now, 0 for no expiration, negative to expire now, or a value greater than 2592000 (30 days) means a Unix timestamp to expire on
|
|
inlinevirtualinherited |
Set logger to use.
| newlogger | Pointer to logger to set, NULL for none (no logging) |
|
inlineinherited |
Set general handler to call when a connection is established.
| cb | OnConnect event to use, NULL for none |
|
inlineinherited |
Set general handler to call when an unexpected error occurs.
| cb | OnError event to use, NULL for none |
|
inline |
Send a request to prepend to existing value for key.
| key | Key to store under – must not have any spaces |
| value | New value to prepend to existing value |
| on_store | OnStore handler to receive response event |
| on_error | OnError handler to use for unexpected errors (not used for normal fail response), NULL for none |
|
inline |
Send a request to replace an existing value under key and fail if key doesn't exist.
on_store=NULL then this sends a "noreply" request to tell the server not to respond to this command (reducing overhead)| key | Key to store under – must not have any spaces |
| value | New value to store |
| flags | User defined flags to store under key, 0 for none |
| expire | Expiration time in seconds from now, 0 for no expiration, negative to expire now, or a value greater than 2592000 (30 days) means a Unix timestamp to expire on
|
| on_store | OnStore handler to receive response event, NULL for none |
| on_error | OnError handler to use for unexpected errors (not used for normal fail response), NULL for none – ignored if on_store=NULL |
|
inlineinherited |
|
inlineinherited |
Activate timer so it expires after given time elapses.
| on_timer | Timer to use |
| msec | Expiration time in milliseconds |
|
inline |
Send a request to touch (update) the expiration time for given key.
on_touch=NULL then this sends a "noreply" request to tell the server not to respond to this command (reducing overhead)| key | Key to store under – must not have any spaces |
| expire | New expiration time in seconds from now, 0 for no expiration, negative to expire now, or a value greater than 2592000 (30 days) means a Unix timestamp to expire on
|
| on_touch | OnTouch handler to receive response event, NULL for none |
| on_error | OnError handler to use for unexpected errors (not used for normal fail response), NULL for none – ignored if on_store=NULL |
|
friend |
|
friend |
|
protectedinherited |
Pointer to child in AsyncBase chain (always an AsyncClient), NULL for none.
|
static |
|
static |
|
protectedinherited |
Event loop pointer, either owned by this or a parent.
|
protectedinherited |
Whether event-loop is local (same thread), false if separate thread.
|
inherited |
Logger for protocol and debug messages, set to enable logging – see set_logger()
|
static |
|
protectedinherited |
Pointer to parent in AsyncBase chain, NULL if this is the main parent (and owns evloop_ pointer)
|
protectedinherited |
Queue where each item represents an expected response from server.
|
protectedinherited |
Socket read timeout in milliseconds, 0 for none (never timeout)
|
protectedinherited |
Socket write timeout in milliseconds, 0 for none (never timeout)
1.8.13