use of org.springframework.data.redis.connection.RedisClusterConfiguration in project spring-boot by spring-projects.
the class RedisConnectionConfiguration method getClusterConfiguration.
/**
* Create a {@link RedisClusterConfiguration} if necessary.
* @return {@literal null} if no cluster settings are set.
*/
protected final RedisClusterConfiguration getClusterConfiguration() {
if (this.clusterConfiguration != null) {
return this.clusterConfiguration;
}
if (this.properties.getCluster() == null) {
return null;
}
RedisProperties.Cluster clusterProperties = this.properties.getCluster();
RedisClusterConfiguration config = new RedisClusterConfiguration(clusterProperties.getNodes());
if (clusterProperties.getMaxRedirects() != null) {
config.setMaxRedirects(clusterProperties.getMaxRedirects());
}
config.setUsername(this.properties.getUsername());
if (this.properties.getPassword() != null) {
config.setPassword(RedisPassword.of(this.properties.getPassword()));
}
return config;
}
use of org.springframework.data.redis.connection.RedisClusterConfiguration in project pancm_project by xuwujing.
the class RedisConfig method redisClusterConfiguration.
/**
* Redis集群的配置
*
* @return the redis cluster configuration
*/
@Bean
public RedisClusterConfiguration redisClusterConfiguration() {
RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration();
// Set<RedisNode> clusterNodes
String[] serverArray = clusterNodes.split(",");
Set<RedisNode> nodes = new HashSet<RedisNode>();
for (String ipPort : serverArray) {
String[] ipAndPort = ipPort.split(":");
nodes.add(new RedisNode(ipAndPort[0].trim(), Integer.valueOf(ipAndPort[1])));
}
redisClusterConfiguration.setClusterNodes(nodes);
redisClusterConfiguration.setMaxRedirects(mmaxRedirectsac);
return redisClusterConfiguration;
}
use of org.springframework.data.redis.connection.RedisClusterConfiguration in project thingsboard by thingsboard.
the class TBRedisClusterConfiguration method loadFactory.
public JedisConnectionFactory loadFactory() {
RedisClusterConfiguration clusterConfiguration = new RedisClusterConfiguration();
clusterConfiguration.setClusterNodes(getNodes(clusterNodes));
clusterConfiguration.setMaxRedirects(maxRedirects);
clusterConfiguration.setPassword(password);
if (useDefaultPoolConfig) {
return new JedisConnectionFactory(clusterConfiguration);
} else {
return new JedisConnectionFactory(clusterConfiguration, buildPoolConfig());
}
}
use of org.springframework.data.redis.connection.RedisClusterConfiguration in project JAQU-CAZ-Payments-API by InformedSolutions.
the class RedisConfiguration method lettuceConnectionFactory.
/**
* Customised lettuce connection factory builder.
*
* @return A lettuce connection factory instance.
*/
@Bean
@Profile("!integration-tests")
public LettuceConnectionFactory lettuceConnectionFactory() {
log.info("Creating redis-connection for a cluster");
LettuceClientConfiguration clientConfiguration;
if (redisUseSsl) {
log.info("Configuring redis connection using SSL");
clientConfiguration = LettuceClientConfiguration.builder().useSsl().disablePeerVerification().and().commandTimeout(Duration.ofSeconds(commandTimeout)).build();
} else {
clientConfiguration = LettuceClientConfiguration.builder().commandTimeout(Duration.ofSeconds(commandTimeout)).build();
}
RedisClusterConfiguration clusterConfiguration = new RedisClusterConfiguration();
clusterConfiguration.clusterNode(redisClusterEndpoint, redisClusterPort);
return new LettuceConnectionFactory(clusterConfiguration, clientConfiguration);
}
use of org.springframework.data.redis.connection.RedisClusterConfiguration in project LinkAgent by shulieTech.
the class SpringRedisClientInfoCollector method attachment.
/**
* 业务流量的信息采集
*
* @param advice
*/
protected void attachment(Advice advice) {
try {
if (Pradar.isClusterTest()) {
return;
}
LettuceConnectionFactory biz = (LettuceConnectionFactory) advice.getTarget();
Object standaloneConfiguration = biz.getStandaloneConfiguration();
Object clusterConfiguration = biz.getClusterConfiguration();
Object sentinelConfiguration = biz.getSentinelConfiguration();
if (clusterConfiguration != null) {
Set<RedisNode> nodeSet = ((RedisClusterConfiguration) clusterConfiguration).getClusterNodes();
StringBuilder builder = new StringBuilder();
for (RedisNode node : nodeSet) {
String host = node.getHost();
String port = String.valueOf(node.getPort());
builder.append(host.concat(":").concat(port)).append(",");
}
String nodes = builder.deleteCharAt(builder.length() - 1).toString();
String password = null;
try {
char[] passwdbyte = ((RedisClusterConfiguration) clusterConfiguration).getPassword().get();
password = new String(passwdbyte);
} catch (NoSuchElementException e) {
//
}
ResourceManager.set(new Attachment(Arrays.asList(nodes.split(",")), "redis-lettuce", new String[] { "redis" }, new RedisTemplate.LettuceClusterTemplate().setNodes(nodes).setPassword(password)));
} else if (sentinelConfiguration != null) {
RedisSentinelConfiguration redisSentinelConfiguration = (RedisSentinelConfiguration) sentinelConfiguration;
String masterName = redisSentinelConfiguration.getMaster().getName();
String password = null;
try {
char[] passwdbyte = redisSentinelConfiguration.getPassword().get();
password = new String(passwdbyte);
} catch (NoSuchElementException e) {
//
}
Integer database = Integer.parseInt(String.valueOf(redisSentinelConfiguration.getDatabase()));
Set<RedisNode> nodeSet = redisSentinelConfiguration.getSentinels();
StringBuilder builder = new StringBuilder();
for (RedisNode node : nodeSet) {
String host = node.getHost();
String port = String.valueOf(node.getPort());
builder.append(host.concat(":").concat(port)).append(",");
}
String nodes = builder.deleteCharAt(builder.length() - 1).toString();
List<String> sentinelRemoteAddress = new ArrayList<String>();
try {
AbstractRedisClient client = Reflect.on(biz).get("client");
ChannelGroup channelGroup = Reflect.on(client).get("channels");
Iterator iterator = channelGroup.iterator();
while (iterator.hasNext()) {
Object o = iterator.next();
if (o instanceof NioSocketChannel) {
NioSocketChannel channel = (NioSocketChannel) o;
InetSocketAddress inetSocketAddress = channel.remoteAddress();
String host = inetSocketAddress.getAddress().getHostName();
String port = String.valueOf(inetSocketAddress.getPort());
sentinelRemoteAddress.add(host.concat(":").concat(port));
}
}
} catch (Throwable t) {
logger.error(Throwables.getStackTraceAsString(t));
}
sentinelRemoteAddress.addAll(Arrays.asList(nodes.split(",")));
ResourceManager.set(new Attachment(sentinelRemoteAddress, "redis-lettuce", new String[] { "redis" }, new RedisTemplate.LettuceSentinelTemplate().setNodes(nodes).setPassword(password).setMaster(masterName).setDatabase(database)));
} else /**
*standalone肯定不为空 放后面 因为可能为localhost
*/
if (standaloneConfiguration != null && !("localhost".equals(((RedisStandaloneConfiguration) standaloneConfiguration).getHostName()))) {
RedisStandaloneConfiguration configuration = (RedisStandaloneConfiguration) standaloneConfiguration;
String host = configuration.getHostName();
Integer port = configuration.getPort();
Integer db = configuration.getDatabase();
String password = null;
try {
char[] passwdbyte = configuration.getPassword().get();
password = new String(passwdbyte);
} catch (NoSuchElementException e) {
//
}
String node = host.concat(":").concat(String.valueOf(port));
ResourceManager.set(new Attachment(Arrays.asList(node), "redis-lettuce", new String[] { "redis" }, new RedisTemplate.LettuceSingleTemplate().setNodes(node).setPassword(password).setDatabase(db)));
}
} catch (Throwable t) {
logger.error("[redis-lettuce] collector spring biz info error , {}", Throwables.getStackTraceAsString(t));
}
}
Aggregations