diff --git a/pom.xml b/pom.xml
index fd0a57a..dfec3ce 100644
--- a/pom.xml
+++ b/pom.xml
@@ -50,7 +50,7 @@
1.2.4
1.4.2.Final
-
+ 3.20.0
${project.artifactId}-${project.version}
target/build
@@ -268,6 +268,12 @@
system
${project.basedir}/lib/spire.doc.free-5.2.0.jar
+
+
+ org.redisson
+ redisson
+ ${redisson.version}
+
diff --git a/src/main/java/com/ydool/common/config/LogConfig.java b/src/main/java/com/ydool/common/config/LogConfig.java
index 3276b27..802ee2f 100644
--- a/src/main/java/com/ydool/common/config/LogConfig.java
+++ b/src/main/java/com/ydool/common/config/LogConfig.java
@@ -1,6 +1,10 @@
package com.ydool.common.config;
import com.ydool.common.interceptor.SqlLogInterceptor;
+import org.redisson.Redisson;
+import org.redisson.api.RedissonClient;
+import org.redisson.config.Config;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -10,4 +14,17 @@ public class LogConfig {
public SqlLogInterceptor sqlLogInterceptor() {
return new SqlLogInterceptor();
}
+
+
+ @Value("${redis:address}")
+ private String address;
+ @Value("${redis:password}")
+ private String password;
+
+ @Bean
+ public RedissonClient redissonClient(){
+ Config config = new Config();
+ config.useSingleServer().setAddress(address).setPassword(password);
+ return Redisson.create();
+ }
}
diff --git a/src/main/java/com/ydool/common/constant/RedissonConstant.java b/src/main/java/com/ydool/common/constant/RedissonConstant.java
new file mode 100644
index 0000000..6931174
--- /dev/null
+++ b/src/main/java/com/ydool/common/constant/RedissonConstant.java
@@ -0,0 +1,20 @@
+package com.ydool.common.constant;
+
+public interface RedissonConstant {
+ /**
+ * 验证码
+ */
+ String CAPTCHA_CODE = "lc:::oa:::captcha:::code";
+ /**
+ * ip请求验证码接口次数
+ */
+ String CAPTCHA_CODE_COUNT = "lc:::oa:::captcha:::code:::count";
+ /**
+ * ip连续登录失败次数
+ */
+ String LOGIN_FAIL_COUNT = "lc:::oa:::login:::fail:::count";
+ /**
+ * ip黑名单
+ */
+ String IP_BLACK_LIST = "lc:::oa:::ip:::black:::list";
+}
diff --git a/src/main/java/com/ydool/common/utils/RedisUtils.java b/src/main/java/com/ydool/common/utils/RedisUtils.java
new file mode 100644
index 0000000..2808528
--- /dev/null
+++ b/src/main/java/com/ydool/common/utils/RedisUtils.java
@@ -0,0 +1,498 @@
+package com.ydool.common.utils;
+
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.json.JSONUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import lombok.extern.slf4j.Slf4j;
+import org.redisson.api.*;
+import org.redisson.client.codec.StringCodec;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+
+/**
+ * @author liuhaoze
+ * @date 2023/7/17 11:00
+ */
+
+@Slf4j
+@Component
+@ConditionalOnProperty(name = "redis.redisson.enabled", havingValue = "true")
+public class RedisUtils {
+
+ @Resource
+ private RedissonClient redissonClient;
+
+
+ //----------------------------------------------------------------
+
+ /**
+ * 获取 字符串 的 RSetCache
+ *
+ * @param name 缓存名称
+ * @return RSetCache
+ */
+ public RSetCache getSetCache(String name) {
+ RSetCache setCache = redissonClient.getSetCache(name, StringCodec.INSTANCE);
+ return setCache;
+ }
+
+ /**
+ * 新增 RSetCache 数据
+ *
+ * @param name 缓存名称
+ * @param value 值
+ * @param size 缓存时间 单位:s
+ * @param timeUnit 缓存时间单位
+ * @return 是否新增成功
+ */
+ public boolean addSetCache(String name, String value, Integer size, TimeUnit timeUnit) {
+
+ if (ObjectUtil.isNotNull(size) && ObjectUtil.isNotNull(timeUnit)) {
+ return this.getSetCache(name).add(value, size, timeUnit);
+ }
+ return this.getSetCache(name).add(value);
+ }
+
+ /**
+ * 新增 RSetCache 数据
+ *
+ * @param name 缓存名称
+ * @param value 值
+ * @return 是否新增成功
+ */
+ public boolean addSetCache(String name, String value) {
+ return this.getSetCache(name).add(value);
+ }
+
+ /**
+ * 删除 RSetCache 数据
+ *
+ * @param name 缓存名称
+ * @param value 需要移除的值
+ * @return 是否移除成功
+ */
+ public boolean removeSetCache(String name, String value) {
+ return this.getSetCache(name).remove(value);
+ }
+
+ /**
+ * 验证RSetCache里是否包含
+ *
+ * @param name 缓存name
+ * @param value 需要验证的值
+ * @return 是否包含
+ */
+ public boolean setCacheContains(String name, String value) {
+ return this.getSetCache(name).contains(value);
+ }
+
+ /**
+ * 刷新RSetCache的某个参数的缓存时间
+ *
+ * @param name 缓存name
+ * @param value 需要刷新缓存时间的值
+ * @param size 缓存时间
+ * @param timeUnit 缓存时间单位
+ * @return
+ */
+ public boolean setCacheRefresh(String name, String value, Integer size, TimeUnit timeUnit) {
+ this.removeSetCache(name, value);
+ return this.addSetCache(name, value, size, timeUnit);
+ }
+ //----------------------------------------------------------------
+
+
+ //----------------------------------------------------------------
+
+ /**
+ * 获取 RMapCache
+ *
+ * @param name 缓存名
+ * @return RMapCache
+ */
+ public RMapCache getMapCache(String name) {
+ return redissonClient.getMapCache(name, StringCodec.INSTANCE);
+ }
+
+ /**
+ * 获取 RMapCache
+ *
+ * @param name 缓存名
+ * @param key 键
+ * @return 返回 返回结果
+ */
+ public Object getMapCache(String name, String key) {
+ return getMapCache(name).get(key);
+ }
+
+ /**
+ * 新增 RMapCache 数据
+ *
+ * @param name 缓存名称
+ * @param key 键
+ * @param value 值
+ * @param size 缓存时间 单位:s
+ * @param timeUnit 缓存时间单位
+ * @return 返回 返回结果
+ */
+ public Object putMapCache(String name, String key, Object value, Integer size, TimeUnit timeUnit) {
+ if (ObjectUtil.isNotNull(size) && ObjectUtil.isNotNull(timeUnit)) {
+ return getMapCache(name).put(key, value, size, timeUnit);
+ }
+ return getMapCache(name).put(key, value);
+ }
+
+ /**
+ * 新增 RMapCache 数据
+ *
+ * @param name 缓存名称
+ * @param key 键
+ * @param value 值
+ * @return 返回 返回结果
+ */
+ public Object putMapCache(String name, String key, Object value) {
+ return getMapCache(name).put(key, value);
+ }
+
+ /**
+ * 删除 RMapCache 数据
+ *
+ * @param name 缓存名称
+ * @param key 键
+ * @return 返回 返回结果
+ */
+ public Object removeMapCache(String name, String key) {
+ return getMapCache(name).remove(key);
+ }
+
+ /**
+ * 更新 RMapCache 数据
+ *
+ * @param name 缓存名称
+ * @param key 键
+ * @param value 值
+ * @param size 缓存时间 单位:s
+ * @param timeUnit 缓存时间单位
+ * @return 返回 返回结果
+ */
+ public Object mapCacheRefresh(String name, String key, Object value, Integer size, TimeUnit timeUnit) {
+ this.removeMapCache(name, key);
+ return this.putMapCache(name, key, value, size, timeUnit);
+ }
+ //----------------------------------------------------------------
+
+
+
+ //----------------------------------------------------------------
+ /**
+ * 获取 字符串 的 RSet
+ *
+ * @param name 缓存名称
+ * @return RSet
+ */
+ public RSet getSet(String name) {
+ RSet set = redissonClient.getSet(name, StringCodec.INSTANCE);
+ return set;
+ }
+
+ /**
+ * 新增 RSet 数据
+ *
+ * @param name 缓存名称
+ * @param value 值
+ * @return 是否新增成功
+ */
+ public boolean addSet(String name, String value) {
+ return this.getSet(name).add(value);
+ }
+
+ /**
+ * 新增 RSet 数据
+ *
+ * @param name 缓存名称
+ * @param values 值
+ * @return 是否新增成功
+ */
+ public boolean addSet(String name, List values) {
+ return this.getSet(name).addAll(values);
+ }
+
+ /**
+ * 删除 RSet 数据
+ *
+ * @param name 缓存名称
+ * @param value 需要移除的值
+ * @return 是否移除成功
+ */
+ public boolean removeSet(String name, String value) {
+ return this.getSet(name).remove(value);
+ }
+
+
+ /**
+ * 验证是否包含
+ *
+ * @param name 缓存name
+ * @param value 需要验证的值
+ * @return 是否包含
+ */
+ public boolean contains(String name, String value) {
+ return this.getSet(name).contains(value);
+ }
+ //----------------------------------------------------------------
+
+
+ //----------------------------------------------------------------
+
+
+ /**
+ * 获取 RMap
+ *
+ * @param name 缓存名
+ * @return RMap
+ */
+ public RMap getMap(String name) {
+ RMap map = redissonClient.getMap(name, StringCodec.INSTANCE);
+ return map;
+ }
+
+
+ /**
+ * 获取 RMap
+ *
+ * @param name 缓存名
+ * @param key 键
+ * @return 返回 返回结果
+ */
+ public Object getMapObject(String name, String key) {
+ return getMap(name).get(key);
+ }
+
+ /**
+ * 新增 RMap 数据
+ *
+ * @param name 名称
+ * @param key 键
+ * @param value 值
+ * @return 返回 返回结果
+ */
+ public Object putMap(String name, String key, Object value) {
+ return this.getMap(name).put(key, value);
+ }
+
+ /**
+ * 新增 RMap 数据
+ *
+ * @param name 名称
+ * @param map 值
+ */
+ public void putAllMap(String name, Map map) {
+ this.getMap(name).putAll(map);
+ }
+
+ /**
+ * 删除 RMap 数据
+ *
+ * @param name 名称
+ * @param key 键
+ * @return 返回 返回结果
+ */
+ public Object removeMap(String name, String key) {
+ return this.getMap(name).remove(key);
+ }
+
+ //----------------------------------------------------------------
+
+ /**
+ * SET缓存
+ * @param name 缓存KEY
+ * @param value 缓存值
+ */
+ public void set(String name, Object value) {
+ set(name, value, null);
+ }
+
+ /**
+ * SET缓存
+ * @param name 缓存KEY
+ * @param value 缓存值
+ * @param seconds 缓存秒数
+ */
+ public void set(String name, Object value, Integer seconds) {
+ RBucket