io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands Java Examples

The following examples show how to use io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands. 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: ClusterScaleProcessServiceImpl.java    From cymbal with Apache License 2.0 6 votes vote down vote up
private void setSlotToTargetNode(final StatefulRedisClusterConnection redisConnection,
        final RedisClusterNode targetNode, final int slot) {
    RedisAdvancedClusterCommands commands = redisConnection.sync();
    retryTemplate.execute(retryContext -> {
        NodeSelection masters = commands.masters();
        int succeedMasterCount = 0;
        StringBuffer failMessage = new StringBuffer();
        for (int i = 0; i < masters.size(); i++) {
            String result = commands.getConnection(masters.node(i).getNodeId()).
                    clusterSetSlotNode(slot, targetNode.getNodeId());
            if (Constant.Redis.EXECUTE_RESULT_SUCCESS.equals(result)) {
                succeedMasterCount++;
            } else {
                failMessage.append(masters.node(i).getUri());
                failMessage.append(": ");
                failMessage.append(result);
                failMessage.append("\n");
            }
        }
        if (succeedMasterCount * 2 < masters.size()) {
            throw new ScaleException("Fail to set node of slot '%d', return value is '%s'.", slot,
                    failMessage.toString());
        }
        return Constant.Redis.EXECUTE_RESULT_SUCCESS;
    });
}
 
Example #2
Source File: ClusterScaleProcessServiceImpl.java    From cymbal with Apache License 2.0 5 votes vote down vote up
private void migrateKeysInSlot(final StatefulRedisClusterConnection redisConnection,
        final RedisClusterNode sourceNode, final RedisClusterNode targetNode, final int slot) {
    RedisAdvancedClusterCommands commands = redisConnection.sync();
    retryTemplate.execute(retryContext -> {
        boolean migrateDone = false;
        while (!migrateDone) {
            List<String> keys = commands.getConnection(sourceNode.getNodeId())
                    .clusterGetKeysInSlot(slot, KEYS_PER_MIGRATE);
            log.debug("Migrating '{}' keys to '{}'.", keys.size(), targetNode.getUri());

            if (keys.isEmpty()) {
                migrateDone = true;
            } else {
                String[] keysArray = keys.toArray(new String[keys.size()]);

                // do migrate
                String result = commands.migrate(targetNode.getUri().getHost(), targetNode.getUri().getPort(), 0,
                        MIGRATE_TIMEOUT * (retryContext.getRetryCount() + 1),
                        MigrateArgs.Builder.keys(keysArray).copy().replace());

                // if result is OK, del keys from source node
                switch (result) {
                    case Constant.Redis.EXECUTE_RESULT_SUCCESS:
                        commands.del(keysArray);
                        if (keys.size() < KEYS_PER_MIGRATE) {
                            migrateDone = true;
                        }
                        break;
                    case Constant.Redis.EXECUTE_RESULT_NOKEY:
                        migrateDone = true;
                        break;
                    default:
                        throw new ScaleException(String.format("Migrate fail of slot '%d'.", slot));
                }
            }
        }

        return Constant.Redis.EXECUTE_RESULT_SUCCESS;
    });
}
 
Example #3
Source File: TracingRedisAdvancedClusterCommands.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
public TracingRedisAdvancedClusterCommands(RedisAdvancedClusterCommands<K, V> commands,
    TracingConfiguration tracingConfiguration) {

  this.commands = commands;
  this.helper = new TracingHelper(tracingConfiguration);
  this.tracingConfiguration = tracingConfiguration;
}
 
Example #4
Source File: TracingRedisAdvancedClusterCommands.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
public TracingRedisAdvancedClusterCommands(RedisAdvancedClusterCommands<K, V> commands,
    TracingConfiguration tracingConfiguration) {

  this.commands = commands;
  this.helper = new TracingHelper(tracingConfiguration);
  this.tracingConfiguration = tracingConfiguration;
}
 
Example #5
Source File: TracingRedisAdvancedClusterCommands.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
public TracingRedisAdvancedClusterCommands(RedisAdvancedClusterCommands<K, V> commands,
    TracingConfiguration tracingConfiguration) {

  this.commands = commands;
  this.helper = new TracingHelper(tracingConfiguration);
  this.tracingConfiguration = tracingConfiguration;
}
 
Example #6
Source File: StringStringSyncTest.java    From hazelcast-simulator with Apache License 2.0 5 votes vote down vote up
@Prepare(global = true)
public void loadInitialData() {
    Random random = new Random();
    StatefulRedisClusterConnection<String, String> connection = redisClient.connect();
    RedisAdvancedClusterCommands sync = connection.sync();
    // get rid of all data.
    sync.flushall();

    for (int k = 0; k < keyDomain; k++) {
        int r = random.nextInt(valueCount);
        sync.set(Long.toString(k), values[r]);
    }

    //connection.async().set()
}
 
Example #7
Source File: TracingStatefulRedisClusterConnection.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RedisAdvancedClusterCommands<K, V> sync() {
  return new TracingRedisAdvancedClusterCommands<>(connection.sync(), tracingConfiguration);
}
 
Example #8
Source File: TracingStatefulRedisClusterConnection.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RedisAdvancedClusterCommands<K, V> sync() {
  return new TracingRedisAdvancedClusterCommands<>(connection.sync(), tracingConfiguration);
}
 
Example #9
Source File: TracingStatefulRedisClusterConnection.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RedisAdvancedClusterCommands<K, V> sync() {
  return new TracingRedisAdvancedClusterCommands<>(connection.sync(), tracingConfiguration);
}