Skip to content

Commit 781430a

Browse files
Fix Redis version determination for predis replication connection (#522)
* Add check that redis_version is set * Fetch Redis server info for replicated connections * change style * Update CHANGELOG.md --------- Co-authored-by: Till Krüss <[email protected]>
1 parent 61003da commit 781430a

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Unreleased
44

5-
- Fixed `wp_cache_flush_group` issue with Predis and replication connection
5+
- Fixed issues with Predis and replication connections
66
- Fixed rare fatal error in `show_error_and_die()` (one more time)
77

88
## 2.5.2

includes/object-cache.php

+5-11
Original file line numberDiff line numberDiff line change
@@ -1139,22 +1139,16 @@ protected function connect_using_hhvm( $parameters ) {
11391139
* @return void
11401140
*/
11411141
public function fetch_info() {
1142-
$options = method_exists( $this->redis, 'getOptions' )
1143-
? $this->redis->getOptions()
1144-
: new stdClass();
1145-
1146-
if ( isset( $options->replication ) && $options->replication ) {
1147-
return;
1148-
}
1149-
11501142
if ( defined( 'WP_REDIS_CLUSTER' ) ) {
11511143
$connectionId = is_string( WP_REDIS_CLUSTER )
11521144
? 'SERVER'
11531145
: current( $this->build_cluster_connection_array() );
11541146

1155-
$info = $this->determine_client() === 'predis'
1147+
$info = $this->is_predis()
11561148
? $this->redis->getClientBy( 'id', $connectionId )->info()
11571149
: $this->redis->info( $connectionId );
1150+
} else if ($this->is_predis() && $this->redis->getConnection() instanceof Predis\Connection\Replication\MasterSlaveReplication) {
1151+
$info = $this->redis->getClientBy( 'role' , 'master' )->info();
11581152
} else {
11591153
$info = $this->redis->info();
11601154
}
@@ -1888,7 +1882,7 @@ protected function lua_flush_closure( $salt, $escape = true ) {
18881882
return i
18891883
LUA;
18901884

1891-
if ( version_compare( $this->redis_version(), '5', '<' ) && version_compare( $this->redis_version(), '3.2', '>=' ) ) {
1885+
if ( isset($this->redis_version) && version_compare( $this->redis_version, '5', '<' ) && version_compare( $this->redis_version, '3.2', '>=' ) ) {
18921886
$script = 'redis.replicate_commands()' . "\n" . $script;
18931887
}
18941888

@@ -1940,7 +1934,7 @@ function ( $group ) {
19401934
until 0 == cur
19411935
return i
19421936
LUA;
1943-
if ( version_compare( $this->redis_version(), '5', '<' ) && version_compare( $this->redis_version(), '3.2', '>=' ) ) {
1937+
if ( isset($this->redis_version) && version_compare( $this->redis_version, '5', '<' ) && version_compare( $this->redis_version, '3.2', '>=' ) ) {
19441938
$script = 'redis.replicate_commands()' . "\n" . $script;
19451939
}
19461940

0 commit comments

Comments
 (0)