- protected function cas( $casToken, $key, $value, $expiry = 0 ) {
-
- list( $server, $conn ) = $this->getConnection( $key );
- if ( !$conn ) {
- return false;
- }
- $expiry = $this->convertToRelative( $expiry );
- try {
- $conn->watch( $key );
-
- if ( $this->serialize( $this->get( $key ) ) !== $casToken ) {
- $conn->unwatch();
- return false;
- }
-
- // multi()/exec() will fail atomically if the key changed since watch()
- $conn->multi();
- if ( $expiry ) {
- $conn->setex( $key, $expiry, $this->serialize( $value ) );
- } else {
- // No expiry, that is very different from zero expiry in Redis
- $conn->set( $key, $this->serialize( $value ) );
- }
- $result = ( $conn->exec() == array( true ) );
- } catch ( RedisException $e ) {
- $result = false;
- $this->handleException( $conn, $e );
- }
-
- $this->logRequest( 'cas', $key, $server, $result );
- return $result;
- }
-