Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding timeout and port options to the redis cache engine

  • Loading branch information...
commit ab1f336e216aa63bf9bc569ffd333729a9e235b1 1 parent 06476a2
@jellehenkens jellehenkens authored
View
13 app/Config/bootstrap.php
@@ -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'));
View
13 lib/Cake/Cache/Engine/RedisEngine.php
@@ -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
*/
@@ -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)
);
@@ -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;
View
4 lib/Cake/Test/Case/Cache/Engine/RedisEngineTest.php
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.