From e1ddb5b5858d0c82f8bf4cf15a0d53fb0c05ee23 Mon Sep 17 00:00:00 2001 From: Pavlo Yatsukhnenko Date: Mon, 9 Sep 2024 13:43:57 +0300 Subject: [PATCH] Do the scheme as part of `build_cluster_connection_array` --- includes/class-predis.php | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/includes/class-predis.php b/includes/class-predis.php index 788338ed..9fbe687c 100644 --- a/includes/class-predis.php +++ b/includes/class-predis.php @@ -86,11 +86,6 @@ public function connect( $read_timeout = null ) { $servers = $this->build_cluster_connection_array(); $parameters['cluster'] = $servers; $options['cluster'] = 'redis'; - if ( defined('WP_REDIS_SCHEME') ) { - $options['parameters'] = [ - 'scheme' => WP_REDIS_SCHEME, - ]; - } } if ( strcasecmp( 'unix', $parameters['scheme'] ) === 0 ) { @@ -211,13 +206,30 @@ protected function build_cluster_connection_array() { $cluster = array_values( WP_REDIS_CLUSTER ); foreach ( $cluster as $key => $server ) { - $connection_string = parse_url( $server ); + $components = parse_url( $server ); + + if ( ! empty( $components['scheme'] ) ) { + $scheme = $components['scheme']; + } elseif ( defined( 'WP_REDIS_SCHEME' ) ) { + $scheme = WP_REDIS_SCHEME; + } else { + $scheme = null; + } - $cluster[ $key ] = sprintf( - "%s:%s", - $connection_string['host'], - $connection_string['port'] - ); + if ( isset( $scheme ) ) { + $cluster[ $key ] = sprintf( + '%s://%s:%d', + $scheme, + $components['host'], + $components['port'] + ); + } else { + $cluster[ $key ] = sprintf( + '%s:%d', + $components['host'], + $components['port'] + ); + } } return $cluster;