\yrmcdsClient

Memcached client class.

Instances of this class represents a connection to a memcached/yrmcds server. Most methods may throw \yrmcds\Error when a non-recoverable error happens.

Summary

Methods
Properties
Constants
__construct()
setTimeout()
recv()
noop()
get()
getk()
getTouch()
getkTouch()
lockGet()
lockGetk()
touch()
set()
replace()
add()
replaceUnlock()
incr()
incr2()
decr()
decr2()
append()
prepend()
delete()
lock()
unlock()
unlockAll()
flush()
statGeneral()
statSettings()
statItems()
statSizes()
keys()
version()
quit()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

__construct()

__construct(string  $node, integer  $port = 11211, string  $persist_id = NULL, string  $prefix = NULL) 

Constructor.

If $persist_id is NULL, a new connection is established. Otherwise, a persistent connection may be reused.

If $prefix is not NULL, keys will automatically be prefixed with the specified prefix string.

Parameters

string $node

The hostname or IP address of the server.

integer $port

The port number.

string $persist_id

Persistent connection ID.

string $prefix

Auto-prefix for keys.

setTimeout()

setTimeout(integer  $timeout) : void

Set socket timeouts.

Normally, socket operations may time out as specified in yrmcds.default_timeout ini parameter. This method can change timeout temporarily during a request.

Parameters

integer $timeout

The timeout seconds. 0 disables timeout.

recv()

recv() : \yrmcds\Response

Receive a command response.

This method receives a command response. Be warned that commands issued quietly may return a response to tell errors. Also note that statistics commands such as statGeneral() returns a series of response packets.

Returns

\yrmcds\Response

noop()

noop() : integer

Send `Noop` command.

This command can finalize a series of get request issued quietly (i.e. $quiet = TRUE) because the server must send a response for this.

Returns

integer —

The serial number of the request.

get()

get(string  $key, boolean  $quiet = FALSE) : integer

Send `Get` or `GetQ` command to retrieve an object.

This command sends a request to retrieve the object data associated with key. If $quiet is TRUE, the server will not return a response if the object is not found.

The successful response will not contain the key. To include the requested key in the response, use getk().

Parameters

string $key

The key string.

boolean $quiet

TRUE to suppress a successful response.

Returns

integer —

The serial number of the request.

getk()

getk(string  $key, boolean  $quiet = FALSE) : integer

Send `GetK` or `GetKQ` command to retrieve an object.

Like get(), but the successful response contains the requested key.

Parameters

string $key

The key string.

boolean $quiet

TRUE to suppress a successful response.

Returns

integer —

The serial number of the request.

getTouch()

getTouch(string  $key, integer  $expire, boolean  $quiet = FALSE) : integer

Send `GaT` or `GaTQ` command to retrieve and touch an object.

Like get(), but this command resets the object's expiration time.

Parameters

string $key

The key string.

integer $expire

Expiration time in seconds. 0 disables expiration.

boolean $quiet

TRUE to suppress a successful response.

Returns

integer —

The serial number of the request.

getkTouch()

getkTouch(string  $key, integer  $expire, boolean  $quiet = FALSE) : integer

Send `GaTK` or `GaTKQ` command to retrieve and touch an object.

Like getTouch(), but the successful response contains the requested key.

Parameters

string $key

The key string.

integer $expire

Expiration time in seconds. 0 disables expiration.

boolean $quiet

TRUE to suppress a successful response.

Returns

integer —

The serial number of the request.

lockGet()

lockGet(string  $key, boolean  $quiet = FALSE) : integer

Send `LaG` or `LaGQ` command to lock and retrieve an object.

Like get(), but this command first locks the object.

Parameters

string $key

The key string.

boolean $quiet

TRUE to suppress a successful response.

Returns

integer —

The serial number of the request.

lockGetk()

lockGetk(string  $key, boolean  $quiet = FALSE) : integer

Send `LaGK` or `LaGKQ` command to lock and retrieve an object.

Like lockGet(), but the successful response contains the requested key.

Parameters

string $key

The key string.

boolean $quiet

TRUE to suppress a successful response.

Returns

integer —

The serial number of the request.

touch()

touch(string  $key, integer  $expire, boolean  $quiet = FALSE) : integer

