@@ -104,13 +104,13 @@ public function publish($appId, string $channel, stdClass $payload): bool
104
104
105
105
$ payload = json_encode ($ payload );
106
106
107
- $ this ->publishClient ->__call ('publish ' , ["{ $ appId} : { $ channel}" , $ payload ]);
107
+ $ this ->publishClient ->__call ('publish ' , [$ this -> getTopicName ( $ appId, $ channel) , $ payload ]);
108
108
109
109
DashboardLogger::log ($ appId , DashboardLogger::TYPE_REPLICATOR_MESSAGE_PUBLISHED , [
110
110
'channel ' => $ channel ,
111
111
'serverId ' => $ this ->getServerId (),
112
112
'payload ' => $ payload ,
113
- 'pubsub ' => "{ $ appId} : { $ channel}" ,
113
+ 'pubsub ' => $ this -> getTopicName ( $ appId, $ channel) ,
114
114
]);
115
115
116
116
return true ;
@@ -127,7 +127,7 @@ public function subscribe($appId, string $channel): bool
127
127
{
128
128
if (! isset ($ this ->subscribedChannels ["{$ appId }: {$ channel }" ])) {
129
129
// We're not subscribed to the channel yet, subscribe and set the count to 1
130
- $ this ->subscribeClient ->__call ('subscribe ' , ["{ $ appId} : { $ channel}" ]);
130
+ $ this ->subscribeClient ->__call ('subscribe ' , [$ this -> getTopicName ( $ appId, $ channel) ]);
131
131
$ this ->subscribedChannels ["{$ appId }: {$ channel }" ] = 1 ;
132
132
} else {
133
133
// Increment the subscribe count if we've already subscribed
@@ -137,7 +137,7 @@ public function subscribe($appId, string $channel): bool
137
137
DashboardLogger::log ($ appId , DashboardLogger::TYPE_REPLICATOR_SUBSCRIBED , [
138
138
'channel ' => $ channel ,
139
139
'serverId ' => $ this ->getServerId (),
140
- 'pubsub ' => "{ $ appId} : { $ channel}" ,
140
+ 'pubsub ' => $ this -> getTopicName ( $ appId, $ channel) ,
141
141
]);
142
142
143
143
return true ;
@@ -169,7 +169,7 @@ public function unsubscribe($appId, string $channel): bool
169
169
DashboardLogger::log ($ appId , DashboardLogger::TYPE_REPLICATOR_UNSUBSCRIBED , [
170
170
'channel ' => $ channel ,
171
171
'serverId ' => $ this ->getServerId (),
172
- 'pubsub ' => "{ $ appId} : { $ channel}" ,
172
+ 'pubsub ' => $ this -> getTopicName ( $ appId, $ channel) ,
173
173
]);
174
174
175
175
return true ;
@@ -194,7 +194,7 @@ public function joinChannel($appId, string $channel, string $socketId, string $d
194
194
'serverId ' => $ this ->getServerId (),
195
195
'socketId ' => $ socketId ,
196
196
'data ' => $ data ,
197
- 'pubsub ' => "{ $ appId} : { $ channel}" ,
197
+ 'pubsub ' => $ this -> getTopicName ( $ appId, $ channel) ,
198
198
]);
199
199
}
200
200
@@ -209,13 +209,13 @@ public function joinChannel($appId, string $channel, string $socketId, string $d
209
209
*/
210
210
public function leaveChannel ($ appId , string $ channel , string $ socketId )
211
211
{
212
- $ this ->publishClient ->__call ('hdel ' , ["{ $ appId} : { $ channel}" , $ socketId ]);
212
+ $ this ->publishClient ->__call ('hdel ' , [$ this -> getTopicName ( $ appId, $ channel) , $ socketId ]);
213
213
214
214
DashboardLogger::log ($ appId , DashboardLogger::TYPE_REPLICATOR_LEFT_CHANNEL , [
215
215
'channel ' => $ channel ,
216
216
'serverId ' => $ this ->getServerId (),
217
217
'socketId ' => $ socketId ,
218
- 'pubsub ' => "{ $ appId} : { $ channel}" ,
218
+ 'pubsub ' => $ this -> getTopicName ( $ appId, $ channel) ,
219
219
]);
220
220
}
221
221
@@ -228,7 +228,7 @@ public function leaveChannel($appId, string $channel, string $socketId)
228
228
*/
229
229
public function channelMembers ($ appId , string $ channel ): PromiseInterface
230
230
{
231
- return $ this ->publishClient ->__call ('hgetall ' , ["{ $ appId} : { $ channel}" ])
231
+ return $ this ->publishClient ->__call ('hgetall ' , [$ this -> getTopicName ( $ appId, $ channel) ])
232
232
->then (function ($ members ) {
233
233
// The data is expected as objects, so we need to JSON decode
234
234
return array_map (function ($ user ) {
@@ -249,7 +249,7 @@ public function channelMemberCounts($appId, array $channelNames): PromiseInterfa
249
249
$ this ->publishClient ->__call ('multi ' , []);
250
250
251
251
foreach ($ channelNames as $ channel ) {
252
- $ this ->publishClient ->__call ('hlen ' , ["{ $ appId} : { $ channel}" ]);
252
+ $ this ->publishClient ->__call ('hlen ' , [$ this -> getTopicName ( $ appId, $ channel) ]);
253
253
}
254
254
255
255
return $ this ->publishClient ->__call ('exec ' , [])
@@ -371,4 +371,19 @@ public function getServerId()
371
371
{
372
372
return $ this ->serverId ;
373
373
}
374
+
375
+ /**
376
+ * Get the Pub/Sub Topic name to subscribe based on the
377
+ * app ID and channel name.
378
+ *
379
+ * @param mixed $appId
380
+ * @param string $channel
381
+ * @return string
382
+ */
383
+ protected function getTopicName ($ appId , string $ channel ): string
384
+ {
385
+ $ prefix = config ('database.redis.options.prefix ' , null );
386
+
387
+ return "{$ prefix }{$ appId }: {$ channel }" ;
388
+ }
374
389
}
0 commit comments