redisson实现分布式锁
redisson分布式锁使用范例:
RLock lock = null; boolean res = false; try{ lock = RedisUtils.getRedissonClient().getLock(LOCK_NAME); //最大等待30s res = lock.tryLock(30, TimeUnit.SECONDS); if(res){ //执行分布式动作 log.info("加锁成功"); doSomething(); }else{ log.info("加锁失败"); } }catch (Exception e){ log.error("加锁异常", e); }finally{ if(res){ try{ lock.unlock(); }catch(Exception e){ log.error("解锁异常:", e); } } }
redisson官方文档
标签:redisson,log,实现,lock,加锁,res,分布式 From: https://www.cnblogs.com/zhangchiblog/p/16789425.html