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 。 |