Java Code Examples for org.springframework.data.redis.connection.RedisNode

The following examples show how to use org.springframework.data.redis.connection.RedisNode. These examples are extracted from open source projects. 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 Project: summerframework   Source File: CacheCloudInfoHttpHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static RedisSentinelConfiguration generateSentinelConfiguration(Long appId, String hostUrl) {
    try {
        LOCK.tryLock(10, TimeUnit.SECONDS);
        String cachecloudUrl = hostUrl + REDIS_SENTINEL_SUFFIX + CLIENT_VERSION;
        CACHECLOUD_REPORT_URL = hostUrl + CACHECLOUD_REPORT_URL_PATH;
        String url = String.format(cachecloudUrl, String.valueOf(appId));
        String response = HttpUtils.doGet(String.format(url, appId));
        if (response == null || StringUtils.isEmpty(response)) {
            LOGGER.warn("get response from remote server error, appId: {}, continue...", appId);
            throw new RuntimeException();
        }
        ObjectMapper mapper = new ObjectMapper();
        JsonNode heartbeatInfo = mapper.readTree(response);
        String masterName = heartbeatInfo.get("masterName").asText();
        String sentinels = heartbeatInfo.get("sentinels").asText();
        Set<RedisNode> sentinelSet = new HashSet<RedisNode>();
        for (String sentinelStr : sentinels.split(" ")) {
            String[] sentinelArr = sentinelStr.split(":");
            if (sentinelArr.length == 2) {
                sentinelSet.add(new RedisNode(sentinelArr[0], Integer.valueOf(sentinelArr[1])));
            }
        }
        RedisSentinelConfiguration config = new RedisSentinelConfiguration();
        config.master(masterName);
        config.setSentinels(sentinelSet);
        ClientDataCollectReportExecutor.getInstance();
        return config;
    } catch (Throwable e) {
        LOGGER.error("error in build, appId: {}", appId, e);
        throw new RuntimeException(e);
    } finally {
        LOCK.unlock();
    }
}
 
Example 2
Source Project: soul   Source File: RateLimiterPluginDataHandler.java    License: Apache License 2.0 5 votes vote down vote up
private List<RedisNode> createRedisNode(final String url) {
    List<RedisNode> redisNodes = new ArrayList<>();
    List<String> nodes = Lists.newArrayList(Splitter.on(";").split(url));
    for (String node : nodes) {
        String[] parts = StringUtils.split(node, ":");
        Assert.state(Objects.requireNonNull(parts).length == 2, "Must be defined as 'host:port'");
        redisNodes.add(new RedisNode(parts[0], Integer.parseInt(parts[1])));
    }
    return redisNodes;
}
 
Example 3
Source Project: jee-universal-bms   Source File: RedisConfig.java    License: Apache License 2.0 5 votes vote down vote up
private List<RedisNode> createSentinels(String sentinelNodes) {
    List<RedisNode> sentinels = new ArrayList<RedisNode>();
    for (String node : StringUtils.commaDelimitedListToStringArray(sentinelNodes)) {
        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;
}
 
Example 4
private void verify(SentinelsAvailable verificationMode) {

		int failed = 0;
		for (RedisNode node : sentinelConfig.getSentinels()) {
			if (!isAvailable(node)) {
				failed++;
			}
		}

		if (failed > 0) {
			if (SentinelsAvailable.ALL_ACTIVE.equals(verificationMode)) {
				throw new AssumptionViolatedException(
						String.format("Expected all Redis Sentinels to respone but %s of %s did not responde", failed,
								sentinelConfig.getSentinels().size()));
			}

			if (SentinelsAvailable.ONE_ACTIVE.equals(verificationMode) && sentinelConfig.getSentinels().size() - 1 < failed) {
				throw new AssumptionViolatedException(
						"Expected at least one sentinel to respond but it seems all are offline - Game Over!");
			}
		}

		if (SentinelsAvailable.NONE_ACTIVE.equals(verificationMode) && failed != sentinelConfig.getSentinels().size()) {
			throw new AssumptionViolatedException(
					String.format("Expected to have no sentinels online but found that %s are still alive.",
							(sentinelConfig.getSentinels().size() - failed)));
		}
	}
 
Example 5
private boolean isAvailable(RedisNode node) {

		RedisClient redisClient = RedisClient.create(ManagedClientResources.getClientResources(),
				RedisURI.create(node.getHost(), node.getPort()));

		try (StatefulRedisConnection<String, String> connection = redisClient.connect()) {
			connection.sync().ping();
		} catch (Exception e) {
			return false;
		} finally {
			redisClient.shutdown(Duration.ZERO, Duration.ZERO);
		}

		return true;
	}
 
Example 6
Source Project: java-redis-client   Source File: TracingRedisConnection.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void migrate(byte[] key, RedisNode target, int dbIndex, MigrateOption option) {
  helper.doInScope(RedisCommand.MIGRATE, key,
      () -> connection.migrate(key, target, dbIndex, option));
}
 
Example 7
Source Project: java-redis-client   Source File: TracingRedisConnection.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void migrate(byte[] key, RedisNode target, int dbIndex, MigrateOption option,
    long timeout) {
  helper.doInScope(RedisCommand.MIGRATE,
      key, () -> connection.migrate(key, target, dbIndex, option, timeout));
}
 
Example 8
Source Project: java-redis-client   Source File: TracingRedisConnection.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void migrate(byte[] key, RedisNode target, int dbIndex, MigrateOption option) {
  helper.doInScope(RedisCommand.MIGRATE, key,
      () -> connection.migrate(key, target, dbIndex, option));
}
 
Example 9
Source Project: java-redis-client   Source File: TracingRedisConnection.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void migrate(byte[] key, RedisNode target, int dbIndex, MigrateOption option,
    long timeout) {
  helper.doInScope(RedisCommand.MIGRATE,
      key, () -> connection.migrate(key, target, dbIndex, option, timeout));
}
 
Example 10
Source Project: redisson   Source File: RedissonConnection.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void migrate(byte[] key, RedisNode target, int dbIndex, MigrateOption option) {
    migrate(key, target, dbIndex, option, Long.MAX_VALUE);
}
 
Example 11
Source Project: redisson   Source File: RedissonConnection.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void migrate(byte[] key, RedisNode target, int dbIndex, MigrateOption option, long timeout) {
    write(key, StringCodec.INSTANCE, RedisCommands.MIGRATE, target.getHost(), target.getPort(), key, dbIndex, timeout);
}
 
Example 12
Source Project: redisson   Source File: RedissonConnection.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void migrate(byte[] key, RedisNode target, int dbIndex, MigrateOption option) {
    migrate(key, target, dbIndex, option, Long.MAX_VALUE);
}
 
Example 13
Source Project: redisson   Source File: RedissonConnection.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void migrate(byte[] key, RedisNode target, int dbIndex, MigrateOption option, long timeout) {
    write(key, StringCodec.INSTANCE, RedisCommands.MIGRATE, target.getHost(), target.getPort(), key, dbIndex, timeout);
}
 
Example 14
Source Project: redisson   Source File: RedissonConnection.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void migrate(byte[] key, RedisNode target, int dbIndex, MigrateOption option) {
    migrate(key, target, dbIndex, option, Long.MAX_VALUE);
}
 
Example 15
Source Project: redisson   Source File: RedissonConnection.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void migrate(byte[] key, RedisNode target, int dbIndex, MigrateOption option, long timeout) {
    write(key, StringCodec.INSTANCE, RedisCommands.MIGRATE, target.getHost(), target.getPort(), key, dbIndex, timeout);
}