/**
* @param string $key
- * @param int $timeout [optional]
+ * @param int $timeout Lock wait timeout [optional]
+ * @param int $expiry Lock expiry [optional]
* @return bool Success
*/
- public function lock( $key, $timeout = 6 ) {
+ public function lock( $key, $timeout = 6, $expiry = 6 ) {
$this->clearLastError();
$timestamp = microtime( true ); // starting UNIX timestamp
- if ( $this->add( "{$key}:lock", 1, $timeout ) ) {
+ if ( $this->add( "{$key}:lock", 1, $expiry ) ) {
return true;
} elseif ( $this->getLastError() ) {
return false;
}
usleep( $sleep ); // back off
$this->clearLastError();
- $locked = $this->add( "{$key}:lock", 1, $timeout );
+ $locked = $this->add( "{$key}:lock", 1, $expiry );
if ( $this->getLastError() ) {
return false;
}
- } while ( !$locked );
+ } while ( !$locked && ( microtime( true ) - $timestamp ) < $timeout );
return $locked;
}
* Batch insertion
* @param array $data $key => $value assoc array
* @param int $exptime Either an interval in seconds or a unix timestamp for expiry
- * @return bool success
+ * @return bool Success
* @since 1.24
*/
public function setMulti( array $data, $exptime = 0 ) {
return false; // key already set
}
- /**
- * @param string $key
- * @param mixed $value
- * @param int $exptime
- * @return bool Success
- * @deprecated since 1.23
- */
- public function replace( $key, $value, $exptime = 0 ) {
- wfDeprecated( __METHOD__, '1.23' );
- if ( $this->get( $key ) !== false ) {
- return $this->set( $key, $value, $exptime );
- }
- return false; // key not already set
- }
-
/**
* Increase stored value of $key by $value while preserving its TTL
* @param string $key Key to increase
* This will create the key with value $init and TTL $ttl if not present
*
* @param string $key
- * @param integer $ttl
- * @param integer $value
- * @param integer $init
+ * @param int $ttl
+ * @param int $value
+ * @param int $init
* @return bool
* @since 1.24
*/