44 parent::__construct( $params );
48 'compress_threshold' => 1500,
49 'connect_timeout' => 0.5,
54 $this->client->set_servers( $params[
'servers'] );
55 $this->client->set_debug(
true );
58 protected function doGet( $key, $flags = 0, &$casToken =
null ) {
59 $getToken = ( $casToken === self::PASS_BY_REF );
67 ? $this->client->get( $routeKey, $casToken )
68 : $this->client->get( $routeKey );
70 if ( $this->client->_last_cmd_status !== self::ERR_NONE ) {
77 protected function doSet( $key, $value, $exptime = 0, $flags = 0 ) {
80 $res = $this->client->set( $routeKey, $value, $this->
fixExpiry( $exptime ) );
82 if ( $this->client->_last_cmd_status !== self::ERR_NONE ) {
89 protected function doDelete( $key, $flags = 0 ) {
92 $res = $this->client->delete( $routeKey );
94 if ( $this->client->_last_cmd_status !== self::ERR_NONE ) {
101 protected function doAdd( $key, $value, $exptime = 0, $flags = 0 ) {
104 $res = $this->client->add( $routeKey, $value, $this->
fixExpiry( $exptime ) );
106 if ( $this->client->_last_cmd_status !== self::ERR_NONE ) {
113 protected function doCas( $casToken, $key, $value, $exptime = 0, $flags = 0 ) {
116 $res = $this->client->cas( $casToken, $routeKey, $value, $this->
fixExpiry( $exptime ) );
118 if ( $this->client->_last_cmd_status !== self::ERR_NONE ) {
128 $this->client->add( $routeKey, $init - $step, $this->
fixExpiry( $exptime ) );
129 $this->client->incr( $routeKey, $step );
137 $newValue = $this->client->incr( $routeKey, $step ) ??
false;
138 if ( $newValue ===
false && !$this->
getLastError( $watchPoint ) ) {
141 $newValue =
$success ? $init :
false;
142 if ( $newValue ===
false && !$this->
getLastError( $watchPoint ) ) {
144 $newValue = $this->client->incr( $routeKey, $step ) ??
false;
154 $res = $this->client->touch( $routeKey, $this->
fixExpiry( $exptime ) );
156 if ( $this->client->_last_cmd_status !== self::ERR_NONE ) {
165 foreach (
$keys as $key ) {
169 $resByRouteKey = $this->client->get_multi( $routeKeys );
172 foreach ( $resByRouteKey as $routeKey => $value ) {
176 if ( $this->client->_last_cmd_status !== self::ERR_NONE ) {
184 return is_int( $value ) ? $value : $this->client->serialize( $value );
188 return $this->
isInteger( $value ) ? (int)$value : $this->client->unserialize( $value );
getLastError( $watchPoint=0)
Get the "last error" registry.
setLastError( $error)
Set the "last error" registry due to a problem encountered during an attempted operation.
watchErrors()
Get a "watch point" token that can be used to get the "last error" to occur after now.
isInteger( $value)
Check if a value is an integer.
Base class for memcached clients.
validateKeyAndPrependRoute( $key)
memcached client class implemented using (p)fsockopen()
A wrapper class for the pure-PHP memcached client, exposing a BagOStuff interface.
doSet( $key, $value, $exptime=0, $flags=0)
Set an item.
doChangeTTL( $key, $exptime, $flags)
__construct( $params)
Available parameters are:
doAdd( $key, $value, $exptime=0, $flags=0)
Insert an item if it does not already exist.
doCas( $casToken, $key, $value, $exptime=0, $flags=0)
Set an item if the current CAS token matches the provided CAS token.
doGet( $key, $flags=0, &$casToken=null)
Get an item.
doIncrWithInitAsync( $key, $exptime, $step, $init)
doGetMulti(array $keys, $flags=0)
Get an associative array containing the item for each of the keys that have items.
doIncrWithInitSync( $key, $exptime, $step, $init)
doDelete( $key, $flags=0)
Delete an item.