Skip to content

Commit 2a326f1

Browse files
author
yangzhao
committed
根pom添加spring依赖
优化分布式锁模块部分代码 更新Readme
1 parent 3f234db commit 2a326f1

File tree

15 files changed

+168
-819
lines changed

15 files changed

+168
-819
lines changed

README.md

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,80 @@ Java后端常用工具类、缓存接口、消息队列接口、第三方支付
44

55
[TOC]
66

7-
## 1.缓存(common-cache):
7+
## 1.分布式锁、分布式方法锁(common-distributed-lock):
8+
9+
### DistributedLock类(依赖RedisTemplate接口实现)
10+
```
11+
12+
/**
13+
*
14+
* @param key 锁标识
15+
* @param attempt 重试次数
16+
* @return
17+
*/
18+
public boolean lock(String key,int attempt);
19+
20+
/**
21+
*
22+
* @param key 锁标识
23+
* @param time 过期时间
24+
* @param timeUnit 过期时间单位
25+
* @param attemptNum 重试次数
26+
* @return
27+
*/
28+
public boolean lock(String key, long time, TimeUnit timeUnit,int attemptNum)
29+
```
30+
31+
### @EnableMethodLock @MethodLock 使用
32+
#### @EnableMethodLock
33+
34+
**在Spring Boot 项目启动类添加该注解开启分布式方法锁**
35+
36+
**普通Spring项目配置component-scan自动扫描com.yz.common.distributed.lock.configuration包即可**
37+
38+
#### @MethodLock
39+
40+
```
41+
@Target({ElementType.METHOD})
42+
@Retention(RetentionPolicy.RUNTIME)
43+
@Documented
44+
public @interface MethodLock {
45+
/**
46+
* 锁标识
47+
* @return
48+
*/
49+
String key() default "";
50+
51+
/**
52+
* 时间
53+
* @return
54+
*/
55+
long time() default 10;
56+
57+
/**
58+
* 单位
59+
* @return
60+
*/
61+
TimeUnit timeUnit() default TimeUnit.SECONDS;
62+
63+
/**
64+
* 是否自动解锁
65+
* @return
66+
*/
67+
boolean autoUnLock() default true;
68+
69+
/**
70+
* 重试次数
71+
* @return
72+
*/
73+
int attemptNum() default 0;
74+
75+
}
76+
```
77+
78+
在需要使用分布式方法锁的method上使用该注解即可
879

9-
① 基于JVM方法区数据缓存
1080

11-
② 基于redis进行数据缓存
1281

1382
## 2.ES(common-elasticsearch)
1483

common-cache/src/main/java/com/yz/common/cache/CacheFactory.java

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)