代码拉取完成,页面将自动刷新
点击链接加入群聊【Pear Stack】讨论交流:293972109
国内镜像: 【Gitee】:lock-spring-boot-starter
简单描述
lock-spring-boot-starter
一款分布式锁, 支持使用 Redis
和 ZooKeeper
, 开箱即用, 快捷方便
特点
spring-boot-starter
组件开箱即用, 快捷方便自定义key
, 以及spring el
表达式框架名称 | 版本号 | 官网 |
---|---|---|
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 |
Redisson 模式
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}'
Redis Template模式
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}'
ZooKeeper 模式
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 "购买成功!";
}
}
}
暂无~(欢迎留言)
暂无~ (欢迎交换链接)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。