@@ -130,9 +130,8 @@ public function subscribeToChannel(ConnectionInterface $connection, string $chan
130
130
}
131
131
});
132
132
133
- $ this ->getPublishClient ()->sadd (
134
- $ this ->getRedisKey ($ connection ->app ->id , null , ['channels ' ]),
135
- $ channelName
133
+ $ this ->addChannelToSet (
134
+ $ connection ->app ->id , $ channelName
136
135
);
137
136
138
137
$ this ->incrementSubscriptionsCount (
@@ -157,25 +156,19 @@ public function unsubscribeFromChannel(ConnectionInterface $connection, string $
157
156
if ($ count === 0 ) {
158
157
$ this ->unsubscribeFromTopic ($ connection ->app ->id , $ channelName );
159
158
160
- $ this ->getPublishClient ()->srem (
161
- $ this ->getRedisKey ($ connection ->app ->id , null , ['channels ' ]),
162
- $ channelName
163
- );
159
+ $ this ->removeChannelFromSet ($ connection ->app ->id , $ channelName );
164
160
165
161
return ;
166
162
}
167
163
168
- $ increment = $ this ->incrementSubscriptionsCount (
169
- $ connection ->app ->id , $ channelName , - 1
164
+ $ this ->decrementSubscriptionsCount (
165
+ $ connection ->app ->id , $ channelName ,
170
166
)
171
167
->then (function ($ count ) use ($ connection , $ channelName ) {
172
168
if ($ count < 1 ) {
173
169
$ this ->unsubscribeFromTopic ($ connection ->app ->id , $ channelName );
174
170
175
- $ this ->getPublishClient ()->srem (
176
- $ this ->getRedisKey ($ connection ->app ->id , null , ['channels ' ]),
177
- $ channelName
178
- );
171
+ $ this ->removeChannelFromSet ($ connection ->app ->id , $ channelName );
179
172
}
180
173
});
181
174
});
@@ -456,6 +449,49 @@ public function incrementSubscriptionsCount($appId, string $channel = null, int
456
449
);
457
450
}
458
451
452
+ /**
453
+ * Decrement the subscribed count number.
454
+ *
455
+ * @param string|int $appId
456
+ * @param string|null $channel
457
+ * @param int $decrement
458
+ * @return PromiseInterface
459
+ */
460
+ public function decrementSubscriptionsCount ($ appId , string $ channel = null , int $ increment = 1 )
461
+ {
462
+ return $ this ->incrementSubscriptionsCount ($ appId , $ channel , $ increment * -1 );
463
+ }
464
+
465
+ /**
466
+ * Add a channel to the set list.
467
+ *
468
+ * @param string|int $appId
469
+ * @param string $channel
470
+ * @return PromiseInterface
471
+ */
472
+ public function addChannelToSet ($ appId , string $ channel )
473
+ {
474
+ return $ this ->getPublishClient ()->sadd (
475
+ $ this ->getRedisKey ($ appId , null , ['channels ' ]),
476
+ $ channel
477
+ );
478
+ }
479
+
480
+ /**
481
+ * Remove a channel from the set list.
482
+ *
483
+ * @param string|int $appId
484
+ * @param string $channel
485
+ * @return PromiseInterface
486
+ */
487
+ public function removeChannelFromSet ($ appId , string $ channel )
488
+ {
489
+ return $ this ->getPublishClient ()->srem (
490
+ $ this ->getRedisKey ($ appId , null , ['channels ' ]),
491
+ $ channel
492
+ );
493
+ }
494
+
459
495
/**
460
496
* Set data for a topic. Might be used for the presence channels.
461
497
*
0 commit comments