feat: 添加 lettuce-core 用于连接 redis
All checks were successful
Publish Project / build (push) Successful in 2m43s
All checks were successful
Publish Project / build (push) Successful in 2m43s
This commit is contained in:
@@ -17,14 +17,18 @@ dependencies {
|
||||
exclude(group = "com.google.code.gson")
|
||||
}
|
||||
|
||||
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
|
||||
compileOnly("com.zaxxer:HikariCP:4.0.3") { isTransitive = false }
|
||||
// https://mvnrepository.com/artifact/redis.clients/jedis
|
||||
compileOnlyApi("redis.clients:jedis:5.1.4") {
|
||||
exclude(group = "com.google.code.gson")
|
||||
exclude(group = "org.slf4j")
|
||||
}
|
||||
|
||||
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
|
||||
compileOnly("com.zaxxer:HikariCP:4.0.3") { isTransitive = false }
|
||||
// https://mvnrepository.com/artifact/io.lettuce/lettuce-core
|
||||
compileOnlyApi("io.lettuce:lettuce-core:6.7.1.RELEASE") {
|
||||
exclude(group = "io.netty")
|
||||
exclude(group = "org.slf4j")
|
||||
}
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
@@ -6,6 +6,9 @@ import cn.hamster3.mc.plugin.core.common.util.CoreUtils;
|
||||
import cn.hamster3.mc.plugin.core.common.util.SimpleLogger;
|
||||
import com.google.gson.Gson;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import io.lettuce.core.RedisClient;
|
||||
import io.lettuce.core.api.StatefulRedisConnection;
|
||||
import io.lettuce.core.pubsub.StatefulRedisPubSubConnection;
|
||||
import lombok.Getter;
|
||||
import net.kyori.adventure.platform.AudienceProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -41,6 +44,11 @@ public abstract class CoreAPI {
|
||||
*/
|
||||
@Nullable
|
||||
private JedisPool jedisPool;
|
||||
/**
|
||||
* Lettuce Redis 连接池
|
||||
*/
|
||||
@Nullable
|
||||
private RedisClient redisClient;
|
||||
/**
|
||||
* 公用数据库连接池
|
||||
*/
|
||||
@@ -57,6 +65,7 @@ public abstract class CoreAPI {
|
||||
if (enableRedis) {
|
||||
logger.info("正在创建 Redis 连接池");
|
||||
jedisPool = new JedisPool(config.getString("redis-url"));
|
||||
redisClient = RedisClient.create(config.getString("redis-url"));
|
||||
logger.info("Redis 连接池创建完成");
|
||||
} else {
|
||||
logger.info("未启用 Redis 功能");
|
||||
@@ -108,6 +117,24 @@ public abstract class CoreAPI {
|
||||
throw new IllegalStateException("仓鼠核心未启用 Redis 功能");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public RedisClient getRedisClient() {
|
||||
if (redisClient != null) {
|
||||
return redisClient;
|
||||
}
|
||||
throw new IllegalStateException("仓鼠核心未启用 Redis 功能");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public StatefulRedisConnection<String, String> getRedisConnect() {
|
||||
return getRedisClient().connect();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public StatefulRedisPubSubConnection<String, String> getRedisPubSub() {
|
||||
return getRedisClient().connectPubSub();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract SimpleLogger getLogger();
|
||||
|
||||
|
Reference in New Issue
Block a user