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.php47
1 files changed, 17 insertions, 30 deletions
diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php
index 81b49e2fc..c50da1303 100644
--- a/system/libraries/Cache/drivers/Cache_redis.php
+++ b/system/libraries/Cache/drivers/Cache_redis.php
@@ -143,14 +143,21 @@ class CI_Cache_redis extends CI_Driver
*/
public function get($key)
{
- $value = $this->_redis->get($key);
+ $value = $this->_redis->hMGet($key, array('serialized', 'data'));
- if ($value !== FALSE && isset($this->_serialized[$key]))
+ if ( ! is_array($value))
{
- return unserialize($value);
+ return FALSE;
}
- return $value;
+ if ( ! empty($value['serialized']))
+ {
+ return unserialize($value['data']);
+ }
+ else
+ {
+ return $value['data'];
+ }
}
// ------------------------------------------------------------------------
@@ -168,21 +175,12 @@ class CI_Cache_redis extends CI_Driver
{
if (is_array($data) OR is_object($data))
{
- if ( ! $this->_redis->sIsMember('_ci_redis_serialized', $id) && ! $this->_redis->sAdd('_ci_redis_serialized', $id))
- {
- return FALSE;
- }
-
- isset($this->_serialized[$id]) OR $this->_serialized[$id] = TRUE;
- $data = serialize($data);
+ return $this->_redis->hMSet($id, array('serialized' => TRUE, 'data' => serialize($data)));
}
- elseif (isset($this->_serialized[$id]))
+ else
{
- $this->_serialized[$id] = NULL;
- $this->_redis->sRemove('_ci_redis_serialized', $id);
+ return $this->_redis->hMSet($id, array('serialized' => FALSE, 'data' => $data));
}
-
- return $this->_redis->set($id, $data, $ttl);
}
// ------------------------------------------------------------------------
@@ -195,18 +193,7 @@ class CI_Cache_redis extends CI_Driver
*/
public function delete($key)
{
- if ($this->_redis->delete($key) !== 1)
- {
- return FALSE;
- }
-
- if (isset($this->_serialized[$key]))
- {
- $this->_serialized[$key] = NULL;
- $this->_redis->sRemove('_ci_redis_serialized', $key);
- }
-
- return TRUE;
+ return ($this->_redis->delete($key) === 1);
}
// ------------------------------------------------------------------------
@@ -220,7 +207,7 @@ class CI_Cache_redis extends CI_Driver
*/
public function increment($id, $offset = 1)
{
- return $this->_redis->incr($id, $offset);
+ return $this->_redis->hIncrBy($id, 'data', $offset);
}
// ------------------------------------------------------------------------
@@ -234,7 +221,7 @@ class CI_Cache_redis extends CI_Driver
*/
public function decrement($id, $offset = 1)
{
- return $this->_redis->decr($id, $offset);
+ return $this->_redis->hIncrBy($id, 'data', -$offset);
}
// ------------------------------------------------------------------------