Skip to content
redis-lock
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
LICENSE
README.md
pom.xml

README.md

redis-lock

基于redis的分布式锁实现

如何使用

引入依赖

<dependency>
    <groupId>com.luo.redis.lock</groupId>
    <artifactId>redis-lock</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</dependency>

redis配置

spring:
  redis:
    host: 192.168.31.247
    port: 6379
    password: 123456
#    sentinel:
#      master: my-master
#      nodes: 192.168.31.247:6379,192.168.31.247:6379

代码示例

@SpringBootApplication
public class BootApplication {
    public static void main(String[] args) {
        SpringApplication.run(BootApplication.class, args);

        // 锁获取
        RedisLock lock = new RedisLock(UUID.randomUUID().toString(), false);

        Assert.isTrue(lock.tryLock());
        Assert.isTrue(!lock.tryLock());
        Assert.isTrue(lock.unlock());
    }
}
You can’t perform that action at this time.