File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -49,10 +49,14 @@ public function addConfiguration(ArrayNodeDefinition $builder)
4949 ->end ()
5050 ->integerNode ('port ' )->end ()
5151 ->enumNode ('vendor ' )
52- ->values (['phpredis ' , 'predis ' ])
52+ ->values (['phpredis ' , 'predis ' , ' custom ' ])
5353 ->cannotBeEmpty ()
5454 ->info ('The library used internally to interact with Redis server ' )
5555 ->end ()
56+ ->scalarNode ('redis ' )
57+ ->cannotBeEmpty ()
58+ ->info ('A custom redis service id, used with vendor true only ' )
59+ ->end ()
5660 ->booleanNode ('persisted ' )
5761 ->defaultFalse ()
5862 ->info ('bool, Whether it use single persisted connection or open a new one for every context ' )
@@ -73,6 +77,10 @@ public function addConfiguration(ArrayNodeDefinition $builder)
7377 */
7478 public function createConnectionFactory (ContainerBuilder $ container , array $ config )
7579 {
80+ if (false == empty ($ config ['redis ' ])) {
81+ $ config ['redis ' ] = new Reference ($ config ['redis ' ]);
82+ }
83+
7684 $ factory = new Definition (RedisConnectionFactory::class);
7785 $ factory ->setArguments ([isset ($ config ['dsn ' ]) ? $ config ['dsn ' ] : $ config ]);
7886
Original file line number Diff line number Diff line change @@ -104,6 +104,35 @@ public function testShouldCreateConnectionFactory()
104104 ]], $ factory ->getArguments ());
105105 }
106106
107+ public function testShouldCreateConnectionFactoryWithCustomRedisInstance ()
108+ {
109+ $ container = new ContainerBuilder ();
110+
111+ $ transport = new RedisTransportFactory ();
112+
113+ $ serviceId = $ transport ->createConnectionFactory ($ container , [
114+ 'host ' => 'localhost ' ,
115+ 'port ' => 123 ,
116+ 'vendor ' => 'custom ' ,
117+ 'redis ' => 'a.redis.service ' ,
118+ ]);
119+
120+ $ this ->assertTrue ($ container ->hasDefinition ($ serviceId ));
121+ $ factory = $ container ->getDefinition ($ serviceId );
122+ $ this ->assertEquals (RedisConnectionFactory::class, $ factory ->getClass ());
123+
124+ $ config = $ factory ->getArgument (0 );
125+
126+ $ this ->assertInternalType ('array ' , $ config );
127+
128+ $ this ->assertArrayHasKey ('vendor ' , $ config );
129+ $ this ->assertSame ('custom ' , $ config ['vendor ' ]);
130+
131+ $ this ->assertArrayHasKey ('redis ' , $ config );
132+ $ this ->assertInstanceOf (Reference::class, $ config ['redis ' ]);
133+ $ this ->assertSame ('a.redis.service ' , (string ) $ config ['redis ' ]);
134+ }
135+
107136 public function testShouldCreateContext ()
108137 {
109138 $ container = new ContainerBuilder ();
You can’t perform that action at this time.
0 commit comments