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)
49
49
->end ()
50
50
->integerNode ('port ' )->end ()
51
51
->enumNode ('vendor ' )
52
- ->values (['phpredis ' , 'predis ' ])
52
+ ->values (['phpredis ' , 'predis ' , ' custom ' ])
53
53
->cannotBeEmpty ()
54
54
->info ('The library used internally to interact with Redis server ' )
55
55
->end ()
56
+ ->scalarNode ('redis ' )
57
+ ->cannotBeEmpty ()
58
+ ->info ('A custom redis service id, used with vendor true only ' )
59
+ ->end ()
56
60
->booleanNode ('persisted ' )
57
61
->defaultFalse ()
58
62
->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)
73
77
*/
74
78
public function createConnectionFactory (ContainerBuilder $ container , array $ config )
75
79
{
80
+ if (false == empty ($ config ['redis ' ])) {
81
+ $ config ['redis ' ] = new Reference ($ config ['redis ' ]);
82
+ }
83
+
76
84
$ factory = new Definition (RedisConnectionFactory::class);
77
85
$ factory ->setArguments ([isset ($ config ['dsn ' ]) ? $ config ['dsn ' ] : $ config ]);
78
86
Original file line number Diff line number Diff line change @@ -104,6 +104,35 @@ public function testShouldCreateConnectionFactory()
104
104
]], $ factory ->getArguments ());
105
105
}
106
106
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
+
107
136
public function testShouldCreateContext ()
108
137
{
109
138
$ container = new ContainerBuilder ();
You can’t perform that action at this time.
0 commit comments