Skip to content

Commit ef688e1

Browse files
committed
removing null coalescing operators
1 parent 56662b2 commit ef688e1

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/Connections/PhpRedisConnection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public function __construct($client, callable $connector = null, array $sentinel
4949
{
5050
parent::__construct($client, $connector);
5151

52-
$this->retryLimit = (int) ($sentinelOptions['retry_limit'] ?? 20);
53-
$this->retryWait = (int) ($sentinelOptions['retry_wait'] ?? 1000);
52+
$this->retryLimit = (int) (isset($sentinelOptions['retry_limit']) ? $sentinelOptions['retry_limit'] : 20);
53+
$this->retryWait = (int) (isset($sentinelOptions['retry_wait']) ? $sentinelOptions['retry_wait'] : 1000);
5454
}
5555

5656
/**

src/Connectors/PhpRedisConnector.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,24 +93,30 @@ protected function createClientWithSentinel(array $options)
9393
{
9494
$servers = $this->servers;
9595

96+
// Shuffle the servers to perform some loadbalancing.
9697
shuffle($servers);
9798

99+
// Try to connect to any of the servers.
98100
foreach ($servers as $server) {
99-
$host = $server['host'] ?? 'localhost';
100-
$port = $server['port'] ?? 26739;
101-
$service = $options['service'] ?? 'mymaster';
101+
$host = isset($server['host']) ? $server['host'] : 'localhost';
102+
$port = isset($server['port']) ? $server['port'] : 26739;
103+
$service = isset($options['service']) ? $options['service'] : 'mymaster';
102104

105+
// Create a connection to the Sentinel instance.
103106
$sentinel = new RedisSentinel(
104107
$host,
105108
$port,
106-
$options['sentinel_timeout'] ?? 0,
107-
$options['sentinel_persistent'] ?? null,
108-
$options['retry_wait'] ?? 0,
109-
$options['sentinel_read_timeout'] ?? 0,
109+
isset($options['sentinel_timeout']) ? $options['sentinel_timeout'] : 0,
110+
isset($options['sentinel_persistent']) ? $options['sentinel_persistent'] : null,
111+
isset($options['retry_wait']) ? $options['retry_wait'] : 0,
112+
isset($options['sentinel_read_timeout']) ? $options['sentinel_read_timeout'] : 0,
110113
);
111114

112115
try {
113-
if (($options['update_sentinels'] ?? false) === true) {
116+
// Check if the Sentinel server list needs to be updated.
117+
// Put the current server and the other sentinels in the server list.
118+
$updateSentinels = isset($options['update_sentinels']) ? $options['update_sentinels'] : false;
119+
if ($updateSentinels === true) {
114120
$this->servers = array_merge(
115121
[
116122
[
@@ -124,13 +130,15 @@ protected function createClientWithSentinel(array $options)
124130
);
125131
}
126132

133+
// Lookup the master node.
127134
$master = $sentinel->getMasterAddrByName($service);
128135
if (! is_array($master) || ! count($master)) {
129136
throw new RedisException(sprintf('No master found for service "%s".', $service));
130137
}
131138

139+
// Create a PhpRedis client for the selected master node.
132140
return $this->createClient(array_merge(
133-
$options['parameters'] ?? [],
141+
isset($options['parameters']) ? $options['parameters'] : [],
134142
$server,
135143
['host' => $master[0], 'port' => $master[1]]
136144
));

0 commit comments

Comments
 (0)