MediaWiki  1.23.8
RedisBagOStuff Class Reference
Inheritance diagram for RedisBagOStuff:
Collaboration diagram for RedisBagOStuff:

Public Member Functions

 __construct ( $params)
 Construct a RedisBagOStuff object. More...
 
 add ( $key, $value, $expiry=0)
 
 cas ( $casToken, $key, $value, $expiry=0)
 Check and set an item. More...
 
 delete ( $key, $time=0)
 Delete an item. More...
 
 get ( $key, &$casToken=null)
 Get an item with the given key. More...
 
 getMulti (array $keys)
 Get an associative array containing the item for each of the keys that have items. More...
 
 incr ( $key, $value=1)
 Non-atomic implementation of incr(). More...
 
 logRequest ( $method, $key, $server, $result)
 Send information about a single request to the debug log. More...
 
 set ( $key, $value, $expiry=0)
 Set an item. More...
 
- Public Member Functions inherited from BagOStuff
 clearLastError ()
 Clear the "last error" registry. More...
 
 debug ( $text)
 
 decr ( $key, $value=1)
 Decrease stored value of $key by $value while preserving its TTL. More...
 
 deleteObjectsExpiringBefore ( $date, $progressCallback=false)
 Delete all objects expiring before a certain date. More...
 
 getLastError ()
 Get the "last error" registered; clearLastError() should be called manually. More...
 
 lock ( $key, $timeout=6)
 
 merge ( $key, closure $callback, $exptime=0, $attempts=10)
 Merge changes into the existing cache value (possibly creating a new one). More...
 
 replace ( $key, $value, $exptime=0)
 
 setDebug ( $bool)
 
 unlock ( $key)
 

Protected Member Functions

 getConnection ( $key)
 Get a Redis object with a connection suitable for fetching the specified key. More...
 
 handleException (RedisConnRef $conn, $e)
 The redis extension throws an exception in response to various read, write and protocol errors. More...
 
 logError ( $msg)
 Log a fatal error. More...
 
 serialize ( $data)
 
 unserialize ( $data)
 
- Protected Member Functions inherited from BagOStuff
 convertExpiry ( $exptime)
 Convert an optionally relative time to an absolute time. More...
 
 convertToRelative ( $exptime)
 Convert an optionally absolute expiry time to a relative time. More...
 
 isInteger ( $value)
 Check if a value is an integer. More...
 
 mergeViaCas ( $key, closure $callback, $exptime=0, $attempts=10)
 
 mergeViaLock ( $key, closure $callback, $exptime=0, $attempts=10)
 
 setLastError ( $err)
 Set the "last error" registry. More...
 

Protected Attributes

bool $automaticFailover
 
RedisConnectionPool $redisPool
 
Array $servers
 List of server names *. More...
 
- Protected Attributes inherited from BagOStuff
 $lastError = self::ERR_NONE
 

Additional Inherited Members

- Public Attributes inherited from BagOStuff
const ERR_NO_RESPONSE = 1
 
const ERR_NONE = 0
 Possible values for getLastError() More...
 
const ERR_UNEXPECTED = 3
 
const ERR_UNREACHABLE = 2
 

Detailed Description

Definition at line 23 of file RedisBagOStuff.php.

Constructor & Destructor Documentation

◆ __construct()

RedisBagOStuff::__construct (   $params)

Construct a RedisBagOStuff object.

Parameters are:

  • servers: An array of server names. A server name may be a hostname, a hostname/port combination or the absolute path of a UNIX socket. If a hostname is specified but no port, the standard port number 6379 will be used. Required.
  • connectTimeout: The timeout for new connections, in seconds. Optional, default is 1 second.
  • persistent: Set this to true to allow connections to persist across multiple web requests. False by default.
  • password: The authentication password, will be sent to Redis in clear text. Optional, if it is unspecified, no AUTH command will be sent.
  • automaticFailover: If this is false, then each key will be mapped to a single server, and if that server is down, any requests for that key will fail. If this is true, a connection failure will cause the client to immediately try the next server in the list (as determined by a consistent hashing algorithm). True by default. This has the potential to create consistency issues if a server is slow enough to flap, for example if it is in swap death.

Definition at line 54 of file RedisBagOStuff.php.

References $params, array(), as, servers, and RedisConnectionPool\singleton().

Member Function Documentation

◆ add()

RedisBagOStuff::add (   $key,
  $value,
  $exptime = 0 
)
Parameters
$keystring
$valuemixed
$exptimeinteger
Returns
bool success

Reimplemented from BagOStuff.

Definition at line 210 of file RedisBagOStuff.php.

References $e, $section, array(), BagOStuff\convertToRelative(), getConnection(), handleException(), list, logRequest(), and serialize().

◆ cas()

RedisBagOStuff::cas (   $casToken,
  $key,
  $value,
  $exptime = 0 
)

Check and set an item.

Parameters
$casTokenmixed
$keystring
$valuemixed
int$exptimeEither an interval in seconds or a unix timestamp for expiry
Returns
bool success

