Redis 后端
Spring Cloud 配置服务器支持Redis作为配置属性的后端。 你可以通过添加 Spring Data Redis 的依赖来启用这个功能。
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
</dependencies>
以下配置使用 Spring DataRedis模板访问Redis。我们可以使用spring.redis.*覆盖默认连接设置的属性。
spring:
profiles:
active: redis
redis:
host: redis
port: 16379
属性应该作为哈希中的字段存储。哈希的名称应为spring.application.name的性质或合取spring.application.name和春季档案活跃[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"
}
当没有指定配置文件时默认值将被使用。 |