10
10
use Illuminate \Support \Arr ;
11
11
use Illuminate \Support \ServiceProvider ;
12
12
use Monospice \LaravelRedisSentinel \Configuration \Loader as ConfigurationLoader ;
13
+ use Monospice \LaravelRedisSentinel \Contracts \Factory ;
13
14
use Monospice \LaravelRedisSentinel \RedisSentinelManager ;
14
15
15
16
/**
@@ -58,6 +59,23 @@ public function register()
58
59
{
59
60
$ this ->config = ConfigurationLoader::load ($ this ->app );
60
61
62
+ $ this ->registerServices ();
63
+
64
+ // If we want Laravel's Redis API to use Sentinel, we'll return an
65
+ // instance of the RedisSentinelManager when requesting the "redis"
66
+ // service:
67
+ if ($ this ->config ->shouldOverrideLaravelRedisApi ) {
68
+ $ this ->registerOverrides ();
69
+ }
70
+ }
71
+
72
+ /**
73
+ * Register the core Redis Sentinel connection manager.
74
+ *
75
+ * @return void
76
+ */
77
+ protected function registerServices ()
78
+ {
61
79
$ this ->app ->singleton ('redis-sentinel ' , function ($ app ) {
62
80
$ class = $ this ->config ->getVersionedRedisSentinelManagerClass ();
63
81
$ config = $ this ->config ->get ('database.redis-sentinel ' , [ ]);
@@ -66,12 +84,11 @@ public function register()
66
84
return new RedisSentinelManager (new $ class ($ driver , $ config ));
67
85
});
68
86
69
- // If we want Laravel's Redis API to use Sentinel, we'll return an
70
- // instance of the RedisSentinelManager when requesting the "redis"
71
- // service:
72
- if ($ this ->config ->shouldOverrideLaravelRedisApi ) {
73
- $ this ->registerOverrides ();
74
- }
87
+ $ this ->app ->singleton ('redis-sentinel.manager ' , function ($ app ) {
88
+ return $ app ->make ('redis-sentinel ' )->getVersionedManager ();
89
+ });
90
+
91
+ $ this ->app ->alias ('redis-sentinel ' , Factory::class);
75
92
}
76
93
77
94
/**
@@ -87,7 +104,7 @@ protected function registerOverrides()
87
104
});
88
105
89
106
$ this ->app ->bind ('redis.connection ' , function ($ app ) {
90
- return $ app ->make ('redis-sentinel ' )->connection ();
107
+ return $ app ->make ('redis-sentinel.manager ' )->connection ();
91
108
});
92
109
}
93
110
@@ -140,7 +157,7 @@ protected function addRedisSentinelBroadcaster()
140
157
{
141
158
$ this ->app ->make (BroadcastFactory::class)
142
159
->extend ('redis-sentinel ' , function ($ app , $ conf ) {
143
- $ redis = $ app ->make ('redis-sentinel ' )-> getVersionedManager ( );
160
+ $ redis = $ app ->make ('redis-sentinel.manager ' );
144
161
$ connection = Arr::get ($ conf , 'connection ' , 'default ' );
145
162
146
163
return new RedisBroadcaster ($ redis , $ connection );
@@ -158,7 +175,7 @@ protected function addRedisSentinelCacheStore()
158
175
$ cache = $ this ->app ->make ('cache ' );
159
176
160
177
$ cache ->extend ('redis-sentinel ' , function ($ app , $ conf ) use ($ cache ) {
161
- $ redis = $ app ->make ('redis-sentinel ' )-> getVersionedManager ( );
178
+ $ redis = $ app ->make ('redis-sentinel.manager ' );
162
179
$ prefix = $ app ->make ('config ' )->get ('cache.prefix ' );
163
180
$ connection = Arr::get ($ conf , 'connection ' , 'default ' );
164
181
$ store = new RedisStore ($ redis , $ prefix , $ connection );
@@ -195,7 +212,7 @@ protected function addRedisSentinelSessionHandler()
195
212
protected function addRedisSentinelQueueConnector ()
196
213
{
197
214
$ this ->app ->make ('queue ' )->extend ('redis-sentinel ' , function () {
198
- $ redis = $ this ->app ->make ('redis-sentinel ' )-> getVersionedManager ( );
215
+ $ redis = $ this ->app ->make ('redis-sentinel.manager ' );
199
216
200
217
return new RedisConnector ($ redis );
201
218
});
0 commit comments