This adapter uses the phpredis PHP extension, which can be found here: https://github.com/nicolasff/phpredis The Redis cache adapter is meant to be used through the Cache interface, which abstracts away key generation, adapter instantiation and filter implementation. This adapter does not aim to provide a full implementation of the Redis API, but rather only a subset of its features that are useful in the context of a semi-persistent cache. A simple configuration of this adapter can be accomplished in config/bootstrap/cache.php as follows: {{{ Cache::config(array( 'cache-config-name' => array( 'adapter' => 'Redis', 'host' => '127.0.0.1:6379' ) )); }}} The 'host' key accepts a string argument in the format of ip:port where the Redis server can be found. This Redis adapter provides basic support for write, read, delete and clear cache functionality, as well as allowing the first four methods to be filtered as per the Lithium filtering system.
See also: lithium\storage\Cache::key()
See also: lithium\storage\Cache::adapter()
Inheritance: extends lithium\core\Object
コード例 #1
0
 /**
  * Skip the test if the Redis extension is unavailable.
  *
  * @return void
  */
 public function skip()
 {
     $extensionExists = extension_loaded('redis');
     $message = 'The redis extension is not installed.';
     $this->skipIf(!$extensionExists, $message);
     $R = new \Redis();
     $R->connect('127.0.0.1', 6379);
     $message = 'redis-server does not appear to be running on 127.0.0.1:6379';
     $result = $R->info();
     $this->skipIf(empty($result), $message);
     unset($R);
 }
コード例 #2
0
 public function testWriteNoCacheExpiry()
 {
     $redis = new Redis(array('expiry' => null));
     $key = 'default_key';
     $data = 'value';
     $redis->write($key, $data)->__invoke(null, compact('key', 'data'), null);
     $this->assertEqual($data, $this->_redis->get($key));
     $this->assertTrue($this->_redis->delete($key));
 }
コード例 #3
0
ファイル: RedisTest.php プロジェクト: fedeisas/lithium
 public function testIncrementWithScope()
 {
     $adapter = new Redis(array('scope' => 'primary'));
     $this->_redis->set('primary:key1', 1, 60);
     $this->_redis->set('key1', 1, 60);
     $adapter->increment('key1');
     $expected = 1;
     $result = $this->_redis->get('key1');
     $this->assertEqual($expected, $result);
     $expected = 2;
     $result = $this->_redis->get('primary:key1');
     $this->assertEqual($expected, $result);
 }
コード例 #4
0
ファイル: RedisTest.php プロジェクト: EHER/chegamos
 public function testWriteDefaultCacheExpiry()
 {
     $Redis = new Redis(array('expiry' => '+5 seconds'));
     $key = 'default_key';
     $data = 'value';
     $time = strtotime('+5 seconds');
     $closure = $Redis->write($key, $data);
     $this->assertTrue(is_callable($closure));
     $params = compact('key', 'data');
     $result = $closure($Redis, $params, null);
     $expected = $data;
     $this->assertEqual($expected, $result);
     $result = $this->_Redis->get($key);
     $this->assertEqual($expected, $result);
     $result = $this->_Redis->ttl($key);
     $this->assertEqual($time - time(), $result);
     $result = $this->_Redis->delete($key);
     $this->assertTrue($result);
 }