Skip to content

Commit

Permalink
[5.3] RedisStore - Extract two new methods (#15657)
Browse files Browse the repository at this point in the history
  • Loading branch information
KennedyTedesco authored and taylorotwell committed Sep 29, 2016
1 parent 309fe4c commit a11a406
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/Illuminate/Cache/RedisStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(Redis $redis, $prefix = '', $connection = 'default')
{
$this->redis = $redis;
$this->setPrefix($prefix);
$this->connection = $connection;
$this->setConnection($connection);
}

/**
Expand All @@ -52,7 +52,7 @@ public function __construct(Redis $redis, $prefix = '', $connection = 'default')
public function get($key)
{
if (! is_null($value = $this->connection()->get($this->prefix.$key))) {
return is_numeric($value) ? $value : unserialize($value);
return $this->unserialize($value);
}
}

Expand All @@ -75,7 +75,7 @@ public function many(array $keys)
$values = $this->connection()->mget($prefixedKeys);

foreach ($values as $index => $value) {
$return[$keys[$index]] = is_numeric($value) ? $value : unserialize($value);
$return[$keys[$index]] = $this->unserialize($value);
}

return $return;
Expand All @@ -91,7 +91,7 @@ public function many(array $keys)
*/
public function put($key, $value, $minutes)
{
$value = is_numeric($value) ? $value : serialize($value);
$value = $this->serialize($value);

$this->connection()->setex($this->prefix.$key, (int) max(1, $minutes * 60), $value);
}
Expand Down Expand Up @@ -147,9 +147,7 @@ public function decrement($key, $value = 1)
*/
public function forever($key, $value)
{
$value = is_numeric($value) ? $value : serialize($value);

$this->connection()->set($this->prefix.$key, $value);
$this->connection()->set($this->prefix.$key, $this->serialize($value));
}

/**
Expand Down Expand Up @@ -235,4 +233,26 @@ public function setPrefix($prefix)
{
$this->prefix = ! empty($prefix) ? $prefix.':' : '';
}

/**
* Serialize the value.
*
* @param mixed $value
* @return mixed
*/
protected function serialize($value)
{
return is_numeric($value) ? $value : serialize($value);
}

/**
* Unserialize the value.
*
* @param mixed $value
* @return mixed
*/
protected function unserialize($value)
{
return is_numeric($value) ? $value : unserialize($value);
}
}

0 comments on commit a11a406

Please sign in to comment.