org.springframework.data.redis.connection.RedisServer Java Examples

The following examples show how to use org.springframework.data.redis.connection.RedisServer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpringRedis.java    From xmanager with Apache License 2.0 6 votes vote down vote up
/**
 * redis 得到所有的master and slave 信息
 */
@Test
public void testGetAllMasterAndSlave() {

    RedisSentinelConnection conn = stringRedisTemplate.getConnectionFactory().getSentinelConnection();

    for (RedisServer master : conn.masters()) {
        System.out.println("master => " + master);// 打印master信息
        Collection<RedisServer> slaves = conn.slaves(master);
        // 打印该master下的所有slave信息
        for (RedisServer slave : slaves) {
            System.out.println("slaves of " + master + " => " + slave);
        }
        System.out.println("--------------");
    }
}
 
Example #2
Source File: RedissonSentinelConnection.java    From redisson with Apache License 2.0 5 votes vote down vote up
private static List<RedisServer> toRedisServersList(List<Map<String, String>> source) {
    List<RedisServer> servers = new ArrayList<RedisServer>(source.size());
    for (Map<String, String> info : source) {
        servers.add(RedisServer.newServerFrom(Converters.toProperties(info)));
    }
    return servers;
}
 
Example #3
Source File: RedissonSentinelConnectionTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testMonitor() {
    Collection<RedisServer> masters = connection.masters();
    RedisServer master = masters.iterator().next();
    master.setName(master.getName() + ":");
    connection.monitor(master);
}
 
Example #4
Source File: RedissonSentinelConnectionTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailover() throws InterruptedException {
    Collection<RedisServer> masters = connection.masters();
    connection.failover(masters.iterator().next());
    
    Thread.sleep(10000);
    
    RedisServer newMaster = connection.masters().iterator().next();
    assertThat(masters.iterator().next().getPort()).isNotEqualTo(newMaster.getPort());
}
 
Example #5
Source File: RedissonSentinelConnection.java    From redisson with Apache License 2.0 5 votes vote down vote up
private static List<RedisServer> toRedisServersList(List<Map<String, String>> source) {
    List<RedisServer> servers = new ArrayList<RedisServer>(source.size());
    for (Map<String, String> info : source) {
        servers.add(RedisServer.newServerFrom(Converters.toProperties(info)));
    }
    return servers;
}
 
Example #6
Source File: RedissonSentinelConnectionTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testMonitor() {
    Collection<RedisServer> masters = connection.masters();
    RedisServer master = masters.iterator().next();
    master.setName(master.getName() + ":");
    connection.monitor(master);
}
 
Example #7
Source File: RedissonSentinelConnectionTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailover() throws InterruptedException {
    Collection<RedisServer> masters = connection.masters();
    connection.failover(masters.iterator().next());
    
    Thread.sleep(10000);
    
    RedisServer newMaster = connection.masters().iterator().next();
    assertThat(masters.iterator().next().getPort()).isNotEqualTo(newMaster.getPort());
}
 
Example #8
Source File: RedissonSentinelConnectionTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testMonitor() {
    Collection<RedisServer> masters = connection.masters();
    RedisServer master = masters.iterator().next();
    master.setName(master.getName() + ":");
    connection.monitor(master);
}
 
Example #9
Source File: RedissonSentinelConnectionTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailover() throws InterruptedException {
    Collection<RedisServer> masters = connection.masters();
    connection.failover(masters.iterator().next());
    
    Thread.sleep(10000);
    
    RedisServer newMaster = connection.masters().iterator().next();
    assertThat(masters.iterator().next().getPort()).isNotEqualTo(newMaster.getPort());
}
 
Example #10
Source File: RedissonSentinelConnection.java    From redisson with Apache License 2.0 5 votes vote down vote up
private static List<RedisServer> toRedisServersList(List<Map<String, String>> source) {
    List<RedisServer> servers = new ArrayList<RedisServer>(source.size());
    for (Map<String, String> info : source) {
        servers.add(RedisServer.newServerFrom(Converters.toProperties(info)));
    }
    return servers;
}
 
Example #11
Source File: RedissonSentinelConnectionTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testMonitor() {
    Collection<RedisServer> masters = connection.masters();
    RedisServer master = masters.iterator().next();
    master.setName(master.getName() + ":");
    connection.monitor(master);
}
 
Example #12
Source File: RedissonSentinelConnectionTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailover() throws InterruptedException {
    Collection<RedisServer> masters = connection.masters();
    connection.failover(masters.iterator().next());
    
    Thread.sleep(10000);
    
    RedisServer newMaster = connection.masters().iterator().next();
    assertThat(masters.iterator().next().getPort()).isNotEqualTo(newMaster.getPort());
}
 
Example #13
Source File: RedissonSentinelConnection.java    From redisson with Apache License 2.0 5 votes vote down vote up
private static List<RedisServer> toRedisServersList(List<Map<String, String>> source) {
    List<RedisServer> servers = new ArrayList<RedisServer>(source.size());
    for (Map<String, String> info : source) {
        servers.add(RedisServer.newServerFrom(Converters.toProperties(info)));
    }
    return servers;
}
 
