72 $redisConf = [
'serializer' =>
'none' ];
73 foreach ( [
'connectTimeout',
'persistent',
'password' ] as
$opt ) {
81 foreach ( $this->
servers as $key => $server ) {
82 $this->serverTagMap[
is_int( $key ) ? $server : $key] = $server;
85 $this->automaticFailover =
$params[
'automaticFailover'] ??
true;
90 protected function doGet( $key, $flags = 0, &$casToken =
null ) {
98 $value = $conn->get( $key );
101 }
catch ( RedisException
$e ) {
106 $this->
logRequest(
'get', $key, $server, $result );
110 public function set( $key,
$value, $expiry = 0, $flags = 0 ) {
118 $result = $conn->setex( $key, $expiry, $this->
serialize( $value ) );
121 $result = $conn->set( $key, $this->
serialize( $value ) );
123 }
catch ( RedisException
$e ) {
128 $this->
logRequest(
'set', $key, $server, $result );
132 public function delete( $key, $flags = 0 ) {
141 }
catch ( RedisException
$e ) {
146 $this->
logRequest(
'delete', $key, $server, $result );
153 foreach (
$keys as $key ) {
158 $conns[$server] = $conn;
159 $batches[$server][] = $key;
162 foreach ( $batches as $server => $batchKeys ) {
163 $conn = $conns[$server];
165 $conn->multi( Redis::PIPELINE );
166 foreach ( $batchKeys as $key ) {
169 $batchResult = $conn->exec();
170 if ( $batchResult ===
false ) {
171 $this->
debug(
"multi request to $server failed" );
174 foreach ( $batchResult as $i =>
$value ) {
179 }
catch ( RedisException
$e ) {
184 $this->
debug(
"getMulti for " . count(
$keys ) .
" keys " .
185 "returned " . count( $result ) .
" results" );
197 $conns[$server] = $conn;
198 $batches[$server][] = $key;
203 foreach ( $batches as $server => $batchKeys ) {
204 $conn = $conns[$server];
206 $conn->multi( Redis::PIPELINE );
207 foreach ( $batchKeys as $key ) {
209 $conn->setex( $key, $expiry, $this->
serialize( $data[$key] ) );
211 $conn->set( $key, $this->
serialize( $data[$key] ) );
214 $batchResult = $conn->exec();
215 if ( $batchResult ===
false ) {
216 $this->
debug(
"setMulti request to $server failed" );
219 foreach ( $batchResult as
$value ) {
224 }
catch ( RedisException
$e ) {
236 foreach (
$keys as $key ) {
241 $conns[$server] = $conn;
242 $batches[$server][] = $key;
246 foreach ( $batches as $server => $batchKeys ) {
247 $conn = $conns[$server];
249 $conn->multi( Redis::PIPELINE );
250 foreach ( $batchKeys as $key ) {
253 $batchResult = $conn->exec();
254 if ( $batchResult ===
false ) {
255 $this->
debug(
"deleteMulti request to $server failed" );
258 foreach ( $batchResult as
$value ) {
263 }
catch ( RedisException
$e ) {
272 public function add( $key,
$value, $expiry = 0, $flags = 0 ) {
280 $result = $conn->set(
283 [
'nx',
'ex' => $expiry ]
286 $result = $conn->setnx( $key, $this->
serialize( $value ) );
288 }
catch ( RedisException
$e ) {
293 $this->
logRequest(
'add', $key, $server, $result );
315 if ( !$conn->exists( $key ) ) {
319 $result = $conn->incrBy( $key,
$value );
320 }
catch ( RedisException
$e ) {
325 $this->
logRequest(
'incr', $key, $server, $result );
329 public function changeTTL( $key, $exptime = 0, $flags = 0 ) {
337 if ( $exptime == 0 ) {
338 $result = $conn->persist( $key );
339 $this->
logRequest(
'persist', $key, $server, $result );
342 $this->
logRequest(
'expire', $key, $server, $result );
345 $this->
logRequest(
'expireAt', $key, $server, $result );
347 }
catch ( RedisException
$e ) {
380 $candidates =
array_keys( $this->serverTagMap );
382 if ( count( $this->
servers ) > 1 ) {
383 ArrayUtils::consistentHashSort( $candidates, $key,
'/' );
384 if ( !$this->automaticFailover ) {
389 while ( ( $tag =
array_shift( $candidates ) ) !==
null ) {
390 $server = $this->serverTagMap[$tag];
391 $conn = $this->redisPool->getConnection( $server, $this->logger );
401 if ( $this->automaticFailover && $candidates ) {
410 }
catch ( RedisException
$e ) {
417 return [ $server, $conn ];
422 return [
false,
false ];
432 $info = $conn->info();
433 return $info[
'master_link_status'] ??
null;
441 $this->logger->error(
"Redis error: $msg" );
454 $this->redisPool->handleError( $conn,
$e );
464 public function logRequest( $method, $key, $server, $result ) {
465 $this->
debug(
"$method $key on $server: " .
466 ( $result ===
false ?
"failure" :
"success" ) );
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
Class representing a cache/ephemeral data store.
convertToExpiry( $exptime)
Convert an optionally relative time to an absolute time.
expiryIsRelative( $exptime)
convertToRelative( $exptime)
Convert an optionally absolute expiry time to a relative time.
setLastError( $err)
Set the "last error" registry.
Redis-based caching module for redis server >= 2.6.12 and phpredis >= 2.2.4.
RedisConnectionPool $redisPool
incr( $key, $value=1)
Non-atomic implementation of incr().
getMasterLinkStatus(RedisConnRef $conn)
Check the master link status of a Redis server that is configured as a replica DB.
array $servers
List of server names.
setMulti(array $data, $expiry=0, $flags=0)
Batch insertion/replace.
changeTTL( $key, $exptime=0, $flags=0)
Change the expiration on a key if it exists.
add( $key, $value, $expiry=0, $flags=0)
Insert an item if it does not already exist.
logError( $msg)
Log a fatal error.
getConnection( $key)
Get a Redis object with a connection suitable for fetching the specified key.
deleteMulti(array $keys, $flags=0)
Batch deletion.
__construct( $params)
Construct a RedisBagOStuff object.
doGet( $key, $flags=0, &$casToken=null)
array $serverTagMap
Map of (tag => server name)
handleException(RedisConnRef $conn, $e)
The redis extension throws an exception in response to various read, write and protocol errors.
getMulti(array $keys, $flags=0)
Get an associative array containing the item for each of the keys that have items.
logRequest( $method, $key, $server, $result)
Send information about a single request to the debug log.
Helper class to handle automatically marking connectons as reusable (via RAII pattern)
Helper class to manage Redis connections.
static singleton(array $options)
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
namespace being checked & $result
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
processing should stop and the error should be shown to the user * false
returning false will NOT prevent logging $e
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
const QOS_SYNCWRITES_NONE
storage can be distributed across multiple servers
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))