Redis 组件

onee-framework-starter-redis

在 spring boot 项目中快速集成 redis 服务组件

模式

目前支持 单点哨兵集群 3种模式

安装

仓库地址:onee-framework-starter-redis

Maven

pom.xml 中添加以下依赖:

<dependency>
    <groupId>io.onee</groupId>
    <artifactId>onee-framework-starter-redis</artifactId>
    <version>1.2.1</version>
</dependency>

参数配置

application.properties 文件中可配置以下参数:

参数名
必须
默认值
说明

of.redis.single.host

localhost

单机模式服务 host,配置则使用单机模式连接 redis 服务(默认)

of.redis.single.port

6379

单机服务端口

of.redis.single.database

0

单机模式数据库编号

of.redis.sentinel.master

-

哨兵模式服务主服务节点地址,配置则使用哨兵模式连接 redis 服务

of.redis.sentinel.nodes

-

哨兵模式从服务节点地址列表,多个以","隔开

of.redis.sentinel.database

0

哨兵模式数据库编号

of.redis.cluster.nodes

-

集群模式服务节点地址列表,多个以","隔开

of.redis.cluster.max-redirects

-

集群模式最大转发数量

of.redis.idleConnectionTimeout

10000

空闲连接断开时间

of.redis.connectTimeout

10000

连接超时时间

of.redis.timeout

30000

响应超时时间

of.redis.password

-

redis 密码

of.redis.connectionPoolSize

64

连接池最大连接数

of.redis.connectionMinimumIdleSize

24

连接池最小空闲连接数

of.redis.retryAttempts

3

失败重连尝试次数

of.redis.retryInterval

1500

失败重连间隔

of.redis.codecClassName

org.redisson.client.codec.StringCodec

编解码类

配置示例

  • 单点

of.redis.single.host=127.0.0.1
of.redis.single.port=6379
of.redis.password=123456
  • 哨兵

of.redis.sentinel.master=127.0.0.1:6379
of.redis.sentinel.nodes=127.0.0.1:6380,127.0.0.1:6381
of.redis.password=123456
  • 集群

of.redis.cluster.nodes=127.0.0.1:6379,127.0.0.1:6380,127.0.0.1:6381
of.redis.password=123456

使用方式

代码示例:StorageSample

@Autowired
private RedisClient redisClient; // redis 工具客户端

Last updated