summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorMasterklavi <masterklavi@gmail.com>2016-03-12 08:32:49 +0100
committerMasterklavi <masterklavi@gmail.com>2016-03-12 08:32:49 +0100
commite5102e1fa8adaa7317f8d3da773f8b77d6f7a2c1 (patch)
tree3f3b9ad7b41ebff3775256a1ac02ace3b6ec2bcb /system
parent1c6a3f4356856899f012c6dc1ae81a21c35016e0 (diff)
Changed the methods of working with serializable values
Diffstat (limited to 'system')
-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);
}
// ------------------------------------------------------------------------