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

The following examples show how to use org.springframework.data.redis.connection.RedisNode. 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: CacheCloudInfoHttpHelper.java    From summerframework with 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 File: RateLimiterPluginDataHandler.java    From soul with 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 File: RedisConfig.java    From jee-universal-bms with 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
Source File: RequiresRedisSentinel.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
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
Source File: RequiresRedisSentinel.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
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 File: TracingRedisConnection.java    From java-redis-client with 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 File: TracingRedisConnection.java    From java-redis-client with 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 File: TracingRedisConnection.java    From java-redis-client with 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 File: TracingRedisConnection.java    From java-redis-client with 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 File: RedissonConnection.java    From redisson with 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 File: RedissonConnection.java    From redisson with 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 File: RedissonConnection.java    From redisson with 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 File: RedissonConnection.java    From redisson with 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 File: RedissonConnection.java    From redisson with 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 File: RedissonConnection.java    From redisson with 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);
}