lock-spring-boot-starter 1.0.0 正式发布,轻松实现分布式锁

栏目: 软件资讯 · 发布时间: 7年前

内容简介:lock-spring-boot-starter是一个基于Redisson实现的Spring Boot Starter项目,将分布式锁的加锁解锁基于aop进行封装,以@Lock注解的方式对外提供服务,使用过程中只需要通过简单的注解@Lock即可实现分布式锁,配置...

lock-spring-boot-starter是一个基于Redisson实现的Spring Boot Starter项目,将分布式锁的加锁解锁基于aop进行封装,以@Lock注解的方式对外提供服务,使用过程中只需要通过简单的注解@Lock即可实现分布式锁,配置容易,上手简单。

lock-spring-boot-starter不仅支持单机 Redis 的方式,同时还支持集群、哨兵、主从等常用Redis集群方式,使原本复杂的配置变得轻松容易。

使用指南:

1. 创建Spring Boot项目

2. 引入maven依赖

<dependency>
     <groupId>org.august.spring.boot</groupId>
     <artifactId>lock-spring-boot-starter</artifactId>
     <version>1.0.0</version>
 </dependency>

3. 在Spring Boot的项目配置文件application.yml中添加相应的配置,如:

lock-config: 
     pattern: single #redis模式配置,single:单机模式,cluster:集群模式,replicated:云托管模式,sentinel:哨兵模式,master_slave:主从模式
     # 不同的redis模式对应不同的配置方式,single-server对应的就是单机模式,具体参数意义可参考redisson的配置参数说明
     single-server: 
         address: 127.0.0.1
         port: 6379
         password: 123456

4. 在需要使用分布式锁的方法上面使用@Lock注解,锁的关键字使用@Key,如:

@Lock
 public void hello(String ces, @Key String orderNo) {
 	System.out.println("hello");
 }

如果需要配置不同类型的锁,可以直接变更@Lock的参数值即可,默认是可重入锁

@Lock提供四个参数可以配置: lockType:锁类型 leaseTime:加锁时间 waitTime:最长等待时间 timeUnit:锁时长单位

DEMO地址如下:https://gitee.com/yizhigui/lock-spring-boot-starter-demo


以上所述就是小编给大家介绍的《lock-spring-boot-starter 1.0.0 正式发布,轻松实现分布式锁》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

PHP for the World Wide Web, Second Edition (Visual QuickStart Gu

PHP for the World Wide Web, Second Edition (Visual QuickStart Gu

Larry Ullman / Peachpit Press / 2004-02-02 / USD 29.99

So you know HTML, even JavaScript, but the idea of learning an actual programming language like PHP terrifies you? Well, stop quaking and get going with this easy task-based guide! Aimed at beginning ......一起来看看 《PHP for the World Wide Web, Second Edition (Visual QuickStart Gu》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

html转js在线工具
html转js在线工具

html转js在线工具