class Memcached (View source)

Constants

OPT_PREFIX_KEY

Constants taken from http://www.php.net/manual/en/memcached.constants.php

OPT_COMPRESSION

OPT_HASH

OPT_DISTRIBUTION

OPT_BUFFER_WRITES

OPT_BINARY_PROTOCOL

OPT_NO_BLOCK

OPT_TCP_NODELAY

OPT_SOCKET_SEND_SIZE

OPT_SOCKET_RECV_SIZE

OPT_CONNECT_TIMEOUT

OPT_RETRY_TIMEOUT

OPT_SEND_TIMEOUT

OPT_RECV_TIMEOUT

OPT_POLL_TIMEOUT

OPT_CACHE_LOOKUPS

OPT_SERVER_FAILURE_LIMIT

OPT_SERIALIZER

HAVE_IGBINARY

HAVE_JSON

SERIALIZER_PHP

SERIALIZER_IGBINARY

SERIALIZER_JSON

HASH_DEFAULT

HASH_MD5

HASH_CRC

HASH_FNV1_64

HASH_FNV1A_64

HASH_FNV1_32

HASH_FNV1A_32

HASH_HSIEH

HASH_MURMUR

DISTRIBUTION_MODULA

DISTRIBUTION_CONSISTENT

OPT_LIBKETAMA_COMPATIBLE

GET_PRESERVE_ORDER

RES_SUCCESS

RES_FAILURE

RES_HOST_LOOKUP_FAILURE

RES_UNKNOWN_READ_FAILURE

RES_PROTOCOL_ERROR

RES_CLIENT_ERROR

RES_SERVER_ERROR

RES_WRITE_FAILURE

RES_DATA_EXISTS

RES_NOTSTORED

RES_NOTFOUND

RES_PARTIAL_READ

RES_SOME_ERRORS

RES_NO_SERVERS

RES_END

RES_ERRNO

RES_BUFFERED

RES_TIMEOUT

RES_BAD_KEY_PROVIDED

RES_CONNECTION_SOCKET_CREATE_FAILURE

RES_PAYLOAD_FAILURE

Methods

__construct($persistent_id = null)

No description

bool
add(string $key, mixed $value, int $expiration = 0)

add is similar to set(), but the operation fails if the key already exists on the server.

bool
addByKey(string $server_key, string $key, mixed $value, int $expiration = 0)

Memcached::addByKey() is functionally equivalent to Memcached::add(), except that the free-form server_key can be used to map the key to a specific server. This is useful if you need to keep a bunch of related keys on a certain server.

addServer($host, $port, $weight = 0)

This function is present only for compatibility and does nothing.

addServers($servers)

This function is present only for compatibility and does nothing.

append(string $key, string $value)

Memcached::append() appends the given value string to the value of an existing item. The reason that value is forced to be a string is that appending mixed types is not well-defined.

appendByKey(string $server_key, string $key, string $value)

No description

bool
cas(mixed $cas_token, string $key, mixed $value, int $expiration = 0)

Performs a set and check operation, so that the item will be stored only if no other client has updated it since it was last fetched by this client.

bool
casByKey(mixed $cas_token, string $server_key, string $key, mixed $value, int $expiration = 0)

No description

bool
decrement(string $key, int $offset = 1, int $initial_value = 0, int $expiration = 0)

Decrements a numeric item's value by $offset.

bool
decrementByKey(string $server_key, string $key, int $offset = 1, int $initial_value = 0, int $expiration = 0)

No description

bool
delete(string $key, int $time = 0)

deletes the $key from the server.

bool
deleteByKey(string $server_key, string $key, int $time = 0)

No description

bool
deleteMulti(array $keys, int $time = 0)

deletes an array of $keys from the server.

bool
deleteMultiByKey(string $server_key, array $keys, int $time = 0)

No description

The
fetch()

fetch retrieves the next result from the last getDelayed() request.

array
fetchAll()

Fetch all of the remaining results from the last getDelayed() request.

bool
flush(int $delay = 0)

Invalidates all existing cache items immediately.

the
get(string $key, callable $cache_cb = null, mixed $cas_token = null)

Returns the item that was previously stored under the $key.

getAllKeys()

This function is present only for compatibility and does nothing.

the
getByKey(string $server_key, string $key, callable $cache_cb, mixed $cas_token)

No description

bool
getDelayed(array $keys, bool $with_cas = false, callable $value_cb = null)

Issues a request to memcache for multiple items the keys of which are specified in the keys array.

bool
getDelayedByKey(string $server_key, array $keys, bool $with_cas = false, callable $value_cb = null)

No description

array
getMulti(array $keys, array $cas_tokens = null, int $flags = 0)

Similar to Memcached::get(), but instead of a single key item, it retrieves multiple items the keys of which are specified in the keys array.

