赞
踩
1.springBoot集成redisson(单机,集群,哨兵)
redisson版本使用3.8.2
- <dependency>
- <groupId>org.redisson</groupId>
- <artifactId>redisson</artifactId>
- <version>3.8.2</version>
- </dependency>
2.配置文件
- application.properties
-
- spring.redis.database=0
- spring.redis.password=
- spring.redis.timeout=3000
- #sentinel/cluster/single
- spring.redis.mode=single
- #连接池配置
- spring.redis.pool.max-idle=16
- spring.redis.pool.min-idle=8
- spring.redis.pool.max-active=8
- spring.redis.pool.max-wait=3000
- spring.redis.pool.conn-timeout=3000
- spring.redis.pool.so-timeout=3000
- spring.redis.pool.size=10
- #单机配置
- spring.redis.single.address=192.168.60.23:6379
- #集群配置
- spring.redis.cluster.scan-interval=1000
- spring.redis.cluster.nodes=
- spring.redis.cluster.read-mode=SLAVE
- spring.redis.cluster.retry-attempts=3
- spring.redis.cluster.failed-attempts=3
- spring.redis.cluster.slave-connection-pool-size=64
- spring.redis.cluster.master-connection-pool-size=64
- spring.redis.cluster.retry-interval=1500
- #哨兵配置
- spring.redis.sentinel.master=business-master
- spring.redis.sentinel.nodes=
- spring.redis.sentinel.master-onlyWrite=true
- spring.redis.sentinel.fail-max=3

3.配置文件读取
RedisProperties
- import lombok.Data;
- import lombok.ToString;
- import org.springframework.boot.context.properties.ConfigurationProperties;
-
- /**
- * @author Abbot
- * @des
- * @date 2018/10/18 10:42
- **/
-
- @ConfigurationProperties(prefix = "spring.redis", ignoreUnknownFields = false)
- @Data
- @ToString
- public class RedisProperties {
-
- private int database;
-
- /**
- * 等待节点回复命令的时间。该时间从命令发送成功时开始计时
- */
- private int timeout;
-
- private String password;
-
- private String mode;
-
- /**
- * 池配置
- */
- private RedisPoolProperties pool;
-
- /**
- * 单机信息配置
- */
- private RedisSingleProperties single;
-
- /**
- * 集群 信息配置
- */
- private RedisClusterProperties cluster;
-
- /**
- * 哨兵配置
-

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。