44
55use InvalidArgumentException ;
66use Illuminate \Contracts \Redis \Factory ;
7+ use Illuminate \Redis \Connections \Connection ;
78
89/**
910 * @mixin \Illuminate\Redis\Connections\Connection
1011 */
1112class RedisManager implements Factory
1213{
14+ /**
15+ * The application instance.
16+ *
17+ * @var \Illuminate\Foundation\Application
18+ */
19+ protected $ app ;
20+
1321 /**
1422 * The name of the default driver.
1523 *
@@ -31,15 +39,24 @@ class RedisManager implements Factory
3139 */
3240 protected $ connections ;
3341
42+ /**
43+ * Indicates whether event dispatcher is set on connections.
44+ *
45+ * @var bool
46+ */
47+ protected $ events = true ;
48+
3449 /**
3550 * Create a new Redis manager instance.
3651 *
52+ * @param \Illuminate\Foundation\Application $app
3753 * @param string $driver
3854 * @param array $config
3955 * @return void
4056 */
41- public function __construct ($ driver , array $ config )
57+ public function __construct ($ app , $ driver , array $ config )
4258 {
59+ $ this ->app = $ app ;
4360 $ this ->driver = $ driver ;
4461 $ this ->config = $ config ;
4562 }
@@ -58,7 +75,9 @@ public function connection($name = null)
5875 return $ this ->connections [$ name ];
5976 }
6077
61- return $ this ->connections [$ name ] = $ this ->resolve ($ name )->setName ($ name );
78+ return $ this ->connections [$ name ] = $ this ->configure (
79+ $ this ->resolve ($ name ), $ name
80+ );
6281 }
6382
6483 /**
@@ -101,6 +120,24 @@ protected function resolveCluster($name)
101120 );
102121 }
103122
123+ /**
124+ * Get the connector instance for the current driver.
125+ *
126+ * @param \Illuminate\Redis\Connections\Connection $connection
127+ * @param string $name
128+ * @return \Illuminate\Redis\Connections\Connection
129+ */
130+ protected function configure (Connection $ connection , $ name )
131+ {
132+ $ connection ->setName ($ name );
133+
134+ if ($ this ->events && $ this ->app ->bound ('events ' )) {
135+ $ connection ->setEventDispatcher ($ this ->app ['events ' ]);
136+ }
137+
138+ return $ connection ;
139+ }
140+
104141 /**
105142 * Get the connector instance for the current driver.
106143 *
@@ -126,6 +163,26 @@ public function connections()
126163 return $ this ->connections ;
127164 }
128165
166+ /**
167+ * Enable setting event dispatcher on connections.
168+ *
169+ * @return array
170+ */
171+ public function enableEvents ()
172+ {
173+ return $ this ->events = true ;
174+ }
175+
176+ /**
177+ * Disable setting event dispatcher on connections.
178+ *
179+ * @return array
180+ */
181+ public function disableEvents ()
182+ {
183+ return $ this ->events = false ;
184+ }
185+
129186 /**
130187 * Pass methods onto the default Redis connection.
131188 *
0 commit comments