From e1056eb11d64f18bf7684ca98254aeb5c2371ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Sat, 7 Jan 2017 20:56:33 -0800 Subject: [PATCH] Normalize PhpRedis GET results --- src/Illuminate/Cache/RedisStore.php | 4 +--- src/Illuminate/Cache/Repository.php | 16 ++++++---------- .../Redis/Connections/PhpRedisConnection.php | 13 +++++++++++++ 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/Illuminate/Cache/RedisStore.php b/src/Illuminate/Cache/RedisStore.php index 4a897f8e8ede..0903fe8fb4df 100755 --- a/src/Illuminate/Cache/RedisStore.php +++ b/src/Illuminate/Cache/RedisStore.php @@ -53,9 +53,7 @@ public function get($key) { $value = $this->connection()->get($this->prefix.$key); - if (! is_null($value) && $value !== false) { - return $this->unserialize($value); - } + return ! is_null($value) ? $this->unserialize($value) : null; } /** diff --git a/src/Illuminate/Cache/Repository.php b/src/Illuminate/Cache/Repository.php index f82c7a588a3e..86535a67056d 100755 --- a/src/Illuminate/Cache/Repository.php +++ b/src/Illuminate/Cache/Repository.php @@ -62,9 +62,7 @@ public function __construct(Store $store) */ public function has($key) { - $value = $this->get($key); - - return ! is_null($value) && $value !== false; + return ! is_null($this->get($key)); } /** @@ -85,7 +83,7 @@ public function get($key, $default = null) // If we could not find the cache value, we will fire the missed event and get // the default value for this cache value. This default could be a callback // so we will execute the value function which will resolve it if needed. - if (is_null($value) || $value === false) { + if (is_null($value)) { $this->event(new CacheMissed($key)); $value = value($default); @@ -128,7 +126,7 @@ protected function handleManyResult($keys, $key, $value) // If we could not find the cache value, we will fire the missed event and get // the default value for this cache value. This default could be a callback // so we will execute the value function which will resolve it if needed. - if (is_null($value) || $value === false) { + if (is_null($value)) { $this->event(new CacheMissed($key)); return isset($keys[$key]) ? value($keys[$key]) : null; @@ -218,12 +216,10 @@ public function add($key, $value, $minutes) ); } - $exists = $this->get($key); - // If the value did not exist in the cache, we will put the value in the cache // so it exists for subsequent requests. Then, we will return true so it is // easy to know if the value gets added. Otherwise, we will return false. - if (is_null($exists) || $exists === false) { + if (is_null($this->get($key))) { $this->put($key, $value, $minutes); return true; @@ -285,7 +281,7 @@ public function remember($key, $minutes, Closure $callback) // If the item exists in the cache we will just return this immediately and if // not we will execute the given Closure and cache the result of that for a // given number of minutes so it's available for all subsequent requests. - if (! is_null($value) && $value !== false) { + if (! is_null($value)) { return $value; } @@ -320,7 +316,7 @@ public function rememberForever($key, Closure $callback) // If the item exists in the cache we will just return this immediately and if // not we will execute the given Closure and cache the result of that for a // given number of minutes so it's available for all subsequent requests. - if (! is_null($value) && $value !== false) { + if (! is_null($value)) { return $value; } diff --git a/src/Illuminate/Redis/Connections/PhpRedisConnection.php b/src/Illuminate/Redis/Connections/PhpRedisConnection.php index 05e8bd1ac49e..5611ac78f411 100644 --- a/src/Illuminate/Redis/Connections/PhpRedisConnection.php +++ b/src/Illuminate/Redis/Connections/PhpRedisConnection.php @@ -17,6 +17,19 @@ public function __construct($client) $this->client = $client; } + /** + * Returns the value of the given key. + * + * @param string $key + * @return string|null + */ + public function get($key) + { + $result = $this->client->get($key); + + return $result !== false ? $result : null; + } + /** * Evaluate a Lua script and return the result. *