Example usage for org.springframework.data.redis.connection RedisClusterNode getId

List of usage examples for org.springframework.data.redis.connection RedisClusterNode getId

Introduction

In this page you can find the example usage for org.springframework.data.redis.connection RedisClusterNode getId.

Prototype

@Nullable
public String getId() 

Source Link

Usage

From source file:org.springframework.data.redis.connection.jedis.JedisClusterConnection.java

@Override
public void clusterSetSlot(RedisClusterNode node, int slot, AddSlots mode) {

    Assert.notNull(node, "Node must not be null.");
    Assert.notNull(mode, "AddSlots mode must not be null.");

    RedisClusterNode nodeToUse = topologyProvider.getTopology().lookup(node);
    String nodeId = nodeToUse.getId();

    clusterCommandExecutor.executeCommandOnSingleNode((JedisClusterCommandCallback<String>) client -> {

        switch (mode) {
        case IMPORTING:
            return client.clusterSetSlotImporting(slot, nodeId);
        case MIGRATING:
            return client.clusterSetSlotMigrating(slot, nodeId);
        case STABLE:
            return client.clusterSetSlotStable(slot);
        case NODE:
            return client.clusterSetSlotNode(slot, nodeId);
        }/*from ww  w.j a  v a2s .c om*/

        throw new IllegalArgumentException(String.format("Unknown AddSlots mode '%s'.", mode));
    }, node);

}

From source file:org.springframework.data.redis.connection.jedis.JedisClusterConnection.java

@Override
public void clusterForget(RedisClusterNode node) {

    Set<RedisClusterNode> nodes = new LinkedHashSet<>(topologyProvider.getTopology().getActiveMasterNodes());
    RedisClusterNode nodeToRemove = topologyProvider.getTopology().lookup(node);
    nodes.remove(nodeToRemove);//  ww w.  j a va  2  s . c om

    clusterCommandExecutor.executeCommandAsyncOnNodes(
            (JedisClusterCommandCallback<String>) client -> client.clusterForget(node.getId()), nodes);
}

From source file:org.springframework.data.redis.connection.jedis.JedisClusterConnection.java

@Override
public void clusterReplicate(RedisClusterNode master, RedisClusterNode replica) {

    RedisClusterNode masterNode = topologyProvider.getTopology().lookup(master);

    clusterCommandExecutor.executeCommandOnSingleNode(
            (JedisClusterCommandCallback<String>) client -> client.clusterReplicate(masterNode.getId()),
            replica);//from w ww  .  jav  a  2 s .  com

}

From source file:org.springframework.data.redis.connection.jedis.JedisClusterConnection.java

@Override
public Set<RedisClusterNode> clusterGetSlaves(RedisClusterNode master) {

    Assert.notNull(master, "Master cannot be null!");

    RedisClusterNode nodeToUse = topologyProvider.getTopology().lookup(master);

    return JedisConverters.toSetOfRedisClusterNodes(clusterCommandExecutor.executeCommandOnSingleNode(
            (JedisClusterCommandCallback<List<String>>) client -> client.clusterSlaves(nodeToUse.getId()),
            master).getValue());// www  .ja va2  s  .  c o  m
}

From source file:org.springframework.data.redis.connection.lettuce.LettuceClusterConnection.java

@Override
public Set<RedisClusterNode> clusterGetSlaves(RedisClusterNode master) {

    Assert.notNull(master, "Master must not be null!");

    RedisClusterNode nodeToUse = topologyProvider.getTopology().lookup(master);

    return clusterCommandExecutor
            .executeCommandOnSingleNode(
                    (LettuceClusterCommandCallback<Set<RedisClusterNode>>) client -> LettuceConverters
                            .toSetOfRedisClusterNodes(client.clusterSlaves(nodeToUse.getId())),
                    master)//from   w  ww .  ja v  a 2  s  .  c  om
            .getValue();
}

From source file:org.springframework.data.redis.connection.lettuce.LettuceClusterConnection.java

@Override
public void clusterForget(RedisClusterNode node) {

    List<RedisClusterNode> nodes = new ArrayList<>(clusterGetNodes());
    RedisClusterNode nodeToRemove = topologyProvider.getTopology().lookup(node);
    nodes.remove(nodeToRemove);/*www.j  ava  2 s .c  o m*/

    this.clusterCommandExecutor.executeCommandAsyncOnNodes(
            (LettuceClusterCommandCallback<String>) client -> client.clusterForget(nodeToRemove.getId()),
            nodes);
}

From source file:org.springframework.data.redis.connection.lettuce.LettuceClusterConnection.java

@Override
public void clusterSetSlot(RedisClusterNode node, int slot, AddSlots mode) {

    Assert.notNull(node, "Node must not be null.");
    Assert.notNull(mode, "AddSlots mode must not be null.");

    RedisClusterNode nodeToUse = topologyProvider.getTopology().lookup(node);
    String nodeId = nodeToUse.getId();

    clusterCommandExecutor.executeCommandOnSingleNode((LettuceClusterCommandCallback<String>) client -> {
        switch (mode) {
        case MIGRATING:
            return client.clusterSetSlotMigrating(slot, nodeId);
        case IMPORTING:
            return client.clusterSetSlotImporting(slot, nodeId);
        case NODE:
            return client.clusterSetSlotNode(slot, nodeId);
        case STABLE:
            return client.clusterSetSlotStable(slot);
        default:/*from  w  ww  .ja  va2 s .  c o  m*/
            throw new InvalidDataAccessApiUsageException("Invalid import mode for cluster slot: " + slot);
        }
    }, node);
}

From source file:org.springframework.data.redis.connection.lettuce.LettuceClusterConnection.java

@Override
public void clusterReplicate(RedisClusterNode master, RedisClusterNode replica) {

    RedisClusterNode masterNode = topologyProvider.getTopology().lookup(master);
    clusterCommandExecutor.executeCommandOnSingleNode(
            (LettuceClusterCommandCallback<String>) client -> client.clusterReplicate(masterNode.getId()),
            replica);//from  w  ww  .  ja  v  a 2  s.c o m
}