1、相关配置

@Component
public class RedissonDistributedLock {

    @Autowired
    private RedissonClient redissonClient;

    public boolean tryLock(String lockKey, long expireTime, long waitTime) throws InterruptedException {
        RLock lock = redissonClient.getLock(lockKey);
        return lock.tryLock(waitTime, expireTime, TimeUnit.MILLISECONDS);
    }

    public void releaseLock(String lockKey) {
        RLock lock = redissonClient.getLock(lockKey);
        if (lock.isHeldByCurrentThread()) {
            lock.unlock();
        }
    }
}

2、相关代码

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部