diff --git a/README.md b/README.md index 9e2dcf7..6d9694e 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ **Tags:** cache, plugin, redis **Requires at least:** 3.0.1 **Tested up to:** 5.5 -**Stable tag:** 1.1.0 +**Stable tag:** 1.1.1 **License:** GPLv2 or later **License URI:** http://www.gnu.org/licenses/gpl-2.0.html @@ -107,6 +107,9 @@ There's a known issue with WordPress `alloptions` cache design. Specifically, a ## Changelog ## +### 1.1.1 (August 17, 2020) ### +* Returns cache data in correct order when using `wp_cache_get_multiple()` and internal cache is already primed [[#292](https://github.com/pantheon-systems/wp-redis/pull/292)]. + ### 1.1.0 (July 13, 2020) ### * Implements `wp_cache_get_multiple()` for WordPress 5.5 [[#287](https://github.com/pantheon-systems/wp-redis/pull/287)]. * Bails early when connecting to Redis throws an Exception to avoid fatal error [[285](https://github.com/pantheon-systems/wp-redis/pull/285)]. diff --git a/object-cache.php b/object-cache.php index 95cc24c..537a516 100644 --- a/object-cache.php +++ b/object-cache.php @@ -694,7 +694,7 @@ public function get_multiple( $keys, $group = 'default', $force = false ) { } } } - $remaining_keys = array_diff( $keys, array_keys( $cache ) ); + $remaining_keys = array_values( array_diff( $keys, array_keys( $cache ) ) ); // If all keys were satisfied by the internal cache, we're sorted. if ( empty( $remaining_keys ) ) { return $cache; @@ -702,6 +702,7 @@ public function get_multiple( $keys, $group = 'default', $force = false ) { if ( $this->_should_use_redis_hashes( $group ) ) { $redis_safe_group = $this->_key( '', $group ); $results = $this->_call_redis( 'hmGet', $redis_safe_group, $remaining_keys ); + $results = is_array( $results ) ? array_values( $results ) : $results; } else { $ids = array(); foreach ( $remaining_keys as $key ) { diff --git a/readme.txt b/readme.txt index d68b28e..750bd1f 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: getpantheon, danielbachhuber, mboynes, Outlandish Josh Tags: cache, plugin, redis Requires at least: 3.0.1 Tested up to: 5.5 -Stable tag: 1.1.0 +Stable tag: 1.1.1 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -107,6 +107,9 @@ There's a known issue with WordPress `alloptions` cache design. Specifically, a == Changelog == += 1.1.1 (August 17, 2020) = +* Returns cache data in correct order when using `wp_cache_get_multiple()` and internal cache is already primed [[#292](https://github.com/pantheon-systems/wp-redis/pull/292)]. + = 1.1.0 (July 13, 2020) = * Implements `wp_cache_get_multiple()` for WordPress 5.5 [[#287](https://github.com/pantheon-systems/wp-redis/pull/287)]. * Bails early when connecting to Redis throws an Exception to avoid fatal error [[285](https://github.com/pantheon-systems/wp-redis/pull/285)]. diff --git a/tests/phpunit/test-cache.php b/tests/phpunit/test-cache.php index a6a7146..3cebac1 100644 --- a/tests/phpunit/test-cache.php +++ b/tests/phpunit/test-cache.php @@ -788,6 +788,40 @@ public function test_get_multiple() { } } + public function test_get_multiple_partial_cache_miss() { + if ( ! class_exists( 'Redis' ) ) { + $this->markTestSkipped( 'Requires an active persistent object cache connection' ); + } + $this->cache->set( 'foo1', 'bar', 'group1' ); + $this->cache->set( 'foo2', 'baz', 'group1' ); + $this->cache->set( 'foo3', 'bap', 'group1' ); + // Reset the internal cache. + $this->cache->cache = array(); + // Prime the second item into the internal cache. + $this->cache->get( 'foo2', 'group1' ); + + $found = $this->cache->get_multiple( array( 'foo1', 'foo2', 'foo3', 'foo4' ), 'group1' ); + + $expected = array( + 'foo1' => 'bar', + 'foo2' => 'baz', + 'foo3' => 'bap', + 'foo4' => false, + ); + + $this->assertSame( $expected, $found ); + $this->assertEquals( 4, $this->cache->cache_hits ); + $this->assertEquals( 1, $this->cache->cache_misses ); + $this->assertEquals( + array( + self::$get_key => 1, + self::$mget_key => 1, + self::$set_key => 3, + ), + $this->cache->redis_calls + ); + } + public function test_get_multiple_non_persistent() { $this->cache->add_non_persistent_groups( array( 'group1' ) ); $this->cache->set( 'foo1', 'bar', 'group1' ); diff --git a/wp-redis.php b/wp-redis.php index d4d6704..e857400 100644 --- a/wp-redis.php +++ b/wp-redis.php @@ -3,7 +3,7 @@ * Plugin Name: WP Redis * Plugin URI: http://github.com/pantheon-systems/wp-redis/ * Description: WordPress Object Cache using Redis. Requires the PhpRedis extension (https://github.com/phpredis/phpredis). - * Version: 1.1.0 + * Version: 1.1.1 * Author: Pantheon, Josh Koenig, Matthew Boynes, Daniel Bachhuber, Alley Interactive * Author URI: https://pantheon.io/ */