diff options
Diffstat (limited to 'system')
-rw-r--r-- | system/libraries/Cache/drivers/Cache_redis.php | 48 |
1 files changed, 18 insertions, 30 deletions
diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index d4d95ebb1..6da86728c 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -151,14 +151,22 @@ class CI_Cache_redis extends CI_Driver */ public function get($key) { - $value = $this->_redis->get($key); + $value = $this->_redis->hMGet($key, array('type', 'data')); - if ($value !== FALSE && isset($this->_serialized[$key])) + if (empty($value['type'])) { - return unserialize($value); + return FALSE; } - return $value; + if ($value['type'] === 'array' OR $value['type'] === 'object') + { + return unserialize($value['data']); + } + else + { + settype($value['data'], $value['type']); + return $value['data']; + } } // ------------------------------------------------------------------------ @@ -176,21 +184,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('type' => gettype($data), '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('type' => gettype($data), 'data' => $data)); } - - return $this->_redis->set($id, $data, $ttl); } // ------------------------------------------------------------------------ @@ -203,18 +202,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); } // ------------------------------------------------------------------------ @@ -228,7 +216,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); } // ------------------------------------------------------------------------ @@ -242,7 +230,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); } // ------------------------------------------------------------------------ |