Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adding timeout and port options to the redis cache engine
  • Loading branch information
Jelle Henkens committed May 29, 2012
1 parent 06476a2 commit ab1f336
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
13 changes: 13 additions & 0 deletions app/Config/bootstrap.php
Expand Up @@ -82,6 +82,19 @@
* 'probability'=> 100, //[optional]
* 'prefix' => Inflector::slug(APP_DIR) . '_', //[optional] prefix every cache file with this string
* ));
*
* Redis (http://http://redis.io/)
*
* Cache::config('default', array(
* 'engine' => 'Redis', //[required]
* 'duration'=> 3600, //[optional]
* 'probability'=> 100, //[optional]
* 'prefix' => Inflector::slug(APP_DIR) . '_', //[optional] prefix every cache file with this string
* 'server' => '127.0.0.1' // localhost
* 'port' => 6379 // default port 6379
* 'timeout' => 0 // timeout in seconds, 0 = unlimited
* 'persistent' => true, // [optional] set this to false for non-persistent connections
* ));
*/
Cache::config('default', array('engine' => 'File'));

Expand Down
13 changes: 8 additions & 5 deletions lib/Cake/Cache/Engine/RedisEngine.php
Expand Up @@ -36,6 +36,9 @@ class RedisEngine extends CacheEngine {
* Settings
*
* - server = string url or ip to the Redis server host
* - port = integer port number to the Redis server (default: 6379)
* - timeout = float timeout in seconds (default: 0)
* - persistent = bool Connects to the Redis server with a persistent connection (default: true)
*
* @var array
*/
Expand All @@ -58,9 +61,9 @@ public function init($settings = array()) {
'engine' => 'Redis',
'prefix' => null,
'server' => '127.0.0.1',
'port' => null,
'persistent' => true,
'serialize' => true
'port' => 6379,
'timeout' => 0,
'persistent' => true
), $settings)
);

Expand All @@ -77,9 +80,9 @@ protected function _connect() {
try {
$this->_Redis = new Redis();
if (empty($this->settings['persistent'])) {
$return = $this->_Redis->connect($this->settings['server']);
$return = $this->_Redis->connect($this->settings['server'], $this->settings['port'], $this->settings['timeout']);
} else {
$return = $this->_Redis->pconnect($this->settings['server']);
$return = $this->_Redis->pconnect($this->settings['server'], $this->settings['port'], $this->settings['timeout']);
}
} catch (RedisException $e) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Test/Case/Cache/Engine/RedisEngineTest.php
Expand Up @@ -64,15 +64,15 @@ public function tearDown() {
*/
public function testSettings() {
$settings = Cache::settings('redis');
unset($settings['serialize'], $settings['path']);
$expecting = array(
'port' => null,
'prefix' => 'cake_',
'duration' => 3600,
'probability' => 100,
'groups' => array(),
'engine' => 'Redis',
'server' => '127.0.0.1',
'port' => 6379,
'timeout' => 0,
'persistent' => true
);
$this->assertEquals($expecting, $settings);
Expand Down

0 comments on commit ab1f336

Please sign in to comment.