Reimplemented from BagOStuff.

Definition at line 115 of file RedisBagOStuff.php.

References $e, $section, array(), BagOStuff\convertToRelative(), getConnection(), handleException(), list, logRequest(), and serialize().

◆ delete()

RedisBagOStuff::delete (   $key,
  $time = 0 
)

Delete an item.

Parameters
$keystring
int$timeAmount of time to delay the operation (mostly memcached-specific)
Returns
bool True if the item was deleted or not found, false on failure

Reimplemented from BagOStuff.

Definition at line 149 of file RedisBagOStuff.php.

References $e, $section, getConnection(), handleException(), list, and logRequest().

◆ get()

RedisBagOStuff::get (   $key,
$casToken = null 
)

Get an item with the given key.

Returns false if it does not exist.

Parameters
$keystring
$casToken[optional]mixed
Returns
mixed Returns false on failure

Reimplemented from BagOStuff.

Definition at line 71 of file RedisBagOStuff.php.

References $e, $section, $value, getConnection(), handleException(), list, logRequest(), and unserialize().

◆ getConnection()

RedisBagOStuff::getConnection (   $key)
protected

Get a Redis object with a connection suitable for fetching the specified key.

Returns
Array (server, RedisConnRef) or (false, false)

Definition at line 288 of file RedisBagOStuff.php.

References $servers, array(), as, ArrayUtils\consistentHashSort(), BagOStuff\ERR_UNREACHABLE, servers, and BagOStuff\setLastError().

Referenced by add(), cas(), delete(), get(), getMulti(), incr(), and set().

◆ getMulti()

RedisBagOStuff::getMulti ( array  $keys)

Get an associative array containing the item for each of the keys that have items.

Parameters
array$keysList of strings
Returns
Array

Reimplemented from BagOStuff.

Definition at line 169 of file RedisBagOStuff.php.

References $e, $keys, $section, $value, array(), as, BagOStuff\debug(), getConnection(), handleException(), list, and unserialize().

◆ handleException()

RedisBagOStuff::handleException ( RedisConnRef  $conn,
  $e 
)
protected

The redis extension throws an exception in response to various read, write and protocol errors.

Sometimes it also closes the connection, sometimes not. The safest response for us is to explicitly destroy the connection object and let it be reopened during the next request.

Definition at line 322 of file RedisBagOStuff.php.

References $e, BagOStuff\ERR_UNEXPECTED, and BagOStuff\setLastError().

Referenced by add(), cas(), delete(), get(), getMulti(), incr(), and set().

◆ incr()

RedisBagOStuff::incr (   $key,
  $value = 1 
)

Non-atomic implementation of incr().

Probably all callers actually want incr() to atomically initialise values to zero if they don't exist, as provided by the Redis INCR command. But we are constrained by the memcached-like interface to return null in that case. Once the key exists, further increments are atomic.

Reimplemented from BagOStuff.

Definition at line 245 of file RedisBagOStuff.php.

References $e, $section, $value, getConnection(), handleException(), list, logRequest(), and unserialize().

◆ logError()

RedisBagOStuff::logError (   $msg)
protected

Log a fatal error.

Definition at line 312 of file RedisBagOStuff.php.

References wfDebugLog().

◆ logRequest()

RedisBagOStuff::logRequest (   $method,
  $key,
  $server,
  $result 
)

Send information about a single request to the debug log.

Definition at line 330 of file RedisBagOStuff.php.

References BagOStuff\debug().

Referenced by add(), cas(), delete(), get(), incr(), and set().

◆ serialize()

RedisBagOStuff::serialize (   $data)
protected
Parameters
mixed$data
Returns
string

Definition at line 270 of file RedisBagOStuff.php.

Referenced by add(), cas(), and set().

◆ set()

RedisBagOStuff::set (   $key,
  $value,
  $exptime = 0 
)

Set an item.

Parameters
$keystring
$valuemixed
int$exptimeEither an interval in seconds or a unix timestamp for expiry
Returns
bool success

Reimplemented from BagOStuff.

Definition at line 91 of file RedisBagOStuff.php.

References $e, $section, BagOStuff\convertToRelative(), getConnection(), handleException(), list, logRequest(), and serialize().

◆ unserialize()

RedisBagOStuff::unserialize (   $data)
protected
Parameters
string$data
Returns
mixed

Definition at line 279 of file RedisBagOStuff.php.

Referenced by get(), getMulti(), and incr().

Member Data Documentation

◆ $automaticFailover

bool RedisBagOStuff::$automaticFailover
protected

Definition at line 26 of file RedisBagOStuff.php.

◆ $redisPool

RedisConnectionPool RedisBagOStuff::$redisPool
protected

Definition at line 24 of file RedisBagOStuff.php.

◆ $servers

Array RedisBagOStuff::$servers
protected

List of server names *.

Definition at line 25 of file RedisBagOStuff.php.

Referenced by getConnection().


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