Skip to content

Commit 3779072

Browse files
authored
feat: Redis sentinel enabled field (#2546)
* Add sentinel enabled field Signed-off-by: Carson Cook <carson.cook@ibm.com> * Default sentinel to false Signed-off-by: Carson Cook <carson.cook@ibm.com> * Fix sentinel enabled test Signed-off-by: Carson Cook <carson.cook@ibm.com> * Add log when connect to redis Signed-off-by: Carson Cook <carson.cook@ibm.com> Signed-off-by: Carson Cook <carson.cook@ibm.com>
1 parent 4ffa3d1 commit 3779072

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

caching-service/src/main/java/org/zowe/apiml/caching/service/redis/RedisOperator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public RedisOperator(RedisClient redisClient, RedisURI redisUri, ApimlLogger api
5555
this.redisClient = redisClient;
5656
redisConnection = MasterReplica.connect(this.redisClient, StringCodec.UTF8, redisUri);
5757
redis = redisConnection.async();
58+
log.info("Connected to Redis {}", redisUri);
5859
} catch (Exception e) {
5960
apimlLog.log("org.zowe.apiml.cache.errorInitializingStorage", "redis", e.getCause().getMessage(), e);
6061
System.exit(1);

caching-service/src/main/java/org/zowe/apiml/caching/service/redis/config/RedisConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void init() {
5656
}
5757

5858
public boolean usesSentinel() {
59-
return sentinel != null;
59+
return sentinel != null && sentinel.isEnabled();
6060
}
6161

6262
public boolean usesSsl() {
@@ -65,6 +65,7 @@ public boolean usesSsl() {
6565

6666
@Data
6767
public static class Sentinel {
68+
private boolean enabled = false;
6869
private String masterInstance;
6970
private List<SentinelNode> nodes;
7071

caching-service/src/main/resources/application.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ caching:
44
redis:
55
timeout: 60
66
masterNodeUri: default:heslo@localhost:6379
7+
sentinel:
8+
enabled: false
9+
masterInstance: redismaster
10+
nodes:
11+
- sentinelpassword@localhost:26379
12+
- sentinelpassword@localhost:26380
13+
- sentinelpassword@localhost:26381
714
ssl:
815
enabled: true
916
keyStore: ${server.ssl.keyStore}

caching-service/src/test/java/org/zowe/apiml/caching/service/redis/config/RedisConfigTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,17 @@ void givenNullSentinel_thenReturnFalse() {
4040
}
4141

4242
@Test
43-
void givenValidSentinel_thenReturnTrue() {
43+
void givenSentinelNotEnabled_thenReturnFalse() {
4444
underTest.setSentinel(new RedisConfig.Sentinel());
45+
assertFalse(underTest.usesSentinel());
46+
}
47+
48+
@Test
49+
void givenValidSentinel_thenReturnTrue() {
50+
RedisConfig.Sentinel sentinel = new RedisConfig.Sentinel();
51+
sentinel.setEnabled(true);
52+
53+
underTest.setSentinel(sentinel);
4554
assertTrue(underTest.usesSentinel());
4655
}
4756
}

0 commit comments

Comments
 (0)