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 ) {
125 public function incr( $key, $value = 1, $flags = 0 ) {
127 $n = $this->client->incr( $routeKey, $value );
129 $res = ( $n !==
false && $n !== null ) ? $n :
false;
131 if ( $this->client->_last_cmd_status !== self::ERR_NONE ) {
138 public function decr( $key, $value = 1, $flags = 0 ) {
140 $n = $this->client->decr( $routeKey, $value );
142 $res = ( $n !==
false && $n !== null ) ? $n :
false;
144 if ( $this->client->_last_cmd_status !== self::ERR_NONE ) {
154 $this->client->add( $routeKey, $init - $step, $this->
fixExpiry( $exptime ) );
155 $this->client->incr( $routeKey, $step );
163 $newValue = $this->client->incr( $routeKey, $step ) ??
false;
164 if ( $newValue ===
false && !$this->
getLastError( $watchPoint ) ) {
167 $newValue =
$success ? $init :
false;
168 if ( $newValue ===
false && !$this->
getLastError( $watchPoint ) ) {
170 $newValue = $this->client->incr( $routeKey, $step ) ??
false;
180 $res = $this->client->touch( $routeKey, $this->
fixExpiry( $exptime ) );
182 if ( $this->client->_last_cmd_status !== self::ERR_NONE ) {
191 foreach (
$keys as $key ) {
195 $resByRouteKey = $this->client->get_multi( $routeKeys );
198 foreach ( $resByRouteKey as $routeKey => $value ) {
202 if ( $this->client->_last_cmd_status !== self::ERR_NONE ) {
210 return is_int( $value ) ? $value : $this->client->serialize( $value );
214 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:
incr( $key, $value=1, $flags=0)
Increase stored value of $key by $value while preserving its TTL.
doAdd( $key, $value, $exptime=0, $flags=0)
Insert an item if it does not already exist.
decr( $key, $value=1, $flags=0)
Decrease stored value of $key by $value while preserving its TTL.
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.