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"
}
未指定配置檔案時,將使用 default
© . This site is unofficial and not affiliated with VMware.