This commit is contained in:
2023-12-27 10:43:20 +08:00
parent 6c4fbc47ab
commit 2183444676
12 changed files with 446 additions and 568 deletions

View File

@@ -9,6 +9,8 @@ import java.util.Properties;
import java.util.Set;
import com.alibaba.fastjson2.JSONObject;
import org.apache.ibatis.mapping.Environment;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
@@ -19,6 +21,7 @@ public class RedisTools {
private static boolean isNotInstallRedis = false;
private static String host;
private static int port;
private static String auth;
public static int TOKEN_TIMEOUT_DEFAULT = 360;
private RedisTools() {
@@ -26,12 +29,11 @@ public class RedisTools {
}
// 写成静态代码块形式,只加载一次,节省资源
static {
//Properties properties = PropertyUtil.loadProperties("jedis.properties");
//host = properties.getProperty("redis.host");
//port = Integer.valueOf(properties.getProperty("redis.port"));
public static void initConfig(int port, String auth) {
host = "127.0.0.1";
port = 6379;
RedisTools.port = port;
RedisTools.auth = auth;
}
@@ -135,18 +137,21 @@ public class RedisTools {
jedis.close();
return flag;
}
public static boolean exists(String key){
if(isNotInstallRedis){
public static boolean exists(String key) {
if (isNotInstallRedis) {
return false;
}
Jedis jedis=getRedis();
boolean flag=jedis.exists(key);
Jedis jedis = getRedis();
boolean flag = jedis.exists(key);
jedis.close();
return flag;
}
public static Jedis getRedis() {
return new Jedis(host, port);
Jedis jedis = new Jedis(host, port);
jedis.auth(auth);
return jedis;
}
public static boolean remove(String key, int index) {
@@ -195,6 +200,7 @@ public class RedisTools {
return flag;
}
private static class PropertyUtil {
// 加载property文件到io流里面