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、相关代码
本站资源均来自互联网,仅供研究学习,禁止违法使用和商用,产生法律纠纷本站概不负责!如果侵犯了您的权益请与我们联系!
转载请注明出处: 免费源码网-免费的源码资源网站 » Redisson 实现分布式锁
发表评论 取消回复