private List<RedisNode> createSentinels(Sentinel sentinel) { List<RedisNode> nodes = new ArrayList<RedisNode>(); for (String node : StringUtils .commaDelimitedListToStringArray(sentinel.getNodes())) { try { String[] parts = StringUtils.split(node, ":"); Assert.state(parts.length == 2, "Must be defined as 'host:port'"); nodes.add(new RedisNode(parts[0], Integer.valueOf(parts[1]))); } catch (RuntimeException ex) { throw new IllegalStateException( "Invalid redis sentinel " + "property '" + node + "'", ex); } } return nodes; }
private List<RedisNode> createSentinels(Sentinel sentinel) { List<RedisNode> sentinels = new ArrayList<RedisNode>(); String nodes = sentinel.getNodes(); for (String node : StringUtils.commaDelimitedListToStringArray(nodes)) { try { String[] parts = StringUtils.split(node, ":"); Assert.state(parts.length == 2, "Must be defined as 'host:port'"); sentinels.add(new RedisNode(parts[0], Integer.valueOf(parts[1]))); } catch (RuntimeException ex) { throw new IllegalStateException( "Invalid redis sentinel " + "property '" + node + "'", ex); } } return sentinels; }
@Test public void shouldUseSentinelMasterName() { String name = "name"; RedisConnectionFactory factory = Mockito.mock(RedisConnectionFactory.class); RedisProperties props = new RedisProperties(); props.setSentinel(new Sentinel()); props.getSentinel().setMaster(name); RedisRelationshipDetector detector = new RedisRelationshipDetector(props, Arrays.asList(factory)); Set<Relationship> rels = new HashSet<>(); rels.add(Dependency.on(Component.of(name, ComponentType.REDIS))); Assertions.assertThat(detector.detect()).isEqualTo(rels); }
protected final RedisSentinelConfiguration getSentinelConfig() { if (this.sentinelConfiguration != null) { return this.sentinelConfiguration; } Sentinel sentinelProperties = this.properties.getSentinel(); if (sentinelProperties != null) { RedisSentinelConfiguration config = new RedisSentinelConfiguration(); config.master(sentinelProperties.getMaster()); config.setSentinels(createSentinels(sentinelProperties)); return config; } return null; }