This article introduces the SpringBoot integration Redisson combat (through redisson-spring-boot-starter), Mainly including SpringBoot integration Redisson combat (through redisson-spring-boot-starter) use examples, application skills, basic knowledge summary and need to pay attention to, has a certain reference value, need friends can refer to.

Redssion’s execution object for executing methods in distributed locks. This type of processing is required when the method allows only one node to run at a time.

<artifactId>adicon-lis-starter-data-redis</artifactId> <name>adicon-lis-starter-data-redis</name> <description> <description> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>org.redisson</groupId> <artifactId>redisson-spring-boot-starter</artifactId> </dependency> <dependency> <groupId>com.adicon</groupId> <artifactId>adicon-lis-starter-commons</artifactId> </dependency> </dependencies>Copy the code
/** * @param lockKey lock * @param waitTime lock waitTime * @param leaseTime lock life time, automatically released when the expiration * @return failed to lock null */ @Override public RLock tryLock(String lockKey, long waitTime, long leaseTime) { RLock lock = redisson.getLock(lockKey); try { if (lock.tryLock(waitTime, leaseTime, TimeUnit.MILLISECONDS)) { return lock; } } catch (InterruptedException ignore) { if (log.isWarnEnabled()) { log.warn("Redisson tryLock exception", ignore); } } return null; }Copy the code