feat: 支持 Redis 5.x

This commit is contained in:
2026-02-14 04:17:14 +08:00
parent cee9c0aa1e
commit a9c83cd544
2 changed files with 27 additions and 24 deletions

View File

@@ -74,7 +74,9 @@ public abstract class BallAPI {
private final Map<UUID, BallPlayerInfo> allPlayerInfo; private final Map<UUID, BallPlayerInfo> allPlayerInfo;
@NotNull @NotNull
private final StatefulRedisPubSubConnection<String, String> redisPubSub; private final StatefulRedisPubSubConnection<String, String> redisPub;
@NotNull
private final StatefulRedisPubSubConnection<String, String> redisSub;
@Nullable @Nullable
private ScheduledFuture<?> lockUpdater; private ScheduledFuture<?> lockUpdater;
@@ -102,7 +104,8 @@ public abstract class BallAPI {
eventBus.register(BallCommonListener.INSTANCE); eventBus.register(BallCommonListener.INSTANCE);
allServerInfo = new ConcurrentHashMap<>(); allServerInfo = new ConcurrentHashMap<>();
allPlayerInfo = new ConcurrentHashMap<>(); allPlayerInfo = new ConcurrentHashMap<>();
redisPubSub = getRedisClient().connectPubSub(); redisPub = getRedisClient().connectPubSub();
redisSub = getRedisClient().connectPubSub();
getLogger().info("频道前缀: " + ballConfig.getChannelPrefix()); getLogger().info("频道前缀: " + ballConfig.getChannelPrefix());
getLogger().info("启用子服更新玩家状态: " + ballConfig.isGameServerUpdatePlayerInfo()); getLogger().info("启用子服更新玩家状态: " + ballConfig.isGameServerUpdatePlayerInfo());
if (ballConfig.isGameServerUpdatePlayerInfo()) { if (ballConfig.isGameServerUpdatePlayerInfo()) {
@@ -112,8 +115,8 @@ public abstract class BallAPI {
getLogger().warning("已启用调试模式"); getLogger().warning("已启用调试模式");
eventBus.register(BallDebugListener.INSTANCE); eventBus.register(BallDebugListener.INSTANCE);
} }
redisPubSub.addListener(BallRedisListener.INSTANCE); redisSub.addListener(BallRedisListener.INSTANCE);
redisPubSub.sync().subscribe(BALL_CHANNEL); redisSub.sync().subscribe(BALL_CHANNEL);
} }
protected void enable() throws SQLException, InterruptedException { protected void enable() throws SQLException, InterruptedException {
@@ -219,7 +222,7 @@ public abstract class BallAPI {
statement.executeUpdate(); statement.executeUpdate();
} }
} }
redisPubSub.close(); redisPub.close();
} }
/** /**
@@ -501,12 +504,12 @@ public abstract class BallAPI {
channel = ballConfig.getChannelPrefix() + channel; channel = ballConfig.getChannelPrefix() + channel;
} }
if (block) { if (block) {
redisPubSub.sync().publish(channel, CoreAPI.getInstance().getGson().toJson(message)); redisPub.sync().publish(channel, CoreAPI.getInstance().getGson().toJson(message));
eventBus.post(new MessageSentEvent(channel, message)); eventBus.post(new MessageSentEvent(channel, message));
} else { } else {
@NotNull String finalChannel = channel; @NotNull String finalChannel = channel;
CoreAPI.getInstance().getExecutorService().execute(() -> { CoreAPI.getInstance().getExecutorService().execute(() -> {
redisPubSub.sync().publish(finalChannel, CoreAPI.getInstance().getGson().toJson(message)); redisPub.sync().publish(finalChannel, CoreAPI.getInstance().getGson().toJson(message));
eventBus.post(new MessageSentEvent(finalChannel, message)); eventBus.post(new MessageSentEvent(finalChannel, message));
}); });
} }
@@ -532,7 +535,7 @@ public abstract class BallAPI {
* @param channels 频道名称 * @param channels 频道名称
*/ */
public void subscribeRaw(@NotNull String... channels) { public void subscribeRaw(@NotNull String... channels) {
redisPubSub.sync().subscribe(channels); redisSub.sync().subscribe(channels);
} }
/** /**
@@ -541,7 +544,7 @@ public abstract class BallAPI {
* @param patterns 频道名称正则表达式 * @param patterns 频道名称正则表达式
*/ */
public void subscribePatterns(@NotNull String patterns) { public void subscribePatterns(@NotNull String patterns) {
redisPubSub.sync().psubscribe(patterns); redisSub.sync().psubscribe(patterns);
} }
/** /**
@@ -564,7 +567,7 @@ public abstract class BallAPI {
* @param channels 频道名称 * @param channels 频道名称
*/ */
public void unsubscribeRaw(@NotNull String... channels) { public void unsubscribeRaw(@NotNull String... channels) {
redisPubSub.sync().unsubscribe(channels); redisSub.sync().unsubscribe(channels);
} }
/** /**
@@ -573,7 +576,7 @@ public abstract class BallAPI {
* @param patterns 频道名称正则表达式 * @param patterns 频道名称正则表达式
*/ */
public void unsubscribePatterns(@NotNull String patterns) { public void unsubscribePatterns(@NotNull String patterns) {
redisPubSub.sync().punsubscribe(patterns); redisSub.sync().punsubscribe(patterns);
} }
@NotNull @NotNull

View File

@@ -11,7 +11,7 @@ plugins {
} }
group = "cn.hamster3.mc.plugin" group = "cn.hamster3.mc.plugin"
version = "1.8.1" version = "1.8.2"
description = "基于 Redis 的 Minecraft 服务端通用消息中间件" description = "基于 Redis 的 Minecraft 服务端通用消息中间件"
subprojects { subprojects {