A distributed lock that supports the use of Redis and Zookeeper, out of the box, fast and easy to use
点击链接加入群聊【Pear Stack】讨论交流:293972109
国内镜像: 【Gitee】:lock-spring-boot-starter
-
简单描述
lock-spring-boot-starter
一款分布式锁, 支持使用Redis
和ZooKeeper
, 开箱即用, 快捷方便 -
特点
spring-boot-starter
组件开箱即用, 快捷方便- 支持
自定义key
, 以及spring el
表达式 - 将生成key的方法和上锁失败的异常方法作为接口, 可以自定义实现层, 更加自由
-
框架名称 版本号 官网 spring-boot-starter-aop 2.6.2 https://spring.io/projects/spring-boot spring-boot-starter-validation 2.6.2 https://spring.io/projects/spring-boot spring-integration-redis 2.6.2 https://spring.io/projects/spring-boot spring-boot-starter-data-redis 2.6.2 https://spring.io/projects/spring-boot redisson-spring-boot-starter 3.16.7 http://redisson.org spring-integration-zookeeper 2.6.2 https://spring.io/projects/spring-boot spring-boot-configuration-processor 2.6.2 https://spring.io/projects/spring-boot hutool-core 5.7.17 https://github.com/dromara/hutool lombok 1.18.22 https://projectlombok.org
-
-
Apache Maven
<dependency> <groupId>io.github.pearstack</groupId> <artifactId>lock-redisson-spring-boot-starter</artifactId> <version>${last.version}</version> </dependency>
-
Gradle Groovy DSL
implementation 'io.github.pearstack:lock-redisson-spring-boot-starter:${last.version}'
-
-
-
Apache Maven
<dependency> <groupId>io.github.pearstack</groupId> <artifactId>lock-redis-template-spring-boot-starter</artifactId> <version>${last.version}</version> </dependency>
-
Gradle Groovy DSL
implementation 'io.github.pearstack:lock-redis-template-spring-boot-starter:${last.version}'
-
-
-
Apache Maven
<dependency> <groupId>io.github.pearstack</groupId> <artifactId>lock-zookeeper-spring-boot-starter</artifactId> <version>${last.version}</version> </dependency>
-
Gradle Groovy DSL
implementation 'io.github.pearstack:lock-zookeeper-spring-boot-starter:${last.version}'
-
PS: 更多细节请看帮助文档
package com.lihao.lock.controller;
import io.github.pearstack.lock.annotation.Locked;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
public class TestController {
public static Integer apple = 200;
public static Integer pear = 200;
/**
* 带分布式锁, 不会出现超卖
*
* @param appleId
* @return
*/
@Locked(keys = "#appleId")
@GetMapping("/get/apple")
public String getApple(Long appleId) {
if (apple <= 0) {
return "对不起, 已经没货了!";
} else {
apple = apple - 1;
log.info("购买成功, 现在apple数量为:{}", apple);
return "购买成功!";
}
}
/**
* 不带分布式锁, 会出现超卖
*
* @param pearId
*/
@GetMapping("/get/pear")
public String getPear(Long pearId) {
if (pear <= 0) {
return "对不起, 已经没货了!";
} else {
pear = pear - 1;
log.info("购买成功, 现在pear数量为:{}", pear);
return "购买成功!";
}
}
}
- 茶猫云赞助服务器 : https://www.cmy.cn
暂无~(欢迎留言)
暂无~ (欢迎交换链接)