From e2c1e97cd51508edf0de6cc7a8669ea113f8eae8 Mon Sep 17 00:00:00 2001
From: Erick Hitter <ehitter@gmail.com>
Date: Thu, 27 Feb 2014 11:56:03 -0800
Subject: [PATCH] Simplify `get()` method's logic rather than duplicating Redis
 lookup calls.

Also fixes a code error introduced in 01b7283c0, where the key, not the retrieved value, was passed to the `restore_value_from_redis()` method.
---
 object-cache.php | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/object-cache.php b/object-cache.php
index f4bdda4..7571d96 100644
--- a/object-cache.php
+++ b/object-cache.php
@@ -934,18 +934,20 @@ class WP_Object_Cache {
 	public function get( $key, $group = 'default', $server_key = '', $byKey = false ) {
 		$derived_key = $this->build_key( $key, $group );
 
-		if ( ! in_array( $group, $this->no_redis_groups ) ) {
-			$value = $this->redis->get( $this->restore_value_from_redis( $derived_key ) );
-		} else {
+		if ( in_array( $group, $this->no_redis_groups ) ) {
 			if ( isset( $this->cache[$derived_key] ) ) {
 				return is_object( $this->cache[$derived_key] ) ? clone $this->cache[$derived_key] : $this->cache[$derived_key];
 			} elseif ( in_array( $group, $this->no_redis_groups ) ) {
 				return false;
-			} else {
-				$value = $this->redis->get( $this->restore_value_from_redis( $derived_key ) );
 			}
 		}
 
+		if ( $this->redis->exists( $derived_key ) ) {
+			$value = $this->restore_value_from_redis( $this->redis->get( $derived_key ) );
+		} else {
+			return false;
+		}
+
 		$this->add_to_internal_cache( $derived_key, $value );
 
 		return is_object( $value ) ? clone $value : $value;
-- 
GitLab