List of usage examples for org.springframework.data.redis.connection RedisNode getPort
@Nullable
public Integer getPort()
From source file:example.springdata.redis.test.util.RequiresRedisSentinel.java
private boolean isAvailable(RedisNode node) { Jedis jedis = null;// w w w .j av a2 s . c o m try { jedis = new Jedis(node.getHost(), node.getPort()); jedis.connect(); jedis.ping(); } catch (Exception e) { return false; } finally { if (jedis != null) { try { jedis.disconnect(); jedis.close(); } catch (Exception e) { e.printStackTrace(); } } } return true; }
From source file:org.solq.dht.db.redis.service.JedisConnectionFactory.java
private Jedis getActiveSentinel() { Assert.notNull(this.sentinelConfig); for (RedisNode node : this.sentinelConfig.getSentinels()) { Jedis jedis = new Jedis(node.getHost(), node.getPort()); if (jedis.ping().equalsIgnoreCase("pong")) { return jedis; }/* w ww. ja v a 2 s .co m*/ } throw new InvalidDataAccessResourceUsageException("no sentinel found"); }
From source file:org.springframework.data.redis.connection.jedis.JedisConnectionFactory.java
/** * Creates {@link JedisCluster} for given {@link RedisClusterConfiguration} and {@link GenericObjectPoolConfig}. * //ww w . ja v a 2 s .com * @param clusterConfig must not be {@literal null}. * @param poolConfig can be {@literal null}. * @return * @since 1.7 */ protected JedisCluster createCluster(RedisClusterConfiguration clusterConfig, GenericObjectPoolConfig poolConfig) { Assert.notNull("Cluster configuration must not be null!"); Set<HostAndPort> hostAndPort = new HashSet<HostAndPort>(); for (RedisNode node : clusterConfig.getClusterNodes()) { hostAndPort.add(new HostAndPort(node.getHost(), node.getPort())); } int redirects = clusterConfig.getMaxRedirects() != null ? clusterConfig.getMaxRedirects().intValue() : 5; if (StringUtils.hasText(getPassword())) { throw new IllegalArgumentException( "Jedis does not support password protected Redis Cluster configurations!"); } if (poolConfig != null) { return new JedisCluster(hostAndPort, timeout, redirects, poolConfig); } return new JedisCluster(hostAndPort, timeout, redirects, poolConfig); }
From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.java
private AbstractRedisClient createRedisClient() { if (isRedisSentinelAware()) { RedisURI redisURI = getSentinelRedisURI(); if (clientResources == null) { return RedisClient.create(redisURI); }//w w w .j a v a 2s . c o m return RedisClient.create(clientResources, redisURI); } if (isClusterAware()) { List<RedisURI> initialUris = new ArrayList<RedisURI>(); for (RedisNode node : this.clusterConfiguration.getClusterNodes()) { initialUris.add(createRedisURIAndApplySettings(node.getHost(), node.getPort())); } RedisClusterClient clusterClient = clientResources != null ? RedisClusterClient.create(clientResources, initialUris) : RedisClusterClient.create(initialUris); this.clusterCommandExecutor = new ClusterCommandExecutor( new LettuceClusterConnection.LettuceClusterTopologyProvider(clusterClient), new LettuceClusterConnection.LettuceClusterNodeResourceProvider(clusterClient), EXCEPTION_TRANSLATION); return clusterClient; } if (pool != null) { return pool.getClient(); } RedisURI uri = createRedisURIAndApplySettings(hostName, port); return clientResources != null ? RedisClient.create(clientResources, uri) : RedisClient.create(uri); }