array
getMultiByKey($server_key, $keys, $with_cas = false, $value_cb = null)

No description

mixed
getOption($option)

Retrieve a Memcached option value.

int
getResultCode()

Returns one of the Memcached::RES_* constants that is the result of the last executed Memcached method.

string
getResultMessage()

Return the message describing the result of the last operation.

getServerByKey($server_key)

This function is present only for compatibility and does nothing.

getServerList()

This function is present only for compatibility and does nothing.

getStats()

This function is present only for compatibility and does nothing.

getVersion()

This function is present only for compatibility and does nothing.

The
increment(string $key, int $offset = 1, int $initial_value = 0, int $expiry = 0)

Increments a numeric item's value by the specified offset. If the item's value is not numeric, and error will result.

The
incrementByKey(string $server_key, string $key, int $offset = 1, int $initial_value = 0, int $expiry = 0)

No description

isPersistent()

This function is present only for compatibility and does nothing.

isPristine()

This function is present only for compatibility and does nothing.

true
prepend(string $key, string $value)

Prepends the given value string to an existing item.

true
prependByKey(string $server_key, string $key, string $value)

No description

quit()

This function is present only for compatibility and does nothing.

true
replace(string $key, mixed $value, int $expiration = 0)

Replace is similar to Memcache::set(), but the operation will fail if the key is not found on the server.

true
replaceByKey(string $server_key, string $key, mixed $value, int $expiration = 0)

No description

resetServerList()

This function is present only for compatibility and does nothing.

true
set(string $key, mixed $value, int $expiration = 0)

Stores the value on a memcache server under the specified key. The expiration parameters can be used to control when the value is considered expired.

true
setByKey(string $server_key, string $key, mixed $value, int $expiration = 0)

No description

setMulti(array $items, int $expiration = 0)

Is similar to Memcached::set(), but instead of a single key/value item, it works on multiple items specified in items.

bool
setMultiByKey(string $server_key, array $items, int $expiration = 0)

No description

bool
setOption(int $option, mixed $value)

This method sets the vaue of a memcached option.

bool
setOptions(mixed $options)

This is a varion of Memcached::setOption() that takes an array of options to be set.

setSaslAuthData($username, $password)

This function is present only for compatibility and does nothing.

bool
touch(string $key, int $expiration = 0)

Sets a new expiration time on an item.

bool
touchByKey(string $server_key, string $key, int $expiration = 0)

Functionally equivalent to Memcached::touch().

Details

__construct($persistent_id = null)

Parameters

$persistent_id

bool add(string $key, mixed $value, int $expiration = 0)

add is similar to set(), but the operation fails if the key already exists on the server.

Parameters

string $key The key under which to store the value.
mixed $value The value to store.
int $expiration The expiration time, defaults to 0.

Return Value

bool true on success, false on failure.

See also

Memcached::set

bool addByKey(string $server_key, string $key, mixed $value, int $expiration = 0)

Memcached::addByKey() is functionally equivalent to Memcached::add(), except that the free-form server_key can be used to map the key to a specific server. This is useful if you need to keep a bunch of related keys on a certain server.

Parameters

string $server_key This parameter is ignored.
string $key The key under which to store the value.
mixed $value The value to store.
int $expiration The expiration time, defaults to 0.

Return Value

bool true on success, false on failure.

See also

Memcached::add

addServer($host, $port, $weight = 0)

This function is present only for compatibility and does nothing.

Parameters

$host
$port
$weight

addServers($servers)

This function is present only for compatibility and does nothing.

Parameters

$servers

append(string $key, string $value)

Memcached::append() appends the given value string to the value of an existing item. The reason that value is forced to be a string is that appending mixed types is not well-defined.

Parameters

string $key The key under which to append the value.
string $value The value to append

appendByKey(string $server_key, string $key, string $value)

Parameters

string $server_key This parameter is ignored.
string $key The key under which to append the value.
string $value The value to append

See also

Memcached::append

bool cas(mixed $cas_token, string $key, mixed $value, int $expiration = 0)

Performs a set and check operation, so that the item will be stored only if no other client has updated it since it was last fetched by this client.

Parameters

mixed $cas_token Unique memcached assigned value.
string $key The key under which to store the value.
mixed $value The value to store.
int $expiration The expiration time, defaults to 0.

Return Value

bool True on success, or false on failure.

bool casByKey(mixed $cas_token, string $server_key, string $key, mixed $value, int $expiration = 0)

Parameters

mixed $cas_token Unique memcached assigned value.
string $server_key Ignored.
string $key The key under which to store the value.
mixed $value The value to store.
int $expiration The expiration time, defaults to 0.

Return Value

bool True on success, or false on failure.

See also

Memcached::cas

bool decrement(string $key, int $offset = 1, int $initial_value = 0, int $expiration = 0)

Decrements a numeric item's value by $offset.

Parameters