Send `Touch` command to retrieve and touch an object.

This command resets the object's expiration time.

Parameters

string $key

The key string.

integer $expire

Expiration time in seconds. 0 disables expiration.

boolean $quiet

Ignored (reserved).

Returns

integer —

The serial number of the request.

set()

set(string  $key, integer|string  $data, integer  $flags, integer  $expire, integer  $cas, boolean  $quiet = FALSE) : integer

Send `Set` or `SetQ` command to store an object.

This command adds or replaces an object.

$key and $data must not be an empty string.

Lower 30 bits of $flags can be used freely. Other bits are reserved for the underlying library routines.

If $cas is not 0, the operation will succeed only when the CAS value of the object is the same as $cas.

Parameters

string $key

The key string.

integer|string $data

Data to be stored.

integer $flags

Flags stored along with the data.

integer $expire

Expiration time in seconds. 0 disables expiration.

integer $cas

Non-zero enables compare-and-swap.

boolean $quiet

TRUE to suppress a successful response.

Returns

integer —

The serial number of the request.

replace()

replace(string  $key, integer|string  $data, integer  $flags, integer  $expire, integer  $cas, boolean  $quiet = FALSE) : integer

Send `Replace` or `ReplaceQ` command to replace an existing object.

Like set(), but this method only replaces an existing object. If there is not an object for $key, an error response will be returned.

Parameters

string $key

The key string.

integer|string $data

Data to be stored.

integer $flags

Flags stored along with the data.

integer $expire

Expiration time in seconds. 0 disables expiration.

integer $cas

Non-zero enables compare-and-swap.

boolean $quiet

TRUE to suppress a successful response.

Returns

integer —

The serial number of the request.

add()

add(string  $key, integer|string  $data, integer  $flags, integer  $expire, integer  $cas, boolean  $quiet = FALSE) : integer

Send `Add` or `AddQ` command to replace an existing object.

Like set(), but this method only stores a new object. If there is already an object for $key, an error response will be returned.

Parameters

string $key

The key string.

integer|string $data

Data to be stored.

integer $flags

Flags stored along with the data.

integer $expire

Expiration time in seconds. 0 disables expiration.

integer $cas

Non-zero enables compare-and-swap.

boolean $quiet

TRUE to suppress a successful response.

Returns

integer —

The serial number of the request.

replaceUnlock()

replaceUnlock(string  $key, integer|string  $data, integer  $flags, integer  $expire, boolean  $quiet = FALSE) : integer

Send `RaU` or `RaUQ` command to replace and unlock an existing object.

This command will fail unless the object has been locked by this client.

Locked object will neither be expired nor evicted, ensuring this command will succeed. After replacing the data, the object will be unlocked.

Parameters

string $key

The key string.

integer|string $data

Data to be stored.

integer $flags

Flags stored along with the data.

integer $expire

Expiration time in seconds. 0 disables expiration.

boolean $quiet

TRUE to suppress a successful response.

Returns

integer —

The serial number of the request.

incr()

incr(string  $key, integer  $value, boolean  $quiet = FALSE) : integer

Send `Increment` or `IncrementQ` command to increment an object's value.

Increments an object's value. If the object data is not numeric, this command will fail.

Parameters

string $key

The key string.

integer $value

Amount to increment.

boolean $quiet

TRUE to suppress a successful response.

Returns

integer —

The serial number of the request.

incr2()

incr2(string  $key, integer  $value, integer  $initial, integer  $expire, boolean  $quiet = FALSE) : integer

Send `Increment` or `IncrementQ` command to increment an object's value.

Like incr(), but this can create an object if no object for $key exists.

Parameters

string $key

The key string.

integer $value

Amount to increment.

integer $initial

The initial object value for creation.

integer $expire

Expiration time for creation.

boolean $quiet

TRUE to suppress a successful response.

Returns

integer —

The serial number of the request.

decr()

decr(string  $key, integer  $value, boolean  $quiet = FALSE) : integer

Send `Decrement` or `DecrementQ` command to decrement an object's value.

Decrements an object's value. If the object data is not numeric, this command will fail.

Parameters

string $key

The key string.

integer $value

Amount to decrement.

boolean $quiet

TRUE to suppress a successful response.

Returns

integer —

The serial number of the request.