Example #14
Source File: RedissonSentinelConnectionTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testMonitor() {
    Collection<RedisServer> masters = connection.masters();
    RedisServer master = masters.iterator().next();
    master.setName(master.getName() + ":");
    connection.monitor(master);
}
 
Example #15
Source File: RedissonSentinelConnectionTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailover() throws InterruptedException {
    Collection<RedisServer> masters = connection.masters();
    connection.failover(masters.iterator().next());
    
    Thread.sleep(10000);
    
    RedisServer newMaster = connection.masters().iterator().next();
    assertThat(masters.iterator().next().getPort()).isNotEqualTo(newMaster.getPort());
}
 
Example #16
Source File: RedissonSentinelConnection.java    From redisson with Apache License 2.0 5 votes vote down vote up
private static List<RedisServer> toRedisServersList(List<Map<String, String>> source) {
    List<RedisServer> servers = new ArrayList<RedisServer>(source.size());
    for (Map<String, String> info : source) {
        servers.add(RedisServer.newServerFrom(Converters.toProperties(info)));
    }
    return servers;
}
 
Example #17
Source File: RedissonSentinelConnectionTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testMonitor() {
    Collection<RedisServer> masters = connection.masters();
    RedisServer master = masters.iterator().next();
    master.setName(master.getName() + ":");
    connection.monitor(master);
}
 
Example #18
Source File: RedissonSentinelConnectionTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailover() throws InterruptedException {
    Collection<RedisServer> masters = connection.masters();
    connection.failover(masters.iterator().next());
    
    Thread.sleep(10000);
    
    RedisServer newMaster = connection.masters().iterator().next();
    assertThat(masters.iterator().next().getPort()).isNotEqualTo(newMaster.getPort());
}
 
Example #19
Source File: RedissonSentinelConnection.java    From redisson with Apache License 2.0 5 votes vote down vote up
private static List<RedisServer> toRedisServersList(List<Map<String, String>> source) {
    List<RedisServer> servers = new ArrayList<RedisServer>(source.size());
    for (Map<String, String> info : source) {
        servers.add(RedisServer.newServerFrom(Converters.toProperties(info)));
    }
    return servers;
}
 
Example #20
Source File: RedissonSentinelConnection.java    From redisson with Apache License 2.0 5 votes vote down vote up
private static List<RedisServer> toRedisServersList(List<Map<String, String>> source) {
    List<RedisServer> servers = new ArrayList<RedisServer>(source.size());
    for (Map<String, String> info : source) {
        servers.add(RedisServer.newServerFrom(Converters.toProperties(info)));
    }
    return servers;
}
 
Example #21
Source File: RedissonSentinelConnectionTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailover() throws InterruptedException {
    Collection<RedisServer> masters = connection.masters();
    connection.failover(masters.iterator().next());
    
    Thread.sleep(10000);
    
    RedisServer newMaster = connection.masters().iterator().next();
    assertThat(masters.iterator().next().getPort()).isNotEqualTo(newMaster.getPort());
}
 
Example #22
Source File: RedissonSentinelConnectionTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testMonitor() {
    Collection<RedisServer> masters = connection.masters();
    RedisServer master = masters.iterator().next();
    master.setName(master.getName() + ":");
    connection.monitor(master);
}
 
Example #23
Source File: RedissonSentinelConnectionTest.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Test
public void testRemove() {
    Collection<RedisServer> masters = connection.masters();
    connection.remove(masters.iterator().next());
}
 
Example #24
Source File: RedissonSentinelConnectionTest.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Test
public void testMasters() {
    Collection<RedisServer> masters = connection.masters();
    assertThat(masters).hasSize(1);
}
 
Example #25
Source File: RedissonSentinelConnection.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public void monitor(RedisServer master) {
    connection.sync(RedisCommands.SENTINEL_MONITOR, master.getName(), master.getHost(), 
                                master.getPort().intValue(), master.getQuorum().intValue());
}
 
Example #26
Source File: TracingRedisSentinelConnection.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public void monitor(RedisServer master) {
  Span span = helper.buildSpan("monitor");
  helper.decorate(span, () -> redisSentinelConnection.monitor(master));
}
 
Example #27
Source File: RedissonSentinelConnection.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public void monitor(RedisServer master) {
    connection.sync(RedisCommands.SENTINEL_MONITOR, master.getName(), master.getHost(), 
                                master.getPort().intValue(), master.getQuorum().intValue());
}
 
Example #28
Source File: RedissonSentinelConnectionTest.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Test
public void testMasters() {
    Collection<RedisServer> masters = connection.masters();
    assertThat(masters).hasSize(1);
}
 
Example #29
Source File: RedissonSentinelConnectionTest.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Test
public void testSlaves() {
    Collection<RedisServer> masters = connection.masters();
    Collection<RedisServer> slaves = connection.slaves(masters.iterator().next());
    assertThat(slaves).hasSize(2);
}
 
Example #30
Source File: RedissonSentinelConnectionTest.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Test
public void testRemove() {
    Collection<RedisServer> masters = connection.masters();
    connection.remove(masters.iterator().next());
}