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.namespring.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