16
16
use Symfony \Component \Messenger \Exception \InvalidArgumentException ;
17
17
use Symfony \Component \Messenger \Exception \LogicException ;
18
18
use Symfony \Component \Messenger \Exception \TransportException ;
19
- use Symfony \Contracts \Service \ResetInterface ;
20
19
21
20
/**
22
21
* A Redis connection.
29
28
*
30
29
* @final
31
30
*/
32
- class Connection implements ResetInterface
31
+ class Connection
33
32
{
34
33
private const DEFAULT_OPTIONS = [
35
34
'host ' => '127.0.0.1 ' ,
@@ -56,8 +55,7 @@ class Connection implements ResetInterface
56
55
'ssl ' => null , // see https://php.net/context.ssl
57
56
];
58
57
59
- private \Redis |Relay |\RedisCluster |null $ redis = null ;
60
- private \Closure $ redisInitializer ;
58
+ private \Redis |Relay |\RedisCluster |\Closure $ redis ;
61
59
private string $ stream ;
62
60
private string $ queue ;
63
61
private string $ group ;
@@ -114,9 +112,9 @@ public function __construct(array $options, \Redis|Relay|\RedisCluster|null $red
114
112
115
113
if ((\is_array ($ host ) && null === $ sentinelMaster ) || $ redis instanceof \RedisCluster) {
116
114
$ hosts = \is_string ($ host ) ? [$ host .': ' .$ port ] : $ host ; // Always ensure we have an array
117
- $ this ->redisInitializer = static fn () => self ::initializeRedisCluster ($ redis , $ hosts , $ auth , $ options );
115
+ $ this ->redis = static fn () => self ::initializeRedisCluster ($ redis , $ hosts , $ auth , $ options );
118
116
} else {
119
- $ this ->redisInitializer = static function () use ($ redis , $ sentinelMaster , $ host , $ port , $ options , $ auth ) {
117
+ $ this ->redis = static function () use ($ redis , $ sentinelMaster , $ host , $ port , $ options , $ auth ) {
120
118
if (null !== $ sentinelMaster ) {
121
119
$ sentinelClass = \extension_loaded ('redis ' ) ? \RedisSentinel::class : Sentinel::class;
122
120
$ hostIndex = 0 ;
@@ -739,15 +737,10 @@ private function rawCommand(string $command, ...$arguments): mixed
739
737
740
738
private function getRedis (): \Redis |Relay |\RedisCluster
741
739
{
742
- if (! $ this ->redis ) {
743
- $ this ->redis = ($ this ->redisInitializer )();
740
+ if ($ this ->redis instanceof \Closure ) {
741
+ $ this ->redis = ($ this ->redis )();
744
742
}
745
743
746
744
return $ this ->redis ;
747
745
}
748
-
749
- public function reset (): void
750
- {
751
- $ this ->redis = null ;
752
- }
753
746
}
0 commit comments