Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b8bd231

Browse files
committed
[Cache] Add support for \Relay\Cluster $context in the connection string
1 parent 8d9f35f commit b8bd231

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/Symfony/Component/Cache/Traits/RedisTrait.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ trait RedisTrait
4848
'lazy' => null,
4949
'redis_cluster' => false,
5050
'relay_cluster' => false,
51+
'relay_cluster_context' => [],
5152
'redis_sentinel' => null,
5253
'dbindex' => 0,
5354
'failover' => 'none',
@@ -377,14 +378,34 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
377378
}
378379

379380
try {
381+
$relayClusterContext = $params['relay_cluster_context'];
382+
383+
foreach (['allow_self_signed', 'verify_peer_name','verify_peer'] as $contextStreamBoolField) {
384+
if(isset($relayClusterContext['stream'][$contextStreamBoolField])) {
385+
$relayClusterContext['stream'][$contextStreamBoolField] = filter_var($relayClusterContext['stream'][$contextStreamBoolField], \FILTER_VALIDATE_BOOL);
386+
}
387+
}
388+
389+
foreach (['use-cache', 'client-tracking','throw-on-error','client-invalidations','reply-literal','persistent'] as $contextBoolField) {
390+
if(isset($relayClusterContext[$contextBoolField])) {
391+
$relayClusterContext[$contextBoolField] = filter_var($relayClusterContext[$contextBoolField], \FILTER_VALIDATE_BOOL);
392+
}
393+
}
394+
395+
foreach (['max-retries', 'serializer','compression','compression-level'] as $contextIntField) {
396+
if(isset($relayClusterContext[$contextIntField])) {
397+
$relayClusterContext[$contextIntField] = filter_var($relayClusterContext[$contextIntField], \FILTER_VALIDATE_INT);
398+
}
399+
}
400+
380401
$relayCluster = new $class(
381402
name: null,
382403
seeds: $hosts,
383404
connect_timeout: $params['timeout'],
384405
command_timeout: $params['command_timeout'],
385406
persistent: (bool) $params['persistent'],
386407
auth: $params['auth'] ?? null,
387-
context: []
408+
context: $relayClusterContext
388409
);
389410
} catch (\Relay\Exception $e) {
390411
throw new InvalidArgumentException('Relay cluster connection failed: '.$e->getMessage());
@@ -541,11 +562,6 @@ protected function doClear(string $namespace): bool
541562
$address = implode(':', $ipAndPort);
542563
$cursor = null;
543564
do {
544-
// mixed &$iterator
545-
// array|string $key_or_address
546-
// mixed $match = null
547-
// int $count = 0
548-
// string|null $type = null
549565
$keys = $this->redis->scan($cursor, $address, $pattern, 1000);
550566
if (isset($keys[1]) && \is_array($keys[1])) {
551567
$cursor = $keys[0];

0 commit comments

Comments
 (0)