Skip to content

Commit

Permalink
Do the scheme as part of build_cluster_connection_array
Browse files Browse the repository at this point in the history
  • Loading branch information
yatsukhnenko committed Sep 9, 2024
1 parent a8cf650 commit e1ddb5b
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions includes/class-predis.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e1ddb5b

Please sign in to comment.