summaryrefslogtreecommitdiffstats
path: root/system/libraries/Cache/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'system/libraries/Cache/drivers')
-rw-r--r--system/libraries/Cache/drivers/Cache_redis.php109
1 files changed, 62 insertions, 47 deletions
diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php
index 205f17cd1..e4a26b5f0 100644
--- a/system/libraries/Cache/drivers/Cache_redis.php
+++ b/system/libraries/Cache/drivers/Cache_redis.php
@@ -21,12 +21,10 @@
* @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
- * @since Version 2.0
+ * @since Version 3.0
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Redis Caching Class
*
@@ -38,12 +36,11 @@
*/
class CI_Cache_redis extends CI_Driver
{
-
/**
* Default config
*
* @static
- * @var array
+ * @var array
*/
protected static $_default_config = array(
'host' => '127.0.0.1',
@@ -55,43 +52,32 @@ class CI_Cache_redis extends CI_Driver
/**
* Redis connection
*
- * @var Redis
+ * @var Redis
*/
protected $_redis;
- /**
- * Class destructor
- *
- * Closes the connection to Redis if present.
- *
- * @return void
- */
- public function __destruct()
- {
- if ($this->_redis)
- {
- $this->_redis->close();
- }
- }
+ // ------------------------------------------------------------------------
/**
* Get cache
*
- * @param string $key Cache key identifier
- * @return mixed
+ * @param string Cache key identifier
+ * @return mixed
*/
public function get($key)
{
return $this->_redis->get($key);
}
+ // ------------------------------------------------------------------------
+
/**
* Save cache
*
- * @param string $key Cache key identifier
- * @param mixed $value Data to save
- * @param integer $ttl Time to live
- * @return boolean
+ * @param string Cache key identifier
+ * @param mixed Data to save
+ * @param int Time to live
+ * @return bool
*/
public function save($key, $value, $ttl = NULL)
{
@@ -100,90 +86,102 @@ class CI_Cache_redis extends CI_Driver
: $this->_redis->set($key, $value);
}
+ // ------------------------------------------------------------------------
+
/**
* Delete from cache
*
- * @param string $key Cache key
- * @return boolean
+ * @param string Cache key
+ * @return bool
*/
public function delete($key)
{
return ($this->_redis->delete($key) === 1);
}
+ // ------------------------------------------------------------------------
+
/**
* Clean cache
*
- * @return boolean
- * @see Redis::flushDB()
+ * @return bool
+ * @see Redis::flushDB()
*/
public function clean()
{
return $this->_redis->flushDB();
}
+ // ------------------------------------------------------------------------
+
/**
* Get cache driver info
*
- * @param string $type Not supported in Redis. Only included in order to offer a
- * consistent cache API.
- * @return array
- * @see Redis::info()
+ * @param string Not supported in Redis.
+ * Only included in order to offer a
+ * consistent cache API.
+ * @return array
+ * @see Redis::info()
*/
public function cache_info($type = NULL)
{
return $this->_redis->info();
}
+ // ------------------------------------------------------------------------
+
/**
* Get cache metadata
*
- * @param string $key Cache key
- * @return array
+ * @param string Cache key
+ * @return array
*/
public function get_metadata($key)
{
$value = $this->get($key);
if ($value)
- {
+ {
return array(
'expire' => time() + $this->_redis->ttl($key),
'data' => $value
);
}
+
+ return FALSE;
}
+ // ------------------------------------------------------------------------
+
/**
* Check if Redis driver is supported
*
- * @return boolean
+ * @return bool
*/
public function is_supported()
{
if (extension_loaded('redis'))
- {
+ {
$this->_setup_redis();
-
return TRUE;
}
else
{
log_message('error', 'The Redis extension must be loaded to use Redis cache.');
-
return FALSE;
}
-
}
+ // ------------------------------------------------------------------------
+
/**
* Setup Redis config and connection
*
- * Loads Redis config file if present. Will halt execution if a Redis connection
- * can't be established.
+ * Loads Redis config file if present. Will halt execution
+ * if a Redis connection can't be established.
*
- * @return void
- * @see Redis::connect()
+ * @return bool
+ * @see Redis::connect()
*/
protected function _setup_redis()
{
@@ -214,8 +212,25 @@ class CI_Cache_redis extends CI_Driver
}
}
+ // ------------------------------------------------------------------------
+
+ /**
+
+ * Class destructor
+ *
+ * Closes the connection to Redis if present.
+ *
+ * @return void
+ */
+ public function __destruct()
+ {
+ if ($this->_redis)
+ {
+ $this->_redis->close();
+ }
+ }
+
}
-// End Class
/* End of file Cache_redis.php */
/* Location: ./system/libraries/Cache/drivers/Cache_redis.php */ \ No newline at end of file