Skip to content

Commit

Permalink
Merge pull request #292 from stavultras/remaining_keys_issue
Browse files Browse the repository at this point in the history
Return cache data in correct order when using `wp_cache_get_multiple()`
  • Loading branch information
danielbachhuber authored Aug 17, 2020
2 parents 866edad + 0e9f5ae commit 8b472e2
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)].
Expand Down
3 changes: 2 additions & 1 deletion object-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -694,14 +694,15 @@ 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;
}
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 ) {
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)].
Expand Down
34 changes: 34 additions & 0 deletions tests/phpunit/test-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down
2 changes: 1 addition & 1 deletion wp-redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/
*/
Expand Down

0 comments on commit 8b472e2

Please sign in to comment.