Fix Redis increment behavior by using BagOStuff->incr instead
authorMatthew Flaschen <mflaschen@wikimedia.org>
Tue, 22 Oct 2013 21:35:23 +0000 (17:35 -0400)
committerMatthew Flaschen <mflaschen@wikimedia.org>
Tue, 22 Oct 2013 21:39:00 +0000 (17:39 -0400)
Due to the PHP serialization, the Redis native INCR and INCRBY do not
work.  This instead falls back on the parent class's incr, which uses
lock and unlock, and incrementing on the PHP side.

Bug: 55986
Change-Id: I500199aeb935963ca118fde163bd7ba0cba8f79f

includes/objectcache/RedisBagOStuff.php

index e1dc42e..135e0e8 100644 (file)
@@ -273,38 +273,6 @@ class RedisBagOStuff extends BagOStuff {
                return $result;
        }
 
-       /**
-        * 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.
-        */
-       public function incr( $key, $value = 1 ) {
-               wfProfileIn( __METHOD__ );
-               list( $server, $conn ) = $this->getConnection( $key );
-               if ( !$conn ) {
-                       wfProfileOut( __METHOD__ );
-                       return false;
-               }
-               if ( !$conn->exists( $key ) ) {
-                       wfProfileOut( __METHOD__ );
-                       return null;
-               }
-               try {
-                       $result = $conn->incrBy( $key, $value );
-               } catch ( RedisException $e ) {
-                       $result = false;
-                       $this->handleException( $server, $conn, $e );
-               }
-
-               $this->logRequest( 'incr', $key, $server, $result );
-               wfProfileOut( __METHOD__ );
-               return $result;
-       }
-
        /**
         * Get a Redis object with a connection suitable for fetching the specified key
         * @return Array (server, RedisConnRef) or (false, false)