string $key The key under which to store the value.
int $offset The amount by which to decrement the item's value.
int $initial_value The value to set the item to if it does not currently exist.
int $expiration The expiration time, defaults to 0.

Return Value

bool True on success, or false on failure.

bool decrementByKey(string $server_key, string $key, int $offset = 1, int $initial_value = 0, int $expiration = 0)

Parameters

string $server_key This parameter is ignored.
string $key The key under which to store the value.
int $offset The amount by which to decrement the item's value.
int $initial_value The value to set the item to if it does not currently exist.
int $expiration The expiration time, defaults to 0.

Return Value

bool True on success, or false on failure.

See also

Memcached::decrement

bool delete(string $key, int $time = 0)

deletes the $key from the server.

Parameters

string $key The key to delete from the server.
int $time The time parameter is the amount of time in seconds the client wishes the server to refuse add and replace commands for this key.

Return Value

bool true on success or false on failure.

bool deleteByKey(string $server_key, string $key, int $time = 0)

Parameters

string $server_key This parameter is ignored.
string $key The key to delete from the server.
int $time The time parameter is the amount of time in seconds the client wishes the server to refuse add and replace commands for this key.

Return Value

bool true on success or false on failure.

See also

Memcached::delete

bool deleteMulti(array $keys, int $time = 0)

deletes an array of $keys from the server.

Parameters

array $keys The keys to delete from the server.
int $time The time parameter is the amount of time in seconds the client wishes the server to refuse add and replace commands for this key.

Return Value

bool true on success or false on failure.

bool deleteMultiByKey(string $server_key, array $keys, int $time = 0)

Parameters

string $server_key This parameter is ignored.
array $keys The keys to delete from the server.
int $time The time parameter is the amount of time in seconds the client wishes the server to refuse add and replace commands for this key.

Return Value

bool true on success or false on failure.

See also

Memcache::deleteMulti().

The fetch()

fetch retrieves the next result from the last getDelayed() request.

Note that currently getDelayed is a synchronous call.

Return Value

The next result, or false if there are no more results.

array fetchAll()

Fetch all of the remaining results from the last getDelayed() request.

Note that currently getDelayed is a synchronous call.

Return Value

array The remaining results, or false if there are no results.

bool flush(int $delay = 0)

Invalidates all existing cache items immediately.

Parameters

int $delay This parameter is ignored.

Return Value

bool true on success, or false on failure.

the get(string $key, callable $cache_cb = null, mixed $cas_token = null)

Returns the item that was previously stored under the $key.

Parameters

string $key The key under which to store the value.
callable $cache_cb Read through caching callback.
mixed $cas_token The variable to store the CAS token in. This value is opaque to the application.

Return Value

the value stored in the cache of false if there was a failure.

getAllKeys()

This function is present only for compatibility and does nothing.

the getByKey(string $server_key, string $key, callable $cache_cb, mixed $cas_token)

Parameters

string $server_key This parameter is ignored.
string $key The key under which to store the value.
callable $cache_cb Read through caching callback.
mixed $cas_token The variable to store the CAS token in. This value is opaque to the application.

Return Value

the value stored in the cache of false if there was a failure.

See also

Memcache::get

bool getDelayed(array $keys, bool $with_cas = false, callable $value_cb = null)

Issues a request to memcache for multiple items the keys of which are specified in the keys array.

Currently this method executes synchronously.

Parameters

array $keys Array of keys to retrieve.
bool $with_cas If true, retrieve the CAS tokens for the keys.
callable $value_cb The result callback.

Return Value

bool true on success, or false on failure.

bool getDelayedByKey(string $server_key, array $keys, bool $with_cas = false, callable $value_cb = null)

Parameters

string $server_key This parameter is ignored.
array $keys Array of keys to retrieve.
bool $with_cas If true, retrieve the CAS tokens for the keys.
callable $value_cb The result callback.

Return Value

bool true on success, or false on failure.

See also

getDelayedByKey.

array getMulti(array $keys, array $cas_tokens = null, int $flags = 0)

Similar to Memcached::get(), but instead of a single key item, it retrieves multiple items the keys of which are specified in the keys array.

Parameters

array $keys Array of keys to retrieve.
array $cas_tokens The variable to store the CAS tokens for found items.
int $flags The flags for the get operation.

Return Value

array The array of found items for false on failure.

See also

Memcached::get

array getMultiByKey($server_key, $keys, $with_cas = false, $value_cb = null)

Parameters

$server_key
$keys
$with_cas
$value_cb

Return Value

array The array of found items for false on failure.

See also

Memcached::getMulti

mixed getOption($option)

Retrieve a Memcached option value.

Parameters

$option

Return Value

mixed the value of the requested option, of false on error.

int getResultCode()

Returns one of the Memcached::RES_* constants that is the result of the last executed Memcached method.

