objectcache: avoid using deprecated phpredis::delete() alias
[lhc/web/wiklou.git] / includes / libs / objectcache / RedisBagOStuff.php
index 2d1ed05..6e467da 100644 (file)
  */
 
 /**
- * Redis-based caching module for redis server >= 2.6.12
+ * Redis-based caching module for redis server >= 2.6.12 and phpredis >= 2.2.4
  *
+ * @see https://github.com/phpredis/phpredis/blob/d310ed7c8/Changelog.md
  * @note Avoid use of Redis::MULTI transactions for twemproxy support
  *
  * @ingroup Cache
  * @ingroup Redis
  */
-class RedisBagOStuff extends BagOStuff {
+class RedisBagOStuff extends MediumSpecificBagOStuff {
        /** @var RedisConnectionPool */
        protected $redisPool;
        /** @var array List of server names */
@@ -143,7 +144,7 @@ class RedisBagOStuff extends BagOStuff {
                $e = null;
                try {
                        // Note that redis does not return false if the key was not there
-                       $result = ( $conn->delete( $key ) !== false );
+                       $result = ( $conn->del( $key ) !== false );
                } catch ( RedisException $e ) {
                        $result = false;
                        $this->handleException( $conn, $e );
@@ -269,7 +270,7 @@ class RedisBagOStuff extends BagOStuff {
                                // Avoid delete() with array to reduce CPU hogging from a single request
                                $conn->multi( Redis::PIPELINE );
                                foreach ( $batchKeys as $key ) {
-                                       $conn->delete( $key );
+                                       $conn->del( $key );
                                }
                                $batchResult = $conn->exec();
                                if ( $batchResult === false ) {
@@ -368,54 +369,11 @@ class RedisBagOStuff extends BagOStuff {
                }
 
                try {
-                       $conn->watch( $key );
-                       if ( $conn->exists( $key ) ) {
-                               $conn->multi( Redis::MULTI );
-                               $conn->incrBy( $key, $value );
-                               $batchResult = $conn->exec();
-                               if ( $batchResult === false ) {
-                                       $result = false;
-                               } else {
-                                       $result = end( $batchResult );
-                               }
-                       } else {
-                               $result = false;
-                               $conn->unwatch();
-                       }
-               } catch ( RedisException $e ) {
-                       try {
-                               $conn->unwatch(); // sanity
-                       } catch ( RedisException $ex ) {
-                               // already errored
-                       }
-                       $result = false;
-                       $this->handleException( $conn, $e );
-               }
-
-               $this->logRequest( 'incr', $key, $conn->getServer(), $result );
-
-               return $result;
-       }
-
-       public function incrWithInit( $key, $exptime, $value = 1, $init = 1 ) {
-               $conn = $this->getConnection( $key );
-               if ( !$conn ) {
-                       return false;
-               }
-
-               $ttl = $this->convertToRelative( $exptime );
-               $preIncrInit = $init - $value;
-               try {
-                       $conn->multi( Redis::MULTI );
-                       $conn->set( $key, $preIncrInit, $ttl ? [ 'nx', 'ex' => $ttl ] : [ 'nx' ] );
-                       $conn->incrBy( $key, $value );
-                       $batchResult = $conn->exec();
-                       if ( $batchResult === false ) {
-                               $result = false;
-                               $this->debug( "incrWithInit request to {$conn->getServer()} failed" );
-                       } else {
-                               $result = end( $batchResult );
+                       if ( !$conn->exists( $key ) ) {
+                               return false;
                        }
+                       // @FIXME: on races, the key may have a 0 TTL
+                       $result = $conn->incrBy( $key, $value );
                } catch ( RedisException $e ) {
                        $result = false;
                        $this->handleException( $conn, $e );