增加 Redis 分布式锁
parent
94dfe41153
commit
53db9de93d
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"local": {
|
"local": {
|
||||||
"baseUrl": "http://127.0.0.1:8080/api",
|
"baseUrl": "http://127.0.0.1:48080/api",
|
||||||
"token": "test1"
|
"token": "test1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,23 @@
|
|||||||
|
package cn.iocoder.dashboard.framework.lock4j.config;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ClassUtil;
|
||||||
|
import cn.iocoder.dashboard.framework.lock4j.core.DefaultLockFailureStrategy;
|
||||||
|
import cn.iocoder.dashboard.framework.lock4j.core.Lock4jRedisKeyConstants;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class Lock4jConfiguration {
|
||||||
|
|
||||||
|
static {
|
||||||
|
// 手动加载 Lock4jRedisKeyConstants 类,因为它不会被使用到
|
||||||
|
// 如果不加载,会导致 Redis 监控,看到它的 Redis Key 枚举
|
||||||
|
ClassUtil.loadClass(Lock4jRedisKeyConstants.class.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public DefaultLockFailureStrategy lockFailureStrategy() {
|
||||||
|
return new DefaultLockFailureStrategy();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
package cn.iocoder.dashboard.framework.lock4j.core;
|
||||||
|
|
||||||
|
import cn.iocoder.dashboard.framework.redis.core.RedisKeyDefine;
|
||||||
|
import org.redisson.api.RLock;
|
||||||
|
|
||||||
|
import static cn.iocoder.dashboard.framework.redis.core.RedisKeyDefine.KeyTypeEnum.HASH;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lock4j Redis Key 枚举类
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
public interface Lock4jRedisKeyConstants {
|
||||||
|
|
||||||
|
RedisKeyDefine LOCK4J = new RedisKeyDefine("分布式锁",
|
||||||
|
"lock4j:%s", // 参数来自 DefaultLockKeyBuilder 类
|
||||||
|
HASH, RLock.class, RedisKeyDefine.TimeoutTypeEnum.DYNAMIC); // Redisson 的 Lock 锁,使用 Hash 数据结构
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
### 请求 /get-permission-info 接口 => 成功
|
||||||
|
GET {{baseUrl}}/tool/test-demo/get?id=1
|
||||||
|
Authorization: Bearer {{token}}
|
||||||
Loading…
Reference in New Issue