Some time ago a large number of project uses a distributed lock redis recent sum up, start springboot integration redisson start.
Redisson is implemented on the basis of a Redis on Java in-memory data grid (In-Memory Data Grid). It not only provides a series of commonly used Java distributed object also provides a number of distributed services. Including ( BitSet
, Set
, Multimap
, SortedSet
, Map
, List
, Queue
, BlockingQueue
, Deque
, BlockingDeque
, Semaphore
, Lock
, AtomicLong
, CountDownLatch
, Publish / Subscribe
, Bloom filter
, Remote service
, Spring cache
, Executor service
, Live Object service
, Scheduler service
) Redisson provides the simplest and most convenient method of Redis.
First, add maven dependence
Added as follows pom.xml
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
<version>3.11.5</version>
</dependency>
Second, modify the configuration file yml
As for how to configure, you can see the starter pack below RedissonAutoConfiguration, RedissonProperties class will learn what parameters need to be set.
After understanding what you need to set parameters, add the following configuration in springboot configuration file:
spring:
repeat:
redisson:
config: "classpath:redisson.yml"
Then, in the resource directory New redisson.yml file, add the following configuration
clusterServersConfig: idleConnectionTimeout: 10000 connectTimeout: 10000 timeout: 3000 retryAttempts: 3 retryInterval: 1500 failedSlaveReconnectionInterval: 3000 failedSlaveCheckInterval: 60000 password: null subscriptionsPerConnection: 5 clientName: null loadBalancer: !<org.redisson.connection.balancer.RoundRobinLoadBalancer> {} subscriptionConnectionMinimumIdleSize: 1 subscriptionConnectionPoolSize: 50 slaveConnectionMinimumIdleSize: 24 slaveConnectionPoolSize 64 masterConnectionMinimumIdleSize: 24 masterConnectionPoolSize: 64 readMode: "SLAVE" subscriptionMode: "SLAVE" nodeAddresses: - "redis://192.168.35.142:7002" - "redis://192.168.35.142:7001" - "redis://192.168.35.142:7000" scanInterval: 1000 pingConnectionInterval: 0 keepAlive: false tcpNoDelay: false threads: 16 nettyThreads: 32 codec: !<org.redisson.codec.FstCodec> {} transportMode: "NIO"
Can also be written directly to all the configuration springboot configuration file (not recommended), as follows:
spring: repeat: redisson: config: clusterServersConfig: idleConnectionTimeout: 10000 connectTimeout: 10000 timeout: 3000 retryAttempts: 3 retryInterval: 1500 failedSlaveReconnectionInterval: 3000 failedSlaveCheckInterval: 60000 password: null subscriptionsPerConnection: 5 clientName: null loadBalancer: !<org.redisson.connection.balancer.RoundRobinLoadBalancer> {} subscriptionConnectionMinimumIdleSize: 1 subscriptionConnectionPoolSize: 50 slaveConnectionMinimumIdleSize: 24 slaveConnectionPoolSize 64 masterConnectionMinimumIdleSize: 24 masterConnectionPoolSize: 64 readMode: "SLAVE" subscriptionMode: "SLAVE" nodeAddresses: - "redis://192.168.35.142:7002" - "redis://192.168.35.142:7001" - "redis://192.168.35.142:7000" scanInterval: 1000 pingConnectionInterval: 0 keepAlive: false tcpNoDelay: false threads: 16 nettyThreads: 32 codec: !<org.redisson.codec.FstCodec> {} transportMode: "NIO"
Third, start running
After starting the project, if the following log, and not being given, it indicates the success of integration
After the successful integration, by RedisTemplate possible additions and deletions to the data and other operations, by RedissonClient acquires various locks; one explains how to use the various distributed lock RedissonClient provided.