Spring Cloud Config Server 支持将 Redis 作为配置属性的后端。 您可以通过向 Spring Data Redis 添加依赖项来启用此功能。Spring中文文档

pom.xml
<dependencies>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-data-redis</artifactId>
	</dependency>
</dependencies>

以下配置使用 Spring Data 访问 Redis。我们可以使用属性来覆盖默认连接设置。RedisTemplatespring.redis.*Spring中文文档

spring:
  profiles:
    active: redis
  redis:
    host: redis
    port: 16379

这些属性应作为哈希中的字段存储。哈希的名称应与 和 的属性或连词相同。spring.application.namespring.application.namespring.profiles.active[n]Spring中文文档

HMSET sample-app server.port "8100" sample.topic.name "test" test.property1 "property1"

运行上面可见的命令后,哈希应包含以下键和值:Spring中文文档

HGETALL sample-app
{
  "server.port": "8100",
  "sample.topic.name": "test",
  "test.property1": "property1"
}
当未指定配置文件时,将使用配置文件。default
当未指定配置文件时,将使用配置文件。default