Return Value

int The result code of the last memcached operation.

string getResultMessage()

Return the message describing the result of the last operation.

Return Value

string Message describing the result of the last operation.

getServerByKey($server_key)

This function is present only for compatibility and does nothing.

Parameters

$server_key

getServerList()

This function is present only for compatibility and does nothing.

getStats()

This function is present only for compatibility and does nothing.

getVersion()

This function is present only for compatibility and does nothing.

The increment(string $key, int $offset = 1, int $initial_value = 0, int $expiry = 0)

Increments a numeric item's value by the specified offset. If the item's value is not numeric, and error will result.

Parameters

string $key The key of the item to increment
int $offset The amount by which to increment the item's value
int $initial_value The value to set the item to if it doesn't exist.
int $expiry The expiry time to set on the item.

Return Value

The new item's value on success or false on failure.

The incrementByKey(string $server_key, string $key, int $offset = 1, int $initial_value = 0, int $expiry = 0)

Parameters

string $server_key This parameter is ignored.
string $key The key of the item to increment
int $offset The amount by which to increment the item's value
int $initial_value The value to set the item to if it doesn't exist.
int $expiry The expiry time to set on the item.

Return Value

The new item's value on success or false on failure.

See also

Memcached::increment

isPersistent()

This function is present only for compatibility and does nothing.

isPristine()

This function is present only for compatibility and does nothing.

true prepend(string $key, string $value)

Prepends the given value string to an existing item.

Parameters

string $key The key under which to store the value.
string $value The string to prepend.

Return Value

true on success or false on failure.

true prependByKey(string $server_key, string $key, string $value)

Parameters

string $server_key This parameter is ignored.
string $key The key under which to store the value.
string $value The string to prepend.

Return Value

true on success or false on failure.

See also

Memcached::prepend

quit()

This function is present only for compatibility and does nothing.

true replace(string $key, mixed $value, int $expiration = 0)

Replace is similar to Memcache::set(), but the operation will fail if the key is not found on the server.

Parameters

string $key The key under which to store the value.
mixed $value The value to store.
int $expiration The expiration time, defaults to 0.

Return Value

true if the method succeeds, false on failure.

true replaceByKey(string $server_key, string $key, mixed $value, int $expiration = 0)

Parameters

string $server_key This parameter is ignored.
string $key The key under which to store the value.
mixed $value The value to store.
int $expiration The expiration time, defaults to 0.

Return Value

true if the method succeeds, false on failure.

See also

Memcached::replace

resetServerList()

This function is present only for compatibility and does nothing.

true set(string $key, mixed $value, int $expiration = 0)

Stores the value on a memcache server under the specified key. The expiration parameters can be used to control when the value is considered expired.

Parameters

string $key The key under which to store the value.
mixed $value The value to store.
int $expiration The expiration time, defaults to 0.

Return Value

true if the method succeeds, false on failure.

true setByKey(string $server_key, string $key, mixed $value, int $expiration = 0)

Parameters

string $server_key This parameter is ignored.
string $key The key under which to store the value.
mixed $value The value to store.
int $expiration The expiration time, defaults to 0.

Return Value

true if the method succeeds, false on failure.

See also

Memcached::set

setMulti(array $items, int $expiration = 0)

Is similar to Memcached::set(), but instead of a single key/value item, it works on multiple items specified in items.

Parameters

array $items An array of key value pairs to set.
int $expiration The expiration time to set for the value.

returns bool true if the call succeeds, false otherwise.

See also

Memcached::set

bool setMultiByKey(string $server_key, array $items, int $expiration = 0)

Parameters

string $server_key This parameter is ignored.
array $items An array of key value pairs to set.
int $expiration The expiration time to set for the value.

Return Value

bool true if the call succeeds, false otherwise.

See also

Memcached::setMulti

bool setOption(int $option, mixed $value)

This method sets the vaue of a memcached option.

Parameters

int $option The option to set.
mixed $value The value to set the option to.

Return Value

bool true if the call succeeds, false otherwise.

bool setOptions(mixed $options)

This is a varion of Memcached::setOption() that takes an array of options to be set.

Parameters

mixed $options An associated array of options.

Return Value

bool true if the call succeeds, false otherwise.

setSaslAuthData($username, $password)

This function is present only for compatibility and does nothing.

Parameters

$username
$password

bool touch(string $key, int $expiration = 0)

Sets a new expiration time on an item.

Parameters

string $key The key under which to append the value.
int $expiration The expiration time, defaults to 0.

Return Value

bool true on success or false on failure.

bool touchByKey(string $server_key, string $key, int $expiration = 0)

Functionally equivalent to Memcached::touch().

Parameters

string $server_key This parameter is ignored.
string $key The key under which to append the value.
int $expiration The expiration time, defaults to 0.

Return Value

bool true on success or false on failure.