Evo C++ Library v0.5.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
MemcachedClient Class Reference

#include <evo/async/memcached_client.h>

Inheritance diagram for MemcachedClient:
Inheritance graph
[legend]

Detailed Description

Implements Memcached protocol for an async client.

Usage:

Example
#include <evo/io.h>
using namespace evo;
void on_connect() {
con().out << "on_connect()" << NL;
}
void on_store(const SubString& key, Memcached::StoreResult result) {
con().out << "on_store() " << key << ' ' << Memcached::StoreResultEnum::get_string(result) << NL;
}
void on_get(const SubString& key, const SubString& value, uint32 flags) {
con().out << "on_get() " << key << " '" << value << "' " << flags << NL;
}
};
int main() {
const ushort MEMC_PORT = 11211;
OnEvent on_event;
memc.set_on_connect(&on_event);
memc.connect_ip("127.0.0.1", MEMC_PORT);
memc.set("key1", "value1", on_event);
memc.set("key2", "value2", on_event);
memc.runlocal();
memc.get("key1", on_event);
memc.get("key2", on_event);
memc.runlocal();
return 0;
}

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...
 
Thisattach_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...
 
Thisset_on_connect (OnConnect *cb)
 Set general handler to call when a connection is established. More...
 
Thisset_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

AsyncBasechild_base_
 Pointer to child in AsyncBase chain (always an AsyncClient), NULL for none. More...
 
AsyncEventLoopevloop_
 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...
 
AsyncBaseparent_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
 

Member Typedef Documentation

◆ Base

typedef AsyncClient<MemcachedClient, impl_memc::ClientQueueItem> Base

◆ ProtocolHandler

typedef MemcachedClient ProtocolHandler
inherited

Derived protocol hander type (must inherit from AsyncClient)

◆ This

typedef AsyncClient<MemcachedClient ,impl_memc::ClientQueueItem > This
inherited

This type

Member Enumeration Documentation

◆ State

enum State
inherited

Client state.

Constructor & Destructor Documentation

◆ MemcachedClient()

MemcachedClient ( SizeT  max_queue_size = DEFAULT_QUEUE_SIZE,
SizeT  max_read_size = DEFAULT_MAX_READ 
)
inline

Constructor to initialize client.

Parameters
max_queue_sizeMax size for pending response queue
max_read_sizeMax read buffer size, 0 for unlimited – this is used to limit the read buffer size

Member Function Documentation

◆ attach_to()

This& attach_to ( AsyncBase parent)
inlineinherited

Attach to a parent AsyncClient or AsyncServer and use the same event-loop as the parent.

  • This must be called before any connect*() method, otherwise this is ignored
Parameters
parentParent to attach to
Returns
This

◆ calc_expire_time()

static int64 calc_expire_time ( int64  seconds,
int64  base = 0 
)
inlinestatic

Calculate memcached expiration time for given number of seconds from now.

  • This returns an expiration value understood by memcached servers: number of seconds from now, or a value greater than 2592000 (30 days) means a Unix timestamp to expire on
Parameters
secondsNumber of seconds now for expiration time
baseBase timestamp to use, 0 for current time – only used if needed
Returns
Expiration time value for memcached

◆ close()

void close ( )
inlineinherited

Close connection.

  • This must not be called from an event handler

◆ connect_ip()

bool connect_ip ( const char *  host,
ushort  port,
int  family = AF_INET 
)
inlineinherited

Start IP connection.

  • This is non-blocking and returns immediately while connecting

◆ decr()

bool decr ( const SubString key,
uint64  count = 1,
OnIncrement on_increment = NULL,
OnError *  on_error = NULL 
)
inline

Send a request to decrement value for given key.

  • If key doesn't exist then the response event count argument will be null
  • If value for key is not an integer, the server will return a CLIENT_ERROR and on_error will be called (if not NULL)
  • If on_increment=NULL then this sends a "noreply" request to tell the server not to respond to this command (reducing overhead)
