Redis Backend
Spring Cloud Config Server 支持 Redis 作为配置属性的后端。您可以通过将依赖项添加到 Spring Data Redis来启用此功能。
Spring Cloud Config Server supports Redis as a backend for configuration properties. You can enable this feature by adding a dependency to 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.*
属性来覆盖默认连接设置。
The following configuration uses Spring Data RedisTemplate
to access a Redis. We can use spring.redis.*
properties to override default connection settings.
spring:
profiles:
active: redis
redis:
host: redis
port: 16379
属性应该存储为哈希中的字段。哈希的名称应与 `spring.application.name`属性或 `spring.application.name`与 `spring.profiles.active[n]`的结合相同。
The properties should be stored as fields in a hash. The name of hash should be the same as spring.application.name
property or conjunction of spring.application.name
and spring.profiles.active[n]
.
HMSET sample-app server.port "8100" sample.topic.name "test" test.property1 "property1"
运行上述命令后,散列应包含以下值:
After running the command visible above a hash should contain the following keys with values:
HGETALL sample-app { "server.port": "8100", "sample.topic.name": "test", "test.property1": "property1" }
如果没有指定配置文件,将使用 |
When no profile is specified |