Redis 后端
Spring Cloud Config Server 支持将 Redis 作为配置属性的后端存储。你可以通过添加 Spring Data Redis 依赖来启用此功能。
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
</dependencies>
以下配置使用 Spring Data 的 RedisTemplate
来访问 Redis。我们可以使用 spring.redis.*
属性来覆盖默认的连接设置。
spring:
profiles:
active: redis
redis:
host: redis
port: 16379
属性应存储在哈希表的字段中。哈希表的名称应与 spring.application.name
属性相同,或者是 spring.application.name
和 spring.profiles.active[n]
的组合。
HMSET sample-app server.port "8100" sample.topic.name "test" test.property1 "property1"
运行上述命令后,哈希应包含以下键值对:
HGETALL sample-app
{
"server.port": "8100",
"sample.topic.name": "test",
"test.property1": "property1"
}
备注
当未指定配置文件时,将使用 default
。