Parameters
keyKey to use – must not have any spaces
countCount to decrement by
on_incrementOnIncrement handler to receive response event, NULL for none
on_errorOnError handler to use for unexpected errors (not used for normal fail response), NULL for none – ignored if on_increment=NULL
Returns
Whether successful, false if unable to send request due to internal error (usually means not connected and no connection in progress)

◆ get()

bool get ( const SubString key,
OnGet on_get,
OnError *  on_error = NULL,
bool  track_notfound = false,
int64 *  expire = NULL 
)
inline

Send a request to get value for one or more keys.

  • The server only sends back responses for keys that were found, so noting which keys weren't found (cache misses) requires some overhead:
    • Use track_notfound to have the client build a list of keys not found, which is passed to OnGet::on_get_end()
Parameters
keyKey(s) to get, multiple keys are space-separated
on_getOnGet handler to receive response events
on_errorOnError handler to use for unexpected errors (not used for normal fail response), NULL for none
track_notfoundWhether 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
expirePointer to expiration time used to "touch" while getting the value by updating the expiration time, NULL to disable this
  • Expiration time is 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
  • See calc_expire_time() helper
Returns
Whether successful, false if unable to send request due to internal error (usually means not connected and no connection in progress)

◆ get_cas()

bool get_cas ( const SubString key,
OnGet on_get,
OnError *  on_error = NULL,
bool  track_notfound = false,
int64 *  expire = NULL 
)
inline

Send a request to get value for one or more keys for Compare-And-Swap.

  • Responses here will include a cas_id, which can be passed to set_cas() or set() to complete the Compare-And-Swap
  • The server only sends back responses for keys that were found, so noting which keys weren't found (cache misses) requires some overhead:
    • Use track_notfound to have the client build a list of keys not found, which is passed to OnGet::on_get_end()
Parameters
keyKey(s) to get, multiple keys are space-separated
on_getOnGet handler to receive response events
on_errorOnError handler to use for unexpected errors (not used for normal fail response), NULL for none
track_notfoundWhether 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
expirePointer to expiration time used to "touch" while getting the value by updating the expiration time, NULL to disable this
  • Expiration time is 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
  • See calc_expire_time() helper
Returns
Whether successful, false if unable to send request due to internal error (usually means not connected and no connection in progress)

◆ get_id()

ulong get_id ( ) const
inlineinherited

Get current client ID.

Returns
Client ID

◆ get_state()

State get_state ( ) const
inlineinherited

Get current state.

Returns
Current state

◆ get_timeout_ptr()

static struct timeval* get_timeout_ptr ( struct timeval &  out,
ulong  ms 
)
inlinestaticprotectedinherited

Get timeval struct pointer from timeout in milliseconds.

Parameters
outStruct to store timeout
msTime in milliseconds to use
Returns
Pointer to out, or NULL if ms is 0

◆ get_touch()

bool get_touch ( const SubString key,
int64  expire,
OnGet on_get,
OnError *  on_error = NULL,
bool  track_notfound = false 
)
inline

Send a request to get value for one or more keys and touch (update) the stored expiration time.

  • The server only sends back responses for keys that were found, so noting which keys weren't found (cache misses) requires some overhead:
    • Use track_notfound to have the client build a list of keys not found, which is passed to OnGet::on_get_end()
Parameters
keyKey(s) to get, multiple keys are space-separated
expireNew 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_getOnGet handler to receive response events
on_errorOnError handler to use for unexpected errors (not used for normal fail response), NULL for none
track_notfoundWhether 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
Returns
Whether successful, false if unable to send request due to internal error (usually means not connected and no connection in progress)

◆ get_touch_cas()

bool get_touch_cas ( const SubString key,
int64  expire,
OnGet on_get,
OnError *  on_error = NULL,
bool  track_notfound = false 
)
inline

Send a request to get value for one or more keys for Compare-And-Swap and touch (update) the stored expiration time.

  • The server only sends back responses for keys that were found, so noting which keys weren't found (cache misses) requires some overhead:
    • Use track_notfound to have the client build a list of keys not found, which is passed to OnGet::on_get_end()
Parameters
keyKey(s) to get, multiple keys are space-separated
expireNew 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_getOnGet handler to receive response events
on_errorOnError handler to use for unexpected errors (not used for normal fail response), NULL for none
track_notfoundWhether 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
Returns
Whether successful, false if unable to send request due to internal error (usually means not connected and no connection in progress)

