From b768b03f9dce21edd91806dc1ca741aa9523db7e Mon Sep 17 00:00:00 2001
From: Luke Woodward <luke.woodward@10up.com>
Date: Fri, 16 May 2014 21:25:24 -0700
Subject: [PATCH] PHP Redis will now serialize and unserialize the data
 internally

---
 object-cache.php | 37 +++++--------------------------------
 1 file changed, 5 insertions(+), 32 deletions(-)

diff --git a/object-cache.php b/object-cache.php
index 0e19283..de046a8 100644
--- a/object-cache.php
+++ b/object-cache.php
@@ -451,9 +451,9 @@ class WP_Object_Cache {
 		// Save to Redis
 		$expiration = abs( intval( $expiration ) );
 		if ( $expiration ) {
-			$result = $this->parse_predis_response( $this->redis->setex( $derived_key, $expiration, $this->prepare_value_for_redis( $value ) ) );
+			$result = $this->parse_predis_response( $this->redis->setex( $derived_key, $expiration, $value ) );
 		} else {
-			$result = $this->parse_predis_response( $this->redis->set( $derived_key, $this->prepare_value_for_redis( $value ) ) );
+			$result = $this->parse_predis_response( $this->redis->set( $derived_key, $value ) );
 		}
 
 		return $result;
@@ -532,7 +532,7 @@ class WP_Object_Cache {
 
 		if ( $this->redis->exists( $derived_key ) ) {
 			$this->cache_hits++;
-			$value = $this->restore_value_from_redis( $this->redis->get( $derived_key ) );
+			$value = $this->redis->get( $derived_key );
 		} else {
 			$this->cache_misses;
 			return false;
@@ -582,9 +582,6 @@ class WP_Object_Cache {
 				// Build an array of values looked up, keyed by the derived cache key
 				$group_cache = array_combine( $derived_keys, $group_cache );
 
-				// Restores cached data to its original data type
-				$group_cache = array_map( array( $this, 'restore_value_from_redis' ), $group_cache );
-
 				// Redis returns null for values not found in cache, but expected return value is false in this instance
 				$group_cache = array_map( array( $this, 'filter_redis_get_multi' ), $group_cache );
 
@@ -629,9 +626,9 @@ class WP_Object_Cache {
 		// Save to Redis
 		$expiration = abs( intval( $expiration ) );
 		if ( $expiration ) {
-			$result = $this->parse_predis_response( $this->redis->setex( $derived_key, $expiration, $this->prepare_value_for_redis( $value ) ) );
+			$result = $this->parse_predis_response( $this->redis->setex( $derived_key, $expiration, $value ) );
 		} else {
-			$result = $this->parse_predis_response( $this->redis->set( $derived_key, $this->prepare_value_for_redis( $value ) ) );
+			$result = $this->parse_predis_response( $this->redis->set( $derived_key, $value ) );
 		}
 
 		return $result;
@@ -743,30 +740,6 @@ class WP_Object_Cache {
 		return preg_replace( '/\s+/', '', WP_CACHE_KEY_SALT . "$prefix$group:$key" );
 	}
 
-	/**
-	 * Prepare a value for storage in Redis, which only accepts strings
-	 *
-	 * @param mixed $value
-	 * @return string
-	 */
-	protected function prepare_value_for_redis( $value ) {
-		$value = maybe_serialize( $value );
-
-		return $value;
-	}
-
-	/**
-	 * Restore a value stored in Redis to its original data type
-	 *
-	 * @param string $value
-	 * @return mixed
-	 */
-	protected function restore_value_from_redis( $value ) {
-		$value = maybe_unserialize( $value );
-
-		return $value;
-	}
-
 	/**
 	 * Convert data types when using Redis MGET
 	 *
-- 
GitLab