feat: 添加忽略前缀订阅频道的 API

This commit is contained in:
2024-01-29 15:21:09 +08:00
parent 7716522380
commit c8eabd5a8b
2 changed files with 39 additions and 1 deletions

View File

@@ -460,6 +460,11 @@ public abstract class BallAPI {
}
}
/**
* 订阅 redis 消息频道
*
* @param channel 频道名称
*/
public void subscribe(@NotNull String... channel) {
for (int i = 0; i < channel.length; i++) {
channel[i] = ballConfig.getChannelPrefix() + channel[i];
@@ -467,10 +472,29 @@ public abstract class BallAPI {
redisPub.sync().subscribe(channel);
}
/**
* 忽略仓鼠球频道前缀配置,订阅 redis 消息频道
*
* @param channel 频道名称
*/
public void subscribeIgnorePrefix(@NotNull String... channel) {
redisPub.sync().subscribe(channel);
}
/**
* 订阅 redis 消息频道(正则)
*
* @param patterns 频道名称正则表达式
*/
public void subscribePatterns(@NotNull String patterns) {
redisPub.sync().psubscribe(patterns);
}
/**
* 取消订阅 redis 频道
*
* @param channel 频道名称
*/
public void unsubscribe(@NotNull String... channel) {
for (int i = 0; i < channel.length; i++) {
channel[i] = ballConfig.getChannelPrefix() + channel[i];
@@ -478,6 +502,20 @@ public abstract class BallAPI {
redisPub.sync().unsubscribe(channel);
}
/**
* 忽略仓鼠球频道前缀配置,取消订阅 redis 频道
*
* @param channel 频道名称
*/
public void unsubscribeIgnorePrefix(@NotNull String... channel) {
redisPub.sync().unsubscribe(channel);
}
/**
* 取消订阅 redis 消息频道(正则)
*
* @param patterns 频道名称正则表达式
*/
public void unsubscribePatterns(@NotNull String patterns) {
redisPub.sync().punsubscribe(patterns);
}