return $success;
}
+ /**
+ * Reset the TTL on a key if it exists
+ *
+ * @param string $key
+ * @param int $expiry
+ * @return bool Success Returns false if there is no key
+ * @since 1.28
+ */
+ public function changeTTL( $key, $expiry = 0 ) {
+ $value = $this->get( $key );
+
+ return ( $value === false ) ? false : $this->set( $key, $value, $expiry );
+ }
+
/**
* Acquire an advisory lock on a key string
*
return $this->mergeViaCas( $key, $callback, $exptime, $attempts );
}
+ public function changeTTL( $key, $exptime = 0 ) {
+ return $this->client->touch( $this->validateKeyEncoding( $key ),
+ $this->fixExpiry( $exptime ) );
+ }
+
/**
* Get the underlying client object. This is provided for debugging
* purposes.
return false;
}
+ /**
+ * Changes the TTL on a key from the server to $time
+ *
+ * @param string $key Key
+ * @param int $time TTL in seconds
+ *
+ * @return bool True on success, false on failure
+ */
+ public function touch( $key, $time = 0 ) {
+ if ( !$this->_active ) {
+ return false;
+ }
+
+ $sock = $this->get_sock( $key );
+ if ( !is_resource( $sock ) ) {
+ return false;
+ }
+
+ $key = is_array( $key ) ? $key[1] : $key;
+
+ if ( isset( $this->stats['touch'] ) ) {
+ $this->stats['touch']++;
+ } else {
+ $this->stats['touch'] = 1;
+ }
+ $cmd = "touch $key $time\r\n";
+ if ( !$this->_fwrite( $sock, $cmd ) ) {
+ return false;
+ }
+ $res = $this->_fgets( $sock );
+
+ if ( $this->_debug ) {
+ $this->_debugprint( sprintf( "MemCache: touch %s (%s)", $key, $res ) );
+ }
+
+ if ( $res == "TOUCHED" ) {
+ return true;
+ }
+
+ return false;
+ }
+
/**
* @param string $key
* @param int $timeout
$result = $this->client->setMulti( $data, $this->fixExpiry( $exptime ) );
return $this->checkResult( false, $result );
}
+
+ public function changeTTL( $key, $expiry = 0 ) {
+ $this->debugLog( "touch($key)" );
+ $result = $this->client->touch( $key, $expiry );
+ return $this->checkResult( $key, $result );
+ }
}
if ( !$conn ) {
return false;
}
- if ( !$conn->exists( $key ) ) {
- return null;
- }
try {
+ if ( !$conn->exists( $key ) ) {
+ return null;
+ }
// @FIXME: on races, the key may have a 0 TTL
$result = $conn->incrBy( $key, $value );
} catch ( RedisException $e ) {
return $result;
}
+ public function changeTTL( $key, $expiry = 0 ) {
+ list( $server, $conn ) = $this->getConnection( $key );
+ if ( !$conn ) {
+ return false;
+ }
+
+ $expiry = $this->convertToRelative( $expiry );
+ try {
+ $result = $conn->expire( $key, $expiry );
+ } catch ( RedisException $e ) {
+ $result = false;
+ $this->handleException( $conn, $e );
+ }
+
+ $this->logRequest( 'expire', $key, $server, $result );
+ return $result;
+ }
+
public function modifySimpleRelayEvent( array $event ) {
if ( array_key_exists( 'val', $event ) ) {
$event['val'] = serialize( $event['val'] ); // this class uses PHP serialization
}
}
+ /**
+ * @covers BagOStuff::changeTTL
+ */
+ public function testChangeTTL() {
+ $key = wfMemcKey( 'test' );
+ $value = 'meow';
+
+ $this->cache->add( $key, $value );
+ $this->assertTrue( $this->cache->changeTTL( $key, 5 ) );
+ $this->assertEquals( $this->cache->get( $key ), $value );
+ $this->cache->delete( $key );
+ $this->assertFalse( $this->cache->changeTTL( $key, 5 ) );
+ }
+
/**
* @covers BagOStuff::add
*/