From: Aaron Date: Wed, 5 Sep 2012 18:51:04 +0000 (-0700) Subject: Made default BagOStuff::incr() function more like memcached. X-Git-Tag: 1.31.0-rc.0~22427^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22auteur_infos%22%2C%20%22id_auteur=%24id%22%29%20.%20%22?a=commitdiff_plain;h=676446ef90bb281ffdf04081fa0404e76ceffb1a;p=lhc%2Fweb%2Fwiklou.git Made default BagOStuff::incr() function more like memcached. Change-Id: Ia216f20fdcf855448e2f2e4d99667e72c6254f82 --- diff --git a/includes/objectcache/BagOStuff.php b/includes/objectcache/BagOStuff.php index 57029a89f5..7bbaff9346 100644 --- a/includes/objectcache/BagOStuff.php +++ b/includes/objectcache/BagOStuff.php @@ -167,19 +167,18 @@ abstract class BagOStuff { * Increase stored value of $key by $value while preserving its TTL * @param $key String: Key to increase * @param $value Integer: Value to add to $key (Default 1) - * @return null if lock is not possible else $key value increased by $value - * @return integer + * @return integer|bool New value or false on failure */ public function incr( $key, $value = 1 ) { if ( !$this->lock( $key ) ) { - return null; + return false; } - - $value = intval( $value ); - - if ( ( $n = $this->get( $key ) ) !== false ) { - $n += $value; - $this->set( $key, $n ); // exptime? + $n = $this->get( $key ); + if ( $this->isInteger( $n ) ) { // key exists? + $n += intval( $value ); + $this->set( $key, max( 0, $n ) ); // exptime? + } else { + $n = false; } $this->unlock( $key ); @@ -220,7 +219,7 @@ abstract class BagOStuff { } /** - * Convert an optionally absolute expiry time to a relative time. If an + * Convert an optionally absolute expiry time to a relative time. If an * absolute time is specified which is in the past, use a short expiry time. * * @param $exptime integer