Redis 后端
Spring Cloud Config Server 支持使用 Redis 作为配置属性的后端。 您可以通过添加对 Spring Data Redis 的依赖来启用此功能。
pom.xml
<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" }
当没有指定 profile 时,将使用 default 。 |