From 2b4b1da636d65ef5ca7efe04a3c5b050fa6d7f41 Mon Sep 17 00:00:00 2001 From: Ben Hale Date: Mon, 11 May 2020 16:06:18 -0700 Subject: [PATCH] Redis Binding This change expands the Redis bindings to handle more properties. [resolves #7] Signed-off-by: Ben Hale --- README.md | 14 +++++++++++--- .../boot/RedisBindingsPropertiesProcessor.java | 8 ++++++++ .../RedisBindingsPropertiesProcessorTest.java | 18 +++++++++++++++++- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 65765c6..9b3f70b 100644 --- a/README.md +++ b/README.md @@ -112,9 +112,17 @@ Disable Property: `org.springframework.cloud.bindings.boot.redis.enable` | Property | Value | -------- | ----- -| `spring.datasource.host` | `{secret.host}` -| `spring.datasource.password` | `{secret.password}` -| `spring.datasource.port` | `{secret.port}` +| `spring.redis.client-name` | `{secret.client-name}` +| `spring.redis.cluster.max-redirects` | `{secret.cluster.max-redirects}` +| `spring.redis.cluster.nodes` | `{secret.cluster-nodes}` +| `spring.redis.database` | `{secret.database}` +| `spring.redis.host` | `{secret.host}` +| `spring.redis.password` | `{secret.password}` +| `spring.redis.port` | `{secret.port}` +| `spring.redis.sentinel.master` | `{secret.sentinel.master}` +| `spring.redis.sentinel.nodes` | `{secret.sentinel.nodes}` +| `spring.redis.ssl` | `{secret.ssl}` +| `spring.redis.url` | `{secret.url}` ### Oracle RDBMS Kind: `SQLServer` diff --git a/src/main/java/org/springframework/cloud/bindings/boot/RedisBindingsPropertiesProcessor.java b/src/main/java/org/springframework/cloud/bindings/boot/RedisBindingsPropertiesProcessor.java index faa7384..7a30317 100644 --- a/src/main/java/org/springframework/cloud/bindings/boot/RedisBindingsPropertiesProcessor.java +++ b/src/main/java/org/springframework/cloud/bindings/boot/RedisBindingsPropertiesProcessor.java @@ -43,9 +43,17 @@ public final class RedisBindingsPropertiesProcessor implements BindingsPropertie bindings.filterBindings(KIND).forEach(binding -> { MapMapper map = new MapMapper(binding.getSecret(), properties); + map.from("client-name").to("spring.redis.client-name"); + map.from("cluster.max-redirects").to("spring.redis.cluster.max-redirects"); + map.from("cluster.nodes").to("spring.redis.cluster.nodes"); + map.from("database").to("spring.redis.database"); map.from("host").to("spring.redis.host"); map.from("password").to("spring.redis.password"); map.from("port").to("spring.redis.port"); + map.from("sentinel.master").to("spring.redis.sentinel.master"); + map.from("sentinel.nodes").to("spring.redis.sentinel.nodes"); + map.from("ssl").to("spring.redis.ssl"); + map.from("url").to("spring.redis.url"); }); } diff --git a/src/test/java/org/springframework/cloud/bindings/boot/RedisBindingsPropertiesProcessorTest.java b/src/test/java/org/springframework/cloud/bindings/boot/RedisBindingsPropertiesProcessorTest.java index 78b9486..db0258d 100644 --- a/src/test/java/org/springframework/cloud/bindings/boot/RedisBindingsPropertiesProcessorTest.java +++ b/src/test/java/org/springframework/cloud/bindings/boot/RedisBindingsPropertiesProcessorTest.java @@ -37,9 +37,17 @@ final class RedisBindingsPropertiesProcessorTest { new Binding("test-name", Paths.get("test-path"), Collections.singletonMap("kind", KIND), new FluentMap() + .withEntry("client-name", "test-client-name") + .withEntry("cluster.max-redirects", "test-cluster-max-redirects") + .withEntry("cluster.nodes", "test-cluster-nodes") + .withEntry("database", "test-database") .withEntry("host", "test-host") .withEntry("password", "test-password") .withEntry("port", "test-port") + .withEntry("sentinel.master", "test-sentinel-master") + .withEntry("sentinel.nodes", "test-sentinel-nodes") + .withEntry("ssl", "test-ssl") + .withEntry("url", "test-url") ) ); @@ -52,9 +60,17 @@ final class RedisBindingsPropertiesProcessorTest { void test() { new RedisBindingsPropertiesProcessor().process(environment, bindings, properties); assertThat(properties) + .containsEntry("spring.redis.client-name", "test-client-name") + .containsEntry("spring.redis.cluster.max-redirects", "test-cluster-max-redirects") + .containsEntry("spring.redis.cluster.nodes", "test-cluster-nodes") + .containsEntry("spring.redis.database", "test-database") .containsEntry("spring.redis.host", "test-host") .containsEntry("spring.redis.password", "test-password") - .containsEntry("spring.redis.port", "test-port"); + .containsEntry("spring.redis.port", "test-port") + .containsEntry("spring.redis.sentinel.master", "test-sentinel-master") + .containsEntry("spring.redis.sentinel.nodes", "test-sentinel-nodes") + .containsEntry("spring.redis.ssl", "test-ssl") + .containsEntry("spring.redis.url", "test-url"); } @Test