- 引入 redission 依赖
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
<version>3.16.7</version>
</dependency>
- 配置yml
一种是使用 spring-boot-starter-data-redis 的配置(推荐使用)
spring:
redis:
host: 122.112.166.49
port: 7000
password: ENC(GY838xUcjjaArWm63U0SRVKAhDF9fqFeFrwemHFraa4ZLHZ3sA2u+mH9q0NQIQ0a)
database: 12
第二种是使用
spring:
redis:
redisson:
file: classpath:redisson.yaml
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://127.0.0.1:7004"
- "redis://127.0.0.1:7001"
- "redis://127.0.0.1:7000"
scanInterval: 1000
pingConnectionInterval: 0
keepAlive: false
tcpNoDelay: false
threads: 16
nettyThreads: 32
codec: !<org.redisson.codec.MarshallingCodec> {}
transportMode: "NIO"
第三种使用 自己写相关的配置类型 参考百度
- 使用方式
RLock lock = redissonClient.getLock("NUM_LOCK");
try {
lock.lock();
initGroupTaskNumByGroupId(groupId);
}finally {
lock.unlock();
}
参考:
https://github.com/redisson/redisson
https://github.com/redisson/redisson/tree/master/redisson-spring-boot-starter
- 本文链接: http://maltose.top/archives/springboot集成redission
- 版权声明: 本博客所有文章除特别声明外,均采用CC BY-NC-SA 3.0 许可协议。转载请注明出处!