diff options
author | Andrey Andreev <narf@devilix.net> | 2016-03-12 13:52:22 +0100 |
---|---|---|
committer | Andrey Andreev <narf@devilix.net> | 2016-03-12 13:52:22 +0100 |
commit | 44ce8f4545c8a0c0de97e93ceb9b2b9f751bc474 (patch) | |
tree | b3ca1189b541f98dfb01361c1d9a1a315628d5cd | |
parent | b38e3d5835d27843638651523256280c693c6fac (diff) |
Add changelog entries for and polish changes from PRs #4528, #4530
-rw-r--r-- | system/libraries/Cache/drivers/Cache_redis.php | 52 | ||||
-rw-r--r-- | user_guide_src/source/changelog.rst | 6 |
2 files changed, 42 insertions, 16 deletions
diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index fa318403e..49385dffa 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -151,21 +151,29 @@ class CI_Cache_redis extends CI_Driver */ public function get($key) { - $value = $this->_redis->hMGet($key, array('type', 'data')); + $data = $this->_redis->hMGet($key, array('__ci_type', '__ci_value')); - if (empty($value['type'])) + if ( ! isset($data['__ci_type'], $data['__ci_value']) OR $data['__ci_value'] === FALSE) { return FALSE; } - if ($value['type'] === 'array' OR $value['type'] === 'object') + switch ($data['__ci_type']) { - return unserialize($value['data']); - } - else - { - settype($value['data'], $value['type']); - return $value['data']; + case 'array': + case 'object': + return unserialize($data['__ci_value']); + case 'boolean': + case 'integer': + case 'double': // Yes, 'double' is returned and NOT 'float' + case 'string': + case 'NULL': + return settype($data['__ci_value'], $data['__ci_type']) + ? $data['__ci_value'] + : FALSE; + case 'resource': + default: + return FALSE; } } @@ -182,21 +190,33 @@ class CI_Cache_redis extends CI_Driver */ public function save($id, $data, $ttl = 60, $raw = FALSE) { - if (is_array($data) OR is_object($data)) + switch ($data_type = gettype($data)) { - $success = $this->_redis->hMSet($id, array('type' => gettype($data), 'data' => serialize($data))); + case 'array': + case 'object': + $data = serialize($data); + break; + case 'boolean': + case 'integer': + case 'double': // Yes, 'double' is returned and NOT 'float' + case 'string': + case 'NULL': + break; + case 'resource': + default: + return FALSE; } - else + + if ( ! $this->_redis->hMSet($id, array('__ci_type' => $data_type, '__ci_value' => $data))) { - $success = $this->_redis->hMSet($id, array('type' => gettype($data), 'data' => $data)); + return FALSE; } - - if ($success && $ttl) + elseif ($ttl) { $this->_redis->expireAt($id, time() + $ttl); } - return $success; + return TRUE; } // ------------------------------------------------------------------------ diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 2a9ccd57a..3bb7e48f5 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -14,6 +14,7 @@ Release Date: Not Released - Libraries - Added UNIX socket connection support to :doc:`Session Library <libraries/sessions>` 'redis' driver. + - Changed data serialization logic in :doc:`Cache Library <libraries/caching>` 'redis' driver for better performance. - Database @@ -26,6 +27,11 @@ Release Date: Not Released - Updated :doc:`HTML Helper <helpers/html_helper>` function :php:func:`meta()` with support for "charset" and "property" properties. - Changed :doc:`HTML Helper <helpers/html_helper>` function :php:func:`doctype()` default document type to HTML 5. +Bug fixes for 3.1.0 +------------------- + +- Fixed a bug (#4528) - :doc:`Cache Library <libraries/caching>` stored all scalar values as strings with the 'redis' driver. + Version 3.0.6 ============= |