@@ -104,13 +104,13 @@ public function publish($appId, string $channel, stdClass $payload): bool
104104
105105 $ payload = json_encode ($ payload );
106106
107- $ this ->publishClient ->__call ('publish ' , ["{ $ appId} : { $ channel}" , $ payload ]);
107+ $ this ->publishClient ->__call ('publish ' , [$ this -> getTopicName ( $ appId, $ channel) , $ payload ]);
108108
109109 DashboardLogger::log ($ appId , DashboardLogger::TYPE_REPLICATOR_MESSAGE_PUBLISHED , [
110110 'channel ' => $ channel ,
111111 'serverId ' => $ this ->getServerId (),
112112 'payload ' => $ payload ,
113- 'pubsub ' => "{ $ appId} : { $ channel}" ,
113+ 'pubsub ' => $ this -> getTopicName ( $ appId, $ channel) ,
114114 ]);
115115
116116 return true ;
@@ -127,7 +127,7 @@ public function subscribe($appId, string $channel): bool
127127 {
128128 if (! isset ($ this ->subscribedChannels ["{$ appId }: {$ channel }" ])) {
129129 // 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) ]);
131131 $ this ->subscribedChannels ["{$ appId }: {$ channel }" ] = 1 ;
132132 } else {
133133 // Increment the subscribe count if we've already subscribed
@@ -137,7 +137,7 @@ public function subscribe($appId, string $channel): bool
137137 DashboardLogger::log ($ appId , DashboardLogger::TYPE_REPLICATOR_SUBSCRIBED , [
138138 'channel ' => $ channel ,
139139 'serverId ' => $ this ->getServerId (),
140- 'pubsub ' => "{ $ appId} : { $ channel}" ,
140+ 'pubsub ' => $ this -> getTopicName ( $ appId, $ channel) ,
141141 ]);
142142
143143 return true ;
@@ -169,7 +169,7 @@ public function unsubscribe($appId, string $channel): bool
169169 DashboardLogger::log ($ appId , DashboardLogger::TYPE_REPLICATOR_UNSUBSCRIBED , [
170170 'channel ' => $ channel ,
171171 'serverId ' => $ this ->getServerId (),
172- 'pubsub ' => "{ $ appId} : { $ channel}" ,
172+ 'pubsub ' => $ this -> getTopicName ( $ appId, $ channel) ,
173173 ]);
174174
175175 return true ;
@@ -194,7 +194,7 @@ public function joinChannel($appId, string $channel, string $socketId, string $d
194194 'serverId ' => $ this ->getServerId (),
195195 'socketId ' => $ socketId ,
196196 'data ' => $ data ,
197- 'pubsub ' => "{ $ appId} : { $ channel}" ,
197+ 'pubsub ' => $ this -> getTopicName ( $ appId, $ channel) ,
198198 ]);
199199 }
200200
@@ -209,13 +209,13 @@ public function joinChannel($appId, string $channel, string $socketId, string $d
209209 */
210210 public function leaveChannel ($ appId , string $ channel , string $ socketId )
211211 {
212- $ this ->publishClient ->__call ('hdel ' , ["{ $ appId} : { $ channel}" , $ socketId ]);
212+ $ this ->publishClient ->__call ('hdel ' , [$ this -> getTopicName ( $ appId, $ channel) , $ socketId ]);
213213
214214 DashboardLogger::log ($ appId , DashboardLogger::TYPE_REPLICATOR_LEFT_CHANNEL , [
215215 'channel ' => $ channel ,
216216 'serverId ' => $ this ->getServerId (),
217217 'socketId ' => $ socketId ,
218- 'pubsub ' => "{ $ appId} : { $ channel}" ,
218+ 'pubsub ' => $ this -> getTopicName ( $ appId, $ channel) ,
219219 ]);
220220 }
221221
@@ -228,7 +228,7 @@ public function leaveChannel($appId, string $channel, string $socketId)
228228 */
229229 public function channelMembers ($ appId , string $ channel ): PromiseInterface
230230 {
231- return $ this ->publishClient ->__call ('hgetall ' , ["{ $ appId} : { $ channel}" ])
231+ return $ this ->publishClient ->__call ('hgetall ' , [$ this -> getTopicName ( $ appId, $ channel) ])
232232 ->then (function ($ members ) {
233233 // The data is expected as objects, so we need to JSON decode
234234 return array_map (function ($ user ) {
@@ -249,7 +249,7 @@ public function channelMemberCounts($appId, array $channelNames): PromiseInterfa
249249 $ this ->publishClient ->__call ('multi ' , []);
250250
251251 foreach ($ channelNames as $ channel ) {
252- $ this ->publishClient ->__call ('hlen ' , ["{ $ appId} : { $ channel}" ]);
252+ $ this ->publishClient ->__call ('hlen ' , [$ this -> getTopicName ( $ appId, $ channel) ]);
253253 }
254254
255255 return $ this ->publishClient ->__call ('exec ' , [])
@@ -371,4 +371,19 @@ public function getServerId()
371371 {
372372 return $ this ->serverId ;
373373 }
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+ }
374389}
0 commit comments