◆ incr()

bool incr ( const SubString key,
uint64  count = 1,
OnIncrement on_increment = NULL,
OnError *  on_error = NULL 
)
inline

Send a request to increment value for given key.

  • If key doesn't exist then the response event count argument will be null
  • If value for key is not an integer, the server will return a CLIENT_ERROR and on_error will be called (if not NULL)
  • If on_increment=NULL then this sends a "noreply" request to tell the server not to respond to this command (reducing overhead)
Parameters
keyKey to use – must not have any spaces
countCount to increment by
on_incrementOnIncrement handler to receive response event, NULL for none
on_errorOnError handler to use for unexpected errors (not used for normal fail response), NULL for none – ignored if on_increment=NULL
Returns
Whether successful, false if unable to send request due to internal error (usually means not connected and no connection in progress)

◆ increment()

bool increment ( const SubString key,
uint64  count = 1,
bool  decrement = false,
OnIncrement on_increment = NULL,
OnError *  on_error = NULL 
)
inline

Send a request to increment or decrement value for given key.

  • If key doesn't exist then the response event count argument will be null
  • If value for key is not an integer, the server will return a CLIENT_ERROR and on_error will be called (if not NULL)
  • If on_increment=NULL then this sends a "noreply" request to tell the server not to respond to this command (reducing overhead)
Parameters
keyKey to use – must not have any spaces
countCount to increment or decrement by
decrementWhether to decrement, false to increment
on_incrementOnIncrement handler to receive response event, NULL for none
on_errorOnError handler to use for unexpected errors (not used for normal fail response), NULL for none – ignored if on_increment=NULL
Returns
Whether successful, false if unable to send request due to internal error (usually means not connected and no connection in progress)

◆ init()

void init ( )
inlineprotectedinherited

Initialize event-loop.

  • Ignored if already initialized

◆ init_attach()

void init_attach ( AsyncBase parent)
inlineprotectedinherited

Initialize and attach to a parent event-loop.

  • Ignored if already initialized
Parameters
parentParent AsyncBase to attach to

◆ remove()

bool remove ( const SubString key,
OnRemove on_remove = NULL,
OnError *  on_error = NULL 
)
inline

Send a request to delete key and value.

  • If on_remove=NULL then this sends a "noreply" request to tell the server not to respond to this command (reducing overhead)
Parameters
keyKey to use – must not have any spaces
on_removeOnRemove handler to receive response event, NULL for none
on_errorOnError handler to use for unexpected errors (not used for normal fail response), NULL for none – ignored if on_remove=NULL
Returns
Whether successful, false if unable to send request due to internal error (usually means not connected and no connection in progress)

◆ run_eventloop()

bool run_eventloop ( )
inlineprotectedinherited

Run event loop and process all events and repeat until shutdown.

Returns
Whether successful, false on internal error

◆ run_eventloop_once()

bool run_eventloop_once ( )
inlineprotectedinherited

Run event loop with one pass and process all events.

  • This waits until some events are active then processes all active events and returns
Returns
Whether successful, false on internal error

◆ runlocal()

bool runlocal ( )
inlineinherited

Run the event-loop locally in current thread until all pending requests are handled (client only).

  • This blocks while client requests are pending
  • This returns false immediately if this does not own an event-loop (i.e. was attached to a parent) – only the top parent can run an event-loop
Returns
Whether successful, false if attached to another AsyncBase or on internal error

◆ set() [1/2]

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 
)
inline

Send a request to set a key and value.

  • This replaces the previous value for given key, and overwrites flags and expire time for that key
  • If on_store=NULL then this sends a "noreply" request to tell the server not to respond to this command (reducing overhead)
Parameters
keyKey to store under – must not have any spaces
valueNew value to store
flagsUser defined flags to store under key, 0 for none
expireExpiration 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_idPointer 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_storeOnStore handler to receive response event, NULL for none
on_errorOnError handler to use for unexpected errors (not used for normal fail response), NULL for none – ignored if on_store=NULL
Returns
Whether successful, false if unable to send request due to internal error (usually means not connected and no connection in progress)

