Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions system/libraries/Cache/drivers/Cache_redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,16 @@ public function __construct()
public function get($key)
{
$data = $this->_redis->hMGet($key, array('__ci_type', '__ci_value'));

if ($this->_redis->sIsMember('_ci_redis_serialized', $key))
// Also serves scalars that 3.1.x cached as plain strings
if ($data === FALSE)
{
return FALSE;
return $this->_get_v31($key);
}

// Also serves scalars that 3.1.x cached as plain strings
if ($data === FALSE)
// Key doesn't exist (hMGet returns an array of FALSE values)
if ( ! isset($data['__ci_type'], $data['__ci_value']) OR $data['__ci_value'] === FALSE)
{
return $this->_redis->get($key);
return FALSE;
}

switch ($data['__ci_type'])
Expand Down Expand Up @@ -295,14 +295,15 @@ public function decrement($id, $offset = 1)
*/
protected function _increment($id, $offset)
{
$value = $this->_redis->incrBy($id, $offset);

if ($value === FALSE)
// Also serves scalars that 3.1.x cached as plain strings, incrBy creates the key if not existing
if ($this->_redis->type($id) === Redis::REDIS_STRING)
{
$value = $this->_redis->hIncrBy($id, '__ci_value', $offset);
$value === FALSE OR $this->_redis->hSet($id, '__ci_type', 'integer');
return $this->_redis->incrBy($id, $offset);
}

$value = $this->_redis->hIncrBy($id, '__ci_value', $offset);
$value === FALSE OR $this->_redis->hSet($id, '__ci_type', 'integer');

return $value;
}

Expand Down Expand Up @@ -386,4 +387,24 @@ public function __destruct()
$this->_redis->close();
}
}

// ------------------------------------------------------------------------

/**
* Get scalars that 3.1.x cached as plain strings
*
* @param string $key Cache ID
* @return mixed
*/
private function _get_v31($key)
{
$value = $this->_redis->get($key);

if ($value !== FALSE && $this->_redis->sIsMember('_ci_redis_serialized', $key))
{
return unserialize($value);
}

return $value;
}
}