feat: 将 lettuce 改为 jedis

This commit is contained in:
2024-03-13 17:10:41 +08:00
parent ffc2ecc2ee
commit f6233f7e82
8 changed files with 28 additions and 28 deletions

View File

@@ -5,7 +5,7 @@ plugins {
}
group = "cn.hamster3.mc.plugin"
version = "1.2.4"
version = "1.3.0"
subprojects {
apply {
@@ -48,11 +48,6 @@ subprojects {
}
shadowJar {
archiveClassifier = ""
relocate("io.lettuce", "cn.hamster3.mc.plugin.core.lib.io.lettuce")
relocate("io.netty", "cn.hamster3.mc.plugin.core.lib.io.netty")
relocate("reactor", "cn.hamster3.mc.plugin.core.lib.reactor")
relocate("org.reactivestreams", "cn.hamster3.mc.plugin.core.lib.org.reactivestreams")
relocate("org.quartz", "cn.hamster3.mc.plugin.core.lib.org.quartz")
relocate("org.terracotta.quartz", "cn.hamster3.mc.plugin.core.lib.org.terracotta.quartz")
relocate("com.zaxxer.hikari", "cn.hamster3.mc.plugin.core.lib.com.zaxxer.hikari")

View File

@@ -1,10 +1,12 @@
@file:Suppress("VulnerableLibrariesLocal")
evaluationDependsOn(":core-common")
dependencies {
implementation(project(":core-common")) {
isTransitive = false
}
compileOnly("org.spigotmc:spigot-api:1.20.4-R0.1-SNAPSHOT")
compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
implementation("de.tr7zw:item-nbt-api:2.12.3-SNAPSHOT")
compileOnly("net.milkbowl.vault:VaultAPI:1.7") {
@@ -28,8 +30,11 @@ dependencies {
implementation("com.zaxxer:HikariCP:4.0.3") {
exclude(group = "org.slf4j")
}
// https://mvnrepository.com/artifact/io.lettuce/lettuce-core
implementation("io.lettuce:lettuce-core:6.3.1.RELEASE")
// https://mvnrepository.com/artifact/redis.clients/jedis
implementation("redis.clients:jedis:5.1.2") {
exclude(group = "com.google.code.gson")
exclude(group = "org.slf4j")
}
// https://mvnrepository.com/artifact/org.quartz-scheduler/quartz
implementation("org.quartz-scheduler:quartz:2.3.2") {
isTransitive = false

View File

@@ -109,7 +109,7 @@ public class HamsterCorePlugin extends JavaPlugin {
public void onDisable() {
long start = System.currentTimeMillis();
Logger logger = getLogger();
CoreAPI.getInstance().getRedisClient().close();
CoreAPI.getInstance().getJedisPool().close();
logger.info("已关闭 Redis 连接池");
CoreAPI.getInstance().getHikariDataSource().close();
logger.info("已关闭数据库连接池");

View File

@@ -6,7 +6,6 @@
# 若没有设置 redis 用户名,也没有设置密码,则可以使用以下格式:
# redis://localhost:6379/0?clientName=HamsterCore
# 若不设置数据库,则默认使用 0
# 详细信息https://github.com/lettuce-io/lettuce-core/wiki/Redis-URI-and-connection-details
redis-url: "redis://localhost:6379/0?clientName=HamsterCore&timeout=5s"
datasource:

View File

@@ -20,8 +20,11 @@ dependencies {
implementation("com.zaxxer:HikariCP:4.0.3") {
exclude(group = "org.slf4j")
}
// https://mvnrepository.com/artifact/io.lettuce/lettuce-core
implementation("io.lettuce:lettuce-core:6.3.1.RELEASE")
// https://mvnrepository.com/artifact/redis.clients/jedis
implementation("redis.clients:jedis:5.1.2") {
exclude(group = "com.google.code.gson")
exclude(group = "org.slf4j")
}
// https://mvnrepository.com/artifact/org.quartz-scheduler/quartz
implementation("org.quartz-scheduler:quartz:2.3.2") {
isTransitive = false

View File

@@ -62,7 +62,7 @@ public class HamsterCorePlugin extends Plugin {
public void onDisable() {
long start = System.currentTimeMillis();
Logger logger = getLogger();
CoreAPI.getInstance().getRedisClient().close();
CoreAPI.getInstance().getJedisPool().close();
logger.info("已关闭 Redis 连接池");
CoreAPI.getInstance().getHikariDataSource().close();
logger.info("已关闭数据库连接池");

View File

@@ -5,24 +5,22 @@ dependencies {
// https://mvnrepository.com/artifact/org.yaml/snakeyaml
compileOnly("org.yaml:snakeyaml:1.19")
implementation("net.kyori:adventure-platform-api:4.3.2") {
compileOnly("net.kyori:adventure-platform-api:4.3.2") {
exclude(group = "org.jetbrains")
}
implementation("net.kyori:adventure-text-serializer-gson:4.13.1") {
compileOnly("net.kyori:adventure-text-serializer-gson:4.13.1") {
exclude(group = "org.jetbrains")
exclude(group = "com.google.code.gson")
}
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
compileOnly("com.zaxxer:HikariCP:5.1.0") { isTransitive = false }
// https://mvnrepository.com/artifact/io.lettuce/lettuce-core
implementation("io.lettuce:lettuce-core:6.3.1.RELEASE") {
exclude(group = "io.netty")
}
implementation("org.quartz-scheduler:quartz:2.3.2") {
isTransitive = false
compileOnly("com.zaxxer:HikariCP:4.0.3") { isTransitive = false }
// https://mvnrepository.com/artifact/redis.clients/jedis
implementation("redis.clients:jedis:5.1.2") {
exclude(group = "com.google.code.gson")
exclude(group = "org.slf4j")
}
compileOnly("org.quartz-scheduler:quartz:2.3.2") { isTransitive = false }
}
tasks {

View File

@@ -5,10 +5,10 @@ import cn.hamster3.mc.plugin.core.common.thread.NamedThreadFactory;
import com.google.gson.Gson;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import io.lettuce.core.RedisClient;
import lombok.Getter;
import net.kyori.adventure.platform.AudienceProvider;
import org.jetbrains.annotations.NotNull;
import redis.clients.jedis.JedisPool;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -23,11 +23,11 @@ public abstract class CoreAPI {
@Getter
protected static CoreAPI instance;
/**
* lettuce redis 客户端
* Redis 连接池
*/
@Getter
@NotNull
private final RedisClient redisClient;
private final JedisPool jedisPool;
/**
* HamsterCore 公用数据库连接池
*/
@@ -50,7 +50,7 @@ public abstract class CoreAPI {
scheduledService = Executors.newScheduledThreadPool(1, new NamedThreadFactory("HamsterCore - Scheduler"));
getLogger().info("正在创建 redis 客户端");
redisClient = RedisClient.create(config.getString("redis-url"));
jedisPool = new JedisPool(config.getString("redis-url"));
getLogger().info("redis 客户端创建完成");
ConfigSection datasourceConfig = config.getSection("datasource");