From 80d663aa81eec7bc0894efe1012faec7f6d452b0 Mon Sep 17 00:00:00 2001 From: Kakysha Date: Mon, 28 Oct 2013 01:39:17 +0400 Subject: Added option to connect through unix socket in redis cache driver --- system/libraries/Cache/drivers/Cache_redis.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index 40823fcb4..8daed8bc3 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -44,6 +44,7 @@ class CI_Cache_redis extends CI_Driver * @var array */ protected static $_default_config = array( + 'socket_type' => 'tcp', 'host' => '127.0.0.1', 'password' => NULL, 'port' => 6379, @@ -200,7 +201,13 @@ class CI_Cache_redis extends CI_Driver try { - $this->_redis->connect($config['host'], $config['port'], $config['timeout']); + if ($config['socket_type'] === 'unix') + { + $v = $this->_redis->connect($config['socket']); + } else // tcp socket + { + $this->_redis->connect($config['host'], $config['port'], $config['timeout']); + } } catch (RedisException $e) { -- cgit v1.2.3-24-g4f1b From 2d14673d1a513a372a5921775aa3987f8444477e Mon Sep 17 00:00:00 2001 From: Kakysha Date: Mon, 28 Oct 2013 20:20:24 +0400 Subject: Correct Redis connection troubleshooting --- system/libraries/Cache/drivers/Cache_redis.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index 8daed8bc3..b0315a3ab 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -164,8 +164,7 @@ class CI_Cache_redis extends CI_Driver { if (extension_loaded('redis')) { - $this->_setup_redis(); - return TRUE; + return $this->_setup_redis(); } else { @@ -206,18 +205,26 @@ class CI_Cache_redis extends CI_Driver $v = $this->_redis->connect($config['socket']); } else // tcp socket { - $this->_redis->connect($config['host'], $config['port'], $config['timeout']); + $v = $this->_redis->connect($config['host'], $config['port'], $config['timeout']); + } + if (!$v) + { + log_message('debug','Redis connection refused. Check the config.'); + return FALSE; } } catch (RedisException $e) { - show_error('Redis connection refused. ' . $e->getMessage()); + log_message('debug','Redis connection refused. ' . $e->getMessage()); + return FALSE; } if (isset($config['password'])) { $this->_redis->auth($config['password']); } + + return TRUE; } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From ffe2130b00bffb2f43debf82c34586642c831b0b Mon Sep 17 00:00:00 2001 From: Kakysha Date: Mon, 28 Oct 2013 21:30:05 +0400 Subject: some code rewrite --- system/libraries/Cache/drivers/Cache_redis.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index b0315a3ab..0bbd5b05c 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -202,12 +202,12 @@ class CI_Cache_redis extends CI_Driver { if ($config['socket_type'] === 'unix') { - $v = $this->_redis->connect($config['socket']); + $success = $this->_redis->connect($config['socket']); } else // tcp socket { - $v = $this->_redis->connect($config['host'], $config['port'], $config['timeout']); + $success = $this->_redis->connect($config['host'], $config['port'], $config['timeout']); } - if (!$v) + if ( ! $success) { log_message('debug','Redis connection refused. Check the config.'); return FALSE; -- cgit v1.2.3-24-g4f1b From 8f3f1f9a6dd7c4feb77ffc040b37799fc101e470 Mon Sep 17 00:00:00 2001 From: Kakysha Date: Mon, 28 Oct 2013 23:14:08 +0400 Subject: Code cleanup --- system/libraries/Cache/drivers/Cache_redis.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index 0bbd5b05c..194745fe0 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -203,10 +203,12 @@ class CI_Cache_redis extends CI_Driver if ($config['socket_type'] === 'unix') { $success = $this->_redis->connect($config['socket']); - } else // tcp socket + } + else // tcp socket { $success = $this->_redis->connect($config['host'], $config['port'], $config['timeout']); } + if ( ! $success) { log_message('debug','Redis connection refused. Check the config.'); @@ -215,7 +217,7 @@ class CI_Cache_redis extends CI_Driver } catch (RedisException $e) { - log_message('debug','Redis connection refused. ' . $e->getMessage()); + log_message('debug','Cache: Redis connection refused ('.$e->getMessage().')'); return FALSE; } -- cgit v1.2.3-24-g4f1b From c6fc0c8a4e3e3909b305e3fc24d898a3563d82a8 Mon Sep 17 00:00:00 2001 From: kakysha Date: Mon, 28 Oct 2013 23:01:08 +0300 Subject: Update Redis Caching block Added config options --- user_guide_src/source/libraries/caching.rst | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/user_guide_src/source/libraries/caching.rst b/user_guide_src/source/libraries/caching.rst index 8d7b4c440..10d0e84d7 100644 --- a/user_guide_src/source/libraries/caching.rst +++ b/user_guide_src/source/libraries/caching.rst @@ -239,21 +239,32 @@ For more information on WinCache, please see Redis Caching ============= +Redis is an in-memory key-value store which can operate in LRU cache mode. +To use it, you need Redis server and any Redis PHP extension, e.g. this one +`https://github.com/nicolasff/phpredis `_. + +Config options to connect to redis server must be stored in the application/config/redis.php file. +Available options are:: + + $config['socket_type'] = 'tcp'; //`tcp` or `unix` + $config['socket'] = '/var/run/redis.sock'; // in case of `unix` socket type + $config['host'] = '127.0.0.1'; + $config['password'] = NULL; + $config['port'] = 6379; + $config['timeout'] = 0; + All of the methods listed above can be accessed without passing a specific adapter to the driver loader as follows:: $this->load->driver('cache'); $this->cache->redis->save('foo', 'bar', 10); -.. important:: Redis may require one or more of the following options: - **host**, **post**, **timeout**, **password**. - -The Redis PHP extension repository is located at -`https://github.com/nicolasff/phpredis `_. +For more information on Redis, please see +`http://redis.io `_. Dummy Cache =========== This is a caching backend that will always 'miss.' It stores no data, but lets you keep your caching code in place in environments that don't -support your chosen cache. \ No newline at end of file +support your chosen cache. -- cgit v1.2.3-24-g4f1b From 6b1b803ee134462e29053a8e34cff8dc2dc96f2d Mon Sep 17 00:00:00 2001 From: kakysha Date: Mon, 28 Oct 2013 23:12:19 +0300 Subject: Added changelog entry --- user_guide_src/source/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index c191432b8..fd024ffce 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -623,6 +623,7 @@ Bug fixes for 3.0 - Fixed a bug (#2681) - ``CI_Security::entity_decode()`` used the `PREG_REPLACE_EVAL` flag, which is deprecated since PHP 5.5. - Fixed a bug (#2691) - nested transactions could end in a deadlock when an error is encountered with *db_debug* set to TRUE. - Fixed a bug (#2515) - ``_exception_handler()`` used to send the 200 "OK" HTTP status code and didn't stop script exection even on fatal errors. +- Fixed a bug - `redis` :doc:`Caching ` driver didn't handle connection failure properly. Version 2.1.4 ============= -- cgit v1.2.3-24-g4f1b From 333b69b029c4d694f1f77aaefeb9c4deeeca47b9 Mon Sep 17 00:00:00 2001 From: Kakysha Date: Tue, 29 Oct 2013 03:49:56 +0400 Subject: Spaces, log message --- system/libraries/Cache/drivers/Cache_redis.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index 194745fe0..f13e4479f 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -211,13 +211,13 @@ class CI_Cache_redis extends CI_Driver if ( ! $success) { - log_message('debug','Redis connection refused. Check the config.'); + log_message('debug', 'Cache: Redis connection refused. Check the config.'); return FALSE; } } catch (RedisException $e) { - log_message('debug','Cache: Redis connection refused ('.$e->getMessage().')'); + log_message('debug', 'Cache: Redis connection refused ('.$e->getMessage().')'); return FALSE; } -- cgit v1.2.3-24-g4f1b From f06864ca1442101d2d3644b5b0948ce5dfcd097f Mon Sep 17 00:00:00 2001 From: kakysha Date: Tue, 29 Oct 2013 02:52:44 +0300 Subject: typos --- user_guide_src/source/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index fd024ffce..1c1100b3d 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -623,7 +623,7 @@ Bug fixes for 3.0 - Fixed a bug (#2681) - ``CI_Security::entity_decode()`` used the `PREG_REPLACE_EVAL` flag, which is deprecated since PHP 5.5. - Fixed a bug (#2691) - nested transactions could end in a deadlock when an error is encountered with *db_debug* set to TRUE. - Fixed a bug (#2515) - ``_exception_handler()`` used to send the 200 "OK" HTTP status code and didn't stop script exection even on fatal errors. -- Fixed a bug - `redis` :doc:`Caching ` driver didn't handle connection failure properly. +- Fixed a bug - Redis :doc:`Caching ` driver didn't handle connection failures properly. Version 2.1.4 ============= -- cgit v1.2.3-24-g4f1b From 34565a7299fa12e951f8e4b40164b8f34d17de23 Mon Sep 17 00:00:00 2001 From: kakysha Date: Tue, 29 Oct 2013 02:59:30 +0300 Subject: Update caching.rst --- user_guide_src/source/libraries/caching.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/libraries/caching.rst b/user_guide_src/source/libraries/caching.rst index 10d0e84d7..9c588f29e 100644 --- a/user_guide_src/source/libraries/caching.rst +++ b/user_guide_src/source/libraries/caching.rst @@ -240,7 +240,7 @@ Redis Caching ============= Redis is an in-memory key-value store which can operate in LRU cache mode. -To use it, you need Redis server and any Redis PHP extension, e.g. this one +To use it, you need Redis server and phpredis PHP extension `https://github.com/nicolasff/phpredis `_. Config options to connect to redis server must be stored in the application/config/redis.php file. -- cgit v1.2.3-24-g4f1b From 4118981aff99c3495a4cf63c96271959587e06ce Mon Sep 17 00:00:00 2001 From: Kakysha Date: Tue, 29 Oct 2013 04:00:41 +0400 Subject: newline at the eof --- user_guide_src/source/libraries/caching.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/libraries/caching.rst b/user_guide_src/source/libraries/caching.rst index 9c588f29e..3f7dc2dd9 100644 --- a/user_guide_src/source/libraries/caching.rst +++ b/user_guide_src/source/libraries/caching.rst @@ -267,4 +267,4 @@ Dummy Cache This is a caching backend that will always 'miss.' It stores no data, but lets you keep your caching code in place in environments that don't -support your chosen cache. +support your chosen cache. \ No newline at end of file -- cgit v1.2.3-24-g4f1b