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(-) (limited to 'system/libraries/Cache/drivers/Cache_redis.php') 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(-) (limited to 'system/libraries/Cache/drivers/Cache_redis.php') 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(-) (limited to 'system/libraries/Cache/drivers/Cache_redis.php') 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(-) (limited to 'system/libraries/Cache/drivers/Cache_redis.php') 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 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(-) (limited to 'system/libraries/Cache/drivers/Cache_redis.php') 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 119d8a7547e155edaaa53682b9247cd7e80d8c9d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 8 Jan 2014 15:27:53 +0200 Subject: Optimize get_instance() calls/assignments --- system/libraries/Cache/drivers/Cache_redis.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Cache/drivers/Cache_redis.php') diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index f13e4479f..48c803d7e 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -208,7 +208,7 @@ class CI_Cache_redis extends CI_Driver { $success = $this->_redis->connect($config['host'], $config['port'], $config['timeout']); } - + if ( ! $success) { log_message('debug', 'Cache: Redis connection refused. Check the config.'); @@ -225,7 +225,7 @@ class CI_Cache_redis extends CI_Driver { $this->_redis->auth($config['password']); } - + return TRUE; } -- cgit v1.2.3-24-g4f1b From 43d7fa73534c07d10a88ec120c0938d0d00a184e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 9 Jan 2014 17:29:45 +0200 Subject: Implement atomic increment/decrement in Cache library Requested via issue #109 Supersedes PR #241 --- system/libraries/Cache/drivers/Cache_redis.php | 49 +++++++++++++++++++++----- 1 file changed, 41 insertions(+), 8 deletions(-) (limited to 'system/libraries/Cache/drivers/Cache_redis.php') diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index 48c803d7e..b6fddf035 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -63,7 +63,7 @@ class CI_Cache_redis extends CI_Driver /** * Get cache * - * @param string Cache key identifier + * @param string Cache ID * @return mixed */ public function get($key) @@ -76,16 +76,17 @@ class CI_Cache_redis extends CI_Driver /** * Save cache * - * @param string Cache key identifier - * @param mixed Data to save - * @param int Time to live - * @return bool + * @param string $id Cache ID + * @param mixed $data Data to save + * @param int $ttl Time to live in seconds + * @param bool $raw Whether to store the raw value (unused) + * @return bool TRUE on success, FALSE on failure */ - public function save($key, $value, $ttl = NULL) + public function save($id, $data, $ttl = 60, $raw = FALSE) { return ($ttl) - ? $this->_redis->setex($key, $ttl, $value) - : $this->_redis->set($key, $value); + ? $this->_redis->setex($id, $ttl, $data) + : $this->_redis->set($id, $data); } // ------------------------------------------------------------------------ @@ -103,6 +104,38 @@ class CI_Cache_redis extends CI_Driver // ------------------------------------------------------------------------ + /** + * Increment a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to add + * @return mixed New value on success or FALSE on failure + */ + public function increment($id, $offset = 1) + { + return $this->_redis->exists($id) + ? $this->_redis->incr($id, $offset) + : FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * Decrement a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to reduce by + * @return mixed New value on success or FALSE on failure + */ + public function decrement($id, $offset = 1) + { + return $this->_redis->exists($id) + ? $this->_redis->decr($id, $offset) + : FALSE; + } + + // ------------------------------------------------------------------------ + /** * Clean cache * -- cgit v1.2.3-24-g4f1b From 871754af60251993d640981e107d2def5f2db396 Mon Sep 17 00:00:00 2001 From: darwinel Date: Tue, 11 Feb 2014 17:34:57 +0100 Subject: 2013 > 2014 Update copyright notices from 2013 to 2014. And update one calendar example in user_guide from year 2013/2014 to 2014/2015. --- system/libraries/Cache/drivers/Cache_redis.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cache/drivers/Cache_redis.php') diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index b6fddf035..1c76426c5 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 3.0 -- cgit v1.2.3-24-g4f1b