decr2()

decr2(string  $key, integer  $value, integer  $initial, integer  $expire, boolean  $quiet = FALSE) : integer

Send `Decrement` or `DecrementQ` command to decrement an object's value.

Like decr(), but this can create an object if no object for $key exists.

Parameters

string $key

The key string.

integer $value

Amount to decrement.

integer $initial

The initial object value for creation.

integer $expire

Expiration time for creation.

boolean $quiet

TRUE to suppress a successful response.

Returns

integer —

The serial number of the request.

append()

append(string  $key, integer|string  $data, boolean  $quiet = FALSE) : integer

Send `Append` or `AppendQ` command to append data.

Parameters

string $key

The key string.

integer|string $data

Data to be appended.

boolean $quiet

TRUE to suppress a successful response.

Returns

integer —

The serial number of the request.

prepend()

prepend(string  $key, integer|string  $data, boolean  $quiet = FALSE) : integer

Send `Prepend` or `PrependQ` command to append data.

Parameters

string $key

The key string.

integer|string $data

Data to be prepended.

boolean $quiet

TRUE to suppress a successful response.

Returns

integer —

The serial number of the request.

delete()

delete(string  $key, boolean  $quiet = FALSE) : integer

Send `Delete` or `DeleteQ` command to delete an object.

Parameters

string $key

The key string.

boolean $quiet

TRUE to suppress a successful response.

Returns

integer —

The serial number of the request.

lock()

lock(string  $key, boolean  $quiet = FALSE) : integer

Send `Lock` or `LockQ` command to lock an object.

This command tries to acquire lock for the object. If another client has already locked the object, this command will immediately fail and send an error response back.

Parameters

string $key

The key string.

boolean $quiet

TRUE to suppress a successful response.

Returns

integer —

The serial number of the request.

unlock()

unlock(string  $key, boolean  $quiet = FALSE) : integer

Send `Unlock` or `UnlockQ` command to unlock an object.

Parameters

string $key

The key string.

boolean $quiet

TRUE to suppress a successful response.

Returns

integer —

The serial number of the request.

unlockAll()

unlockAll(boolean  $quiet = FALSE) : integer

Send `UnlockAll` or `UnlockAllQ` command to unlock all locks.

Parameters

boolean $quiet

TRUE to suppress a successful response.

Returns

integer —

The serial number of the request.

flush()

flush(integer  $delay, boolean  $quiet = FALSE) : integer

Send `Flush` or `FlushQ` command to flush all objects.

If non-zero $delay is specified, flush will delay for that seconds.

Parameters

integer $delay

Delay in seconds.

boolean $quiet

TRUE to suppress a successful response.

Returns

integer —

The serial number of the request.

statGeneral()

statGeneral() : integer

Send `Stat` to retrieve general statictics of the server.

The server will return a series of response packets. The series ends with a response data with null key property.

Returns

integer —

The serial number of the request.

statSettings()

statSettings() : integer

Send `Stat` to retrieve settings of the server.

The server will return a series of response packets. The series ends with a response data with null key property.

Returns

integer —

The serial number of the request.

statItems()

statItems() : integer

Send `Stat` to retrieve item statistics of the server.

The server will return a series of response packets. The series ends with a response data with null key property.

Returns

integer —

The serial number of the request.

statSizes()

statSizes() : integer

Send `Stat` to retrieve size statistics of the server.

The server will return a series of response packets. The series ends with a response data with null key property.

Returns

integer —

The serial number of the request.

keys()

keys(string  $prefix = NULL) : integer

Send `Keys` to retrieve matching keys.

The keys extension is only available for yrmcds server!. memcached does not support the extension so far.

The server will return a series of response packets. The series ends with a response data with null key property.

Parameters

string $prefix

If not NULL, only keys with the given prefix will be fetched.

Returns

integer —

The serial number of the request.

version()

version() : integer

Send `Version` to retrieve the server version.

Returns

integer —

The serial number of the request.

quit()

quit(boolean  $quiet = FALSE) : integer

Send `Quit` or `QuitQ` to ask the server closes the connection.

This command effectively invalidates the connection even though it is persistent.

Parameters

boolean $quiet

TRUE to suppress a successful response.

Returns

integer —

The serial number of the request.