使用 RedissonClient 进行加锁
RLock lock = redissonClient.getLock(LOCK_KEY);
try {
if (!lock.tryLock(Constants.TEN, TimeUnit.SECONDS)) {
throw new BusinessException("访问频繁请稍后再试");
}
doSomething();
} catch (Exception e) {
log.error("系统异常");
} finally {
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
lock.unlock();
}
}