Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] RedisStore - Extract two new methods #15657

Merged
merged 1 commit into from
Sep 29, 2016
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
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);
}
}