*/
function __construct( $params ) {
parent::__construct( $params );
- $redisConf = array( 'serializer' => 'none' ); // manage that in this class
- foreach ( array( 'connectTimeout', 'persistent', 'password' ) as $opt ) {
+ $redisConf = [ 'serializer' => 'none' ]; // manage that in this class
+ foreach ( [ 'connectTimeout', 'persistent', 'password' ] as $opt ) {
if ( isset( $params[$opt] ) ) {
$redisConf[$opt] = $params[$opt];
}
}
public function getMulti( array $keys, $flags = 0 ) {
- $batches = array();
- $conns = array();
+ $batches = [];
+ $conns = [];
foreach ( $keys as $key ) {
list( $server, $conn ) = $this->getConnection( $key );
if ( !$conn ) {
$conns[$server] = $conn;
$batches[$server][] = $key;
}
- $result = array();
+ $result = [];
foreach ( $batches as $server => $batchKeys ) {
$conn = $conns[$server];
try {
* @return bool
*/
public function setMulti( array $data, $expiry = 0 ) {
- $batches = array();
- $conns = array();
+ $batches = [];
+ $conns = [];
foreach ( $data as $key => $value ) {
list( $server, $conn ) = $this->getConnection( $key );
if ( !$conn ) {
$result = $conn->set(
$key,
$this->serialize( $value ),
- array( 'nx', 'ex' => $expiry )
+ [ 'nx', 'ex' => $expiry ]
);
} else {
$result = $conn->setnx( $key, $this->serialize( $value ) );
if ( !$conn ) {
return false;
}
- if ( !$conn->exists( $key ) ) {
- return null;
- }
try {
+ if ( !$conn->exists( $key ) ) {
+ return null;
+ }
// @FIXME: on races, the key may have a 0 TTL
$result = $conn->incrBy( $key, $value );
} catch ( RedisException $e ) {
return $result;
}
+ public function changeTTL( $key, $expiry = 0 ) {
+ list( $server, $conn ) = $this->getConnection( $key );
+ if ( !$conn ) {
+ return false;
+ }
+
+ $expiry = $this->convertToRelative( $expiry );
+ try {
+ $result = $conn->expire( $key, $expiry );
+ } catch ( RedisException $e ) {
+ $result = false;
+ $this->handleException( $conn, $e );
+ }
+
+ $this->logRequest( 'expire', $key, $server, $result );
+ return $result;
+ }
+
public function modifySimpleRelayEvent( array $event ) {
if ( array_key_exists( 'val', $event ) ) {
$event['val'] = serialize( $event['val'] ); // this class uses PHP serialization
* @return mixed
*/
protected function unserialize( $data ) {
- return ctype_digit( $data ) ? intval( $data ) : unserialize( $data );
+ $int = intval( $data );
+ return $data === (string)$int ? $int : unserialize( $data );
}
/**
}
}
- return array( $server, $conn );
+ return [ $server, $conn ];
}
$this->setLastError( BagOStuff::ERR_UNREACHABLE );
- return array( false, false );
+ return [ false, false ];
}
/**