◆ set() [2/2]

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 
)
inline

Send a request to set a key and value.

  • This replaces the previous value for given key, and overwrites flags and expire time for that key
Parameters
keyKey to store under – must not have any spaces
valueNew value to store
on_storeOnStore handler to receive response event
on_errorOnError handler to use for unexpected errors (not used for normal fail response), NULL for none
flagsUser defined flags to store under key, 0 for none
expireExpiration 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_idPointer to Compare-And-Swap ID returned from get_cas() request, NULL if not doing Compare-And-Swap, otherwise this new value is stored unless:
Returns
Whether successful, false if unable to send request due to internal error (usually means not connected and no connection in progress)

◆ set_add()

bool set_add ( const SubString key,
const SubString value,
uint32  flags = 0,
int64  expire = 0,
OnStore on_store = NULL,
OnError *  on_error = NULL 
)
inline

Send a request to add a new key and value and fail if key already exists.

  • If key already exists then nothing is stored and the response will be Memcached::srNOT_STORED
  • If on_store=NULL then this sends a "noreply" request to tell the server not to respond to this command (reducing overhead)
Parameters
keyKey to store under – must not have any spaces
valueNew value to store
flagsUser defined flags to store under key, 0 for none
expireExpiration 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_storeOnStore handler to receive response event, NULL for none
on_errorOnError handler to use for unexpected errors (not used for normal fail response), NULL for none – ignored if on_store=NULL
Returns
Whether successful, false if unable to send request due to internal error (usually means not connected and no connection in progress)

◆ set_append()

bool set_append ( const SubString key,
const SubString value,
OnStore on_store = NULL,
OnError *  on_error = NULL 
)
inline

Send a request to append to existing value for key.

  • This appends to the current value for given key
  • If key doesn't exist then the response will be Memcached::srNOT_STORED
Parameters
keyKey to store under – must not have any spaces
valueNew value to append to existing value
on_storeOnStore handler to receive response event
on_errorOnError handler to use for unexpected errors (not used for normal fail response), NULL for none
Returns
Whether successful, false if unable to send request due to internal error (usually means not connected and no connection in progress)

◆ set_cas()

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 
)
inline

Send a request to set a key and value using Compare-And-Swap.

  • This replaces the previous value for given key, and overwrites flags and expire time for that key
  • get_cas() should be called first to check the current value and cas_id, then if needed this is used to replace that value (if it hasn't changed since)
Parameters
keyKey to store under – must not have any spaces
valueNew value to store
cas_idCompare-And-Swap ID returned from get_cas() request, this new value is stored unless:
on_storeOnStore handler to receive response event
on_errorOnError handler to use for unexpected errors (not used for normal fail response), NULL for none
flagsUser defined flags to store under key, 0 for none
expireExpiration 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
Returns
Whether successful, false if unable to send request due to internal error (usually means not connected and no connection in progress)

◆ set_logger()

virtual void set_logger ( LoggerBase newlogger)
inlinevirtualinherited

Set logger to use.

  • If set, a logger shows low-level details and error information from the framework
  • The logger pointer must remain valid as long as it's referenced here
Parameters
newloggerPointer to logger to set, NULL for none (no logging)

◆ set_on_connect()

This& set_on_connect ( OnConnect *  cb)
inlineinherited

Set general handler to call when a connection is established.

Parameters
cbOnConnect event to use, NULL for none
Returns
This

◆ set_on_error()

This& set_on_error ( OnError *  cb)
inlineinherited

Set general handler to call when an unexpected error occurs.

Parameters
cbOnError event to use, NULL for none
Returns
This

◆ set_prepend()

bool set_prepend ( const SubString key,
const SubString value,
OnStore on_store = NULL,
OnError *  on_error = NULL 
)
inline

Send a request to prepend to existing value for key.

  • This prepends to the current value for given key
  • If key doesn't exist then the response will be Memcached::srNOT_STORED
Parameters
keyKey to store under – must not have any spaces
valueNew value to prepend to existing value
on_storeOnStore handler to receive response event
on_errorOnError handler to use for unexpected errors (not used for normal fail response), NULL for none
Returns
Whether successful, false if unable to send request due to internal error (usually means not connected and no connection in progress)

◆ set_replace()

bool set_replace ( const SubString key,
const SubString value,
uint32  flags = 0,
int64  expire = 0,
OnStore on_store = NULL,
OnError *  on_error = NULL 
)
inline

Send a request to replace an existing value under key and fail if key doesn't exist.

  • If key doesn't exist then nothing is stored and the response will be Memcached::srNOT_STORED
  • If on_store=NULL then this sends a "noreply" request to tell the server not to respond to this command (reducing overhead)
Parameters
keyKey to store under – must not have any spaces
valueNew value to store
flagsUser defined flags to store under key, 0 for none
expireExpiration 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_storeOnStore handler to receive response event, NULL for none
on_errorOnError handler to use for unexpected errors (not used for normal fail response), NULL for none – ignored if on_store=NULL
Returns
Whether successful, false if unable to send request due to internal error (usually means not connected and no connection in progress)

◆ set_timeout()

void set_timeout ( ulong  read_timeout_ms = 0,
ulong  write_timeout_ms = 0 
)
inlineinherited

Set read/write timeouts to use.

Parameters
read_timeout_msSocket read timeout in milliseconds, 0 for none (never timeout)
write_timeout_msSocket write timeout in milliseconds, 0 for none (never timeout)

◆ set_timer()

bool set_timer ( OnTimer on_timer,
ulong  msec 
)
inlineinherited

Activate timer so it expires after given time elapses.

Parameters
on_timerTimer to use
msecExpiration time in milliseconds
Returns
Whether successful, false on internal error

◆ touch()

bool touch ( const SubString key,
int64  expire,
OnTouch on_touch,
OnError *  on_error = NULL 
)
inline

Send a request to touch (update) the expiration time for given key.

  • If on_touch=NULL then this sends a "noreply" request to tell the server not to respond to this command (reducing overhead)
Parameters
keyKey to store under – must not have any spaces
expireNew 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_touchOnTouch handler to receive response event, NULL for none
on_errorOnError handler to use for unexpected errors (not used for normal fail response), NULL for none – ignored if on_store=NULL
Returns
Whether successful, false if unable to send request due to internal error (usually means not connected and no connection in progress)

Friends And Related Function Documentation

◆ AsyncClient< MemcachedClient, QueueItem >

friend class AsyncClient< MemcachedClient, QueueItem >
friend

◆ evo::AsyncBuffers

friend class evo::AsyncBuffers
friend

Member Data Documentation

◆ child_base_

AsyncBase* child_base_
protectedinherited

Pointer to child in AsyncBase chain (always an AsyncClient), NULL for none.

◆ DEFAULT_MAX_READ

const size_t DEFAULT_MAX_READ = 524288
static

◆ DEFAULT_QUEUE_SIZE

const SizeT DEFAULT_QUEUE_SIZE = 256
static

◆ evloop_

AsyncEventLoop* evloop_
protectedinherited

Event loop pointer, either owned by this or a parent.

◆ local_

bool local_
protectedinherited

Whether event-loop is local (same thread), false if separate thread.

◆ logger

LoggerPtr logger
inherited

Logger for protocol and debug messages, set to enable logging – see set_logger()

◆ MIN_INITIAL_READ

const size_t MIN_INITIAL_READ = 0
static

◆ parent_base_

AsyncBase* parent_base_
protectedinherited

Pointer to parent in AsyncBase chain, NULL if this is the main parent (and owns evloop_ pointer)

◆ queue_

AtomicBufferQueue<QueueItem> queue_
protectedinherited

Queue where each item represents an expected response from server.

◆ read_timeout_ms_

ulong read_timeout_ms_
protectedinherited

Socket read timeout in milliseconds, 0 for none (never timeout)

◆ write_timeout_ms_

ulong write_timeout_ms_
protectedinherited

Socket write timeout in milliseconds, 0 for none (never timeout)


The documentation for this class was generated from the following file: