Search in sources :

Example 1 with JedisClusterInfoCache

use of redis.clients.jedis.JedisClusterInfoCache in project LinkAgent by shulieTech.

the class JedisClusterConnectionInterceptor method attachment.

void attachment(Advice advice) {
    try {
        if (Pradar.isClusterTest()) {
            return;
        }
        JedisSlotBasedConnectionHandler handler = (JedisSlotBasedConnectionHandler) advice.getTarget();
        JedisClusterInfoCache cache = Reflect.on(handler).get("cache");
        String password = Reflect.on(cache).get("password");
        Map hashmap = Reflect.on(cache).get("nodes");
        StringBuilder builder = new StringBuilder();
        for (Object node : hashmap.keySet()) {
            model.setClusterMode(String.valueOf(node));
            builder.append(node).append(",");
        }
        builder.deleteCharAt(builder.length() - 1);
        ResourceManager.set(new Attachment(new ArrayList(hashmap.keySet()), RedisConstants.PLUGIN_NAME, new String[] { RedisConstants.MIDDLEWARE_NAME }, new RedisTemplate.JedisClusterTemplate().setNodes(builder.toString()).setPassword(password)));
    } catch (Throwable t) {
    }
}
Also used : JedisSlotBasedConnectionHandler(redis.clients.jedis.JedisSlotBasedConnectionHandler) ArrayList(java.util.ArrayList) Attachment(com.pamirs.attach.plugin.dynamic.Attachment) JedisClusterInfoCache(redis.clients.jedis.JedisClusterInfoCache) Map(java.util.Map)

Example 2 with JedisClusterInfoCache

use of redis.clients.jedis.JedisClusterInfoCache in project spring-data-redis by spring-projects.

the class JedisConnectionFactoryUnitTests method shouldApplySslConfigWhenCreatingClusterClient.

// DATAREDIS-974, GH-2017
@Test
void shouldApplySslConfigWhenCreatingClusterClient() throws NoSuchAlgorithmException {
    SSLParameters sslParameters = new SSLParameters();
    SSLContext context = SSLContext.getDefault();
    SSLSocketFactory socketFactory = context.getSocketFactory();
    JedisPoolConfig poolConfig = new JedisPoolConfig();
    HostnameVerifier hostNameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
    JedisClientConfiguration configuration = // 
    JedisClientConfiguration.builder().useSsl().hostnameVerifier(// 
    hostNameVerifier).sslParameters(// 
    sslParameters).sslSocketFactory(socketFactory).and().clientName(// 
    "my-client").connectTimeout(// 
    Duration.ofMinutes(1)).readTimeout(// 
    Duration.ofMinutes(5)).usePooling().poolConfig(// 
    poolConfig).build();
    connectionFactory = new JedisConnectionFactory(new RedisClusterConfiguration(), configuration);
    connectionFactory.afterPropertiesSet();
    RedisClusterConnection connection = connectionFactory.getClusterConnection();
    assertThat(connection).isInstanceOf(JedisClusterConnection.class);
    JedisCluster cluster = ((JedisClusterConnection) connection).getCluster();
    JedisClusterConnectionHandler connectionHandler = (JedisClusterConnectionHandler) ReflectionTestUtils.getField(cluster, "connectionHandler");
    JedisClusterInfoCache cache = (JedisClusterInfoCache) ReflectionTestUtils.getField(connectionHandler, "cache");
    JedisClientConfig clientConfig = (JedisClientConfig) ReflectionTestUtils.getField(cache, "clientConfig");
    assertThat(clientConfig.getConnectionTimeoutMillis()).isEqualTo(60000);
    assertThat(clientConfig.getSocketTimeoutMillis()).isEqualTo(300000);
    assertThat(clientConfig.getPassword()).isNull();
    assertThat(clientConfig.getClientName()).isEqualTo("my-client");
    assertThat(clientConfig.isSsl()).isEqualTo(true);
    assertThat(clientConfig.getSslSocketFactory()).isEqualTo(socketFactory);
    assertThat(clientConfig.getSslParameters()).isEqualTo(sslParameters);
    assertThat(clientConfig.getHostnameVerifier()).isEqualTo(hostNameVerifier);
    assertThat(clientConfig.getHostAndPortMapper()).isNull();
}
Also used : RedisClusterConnection(org.springframework.data.redis.connection.RedisClusterConnection) JedisClientConfig(redis.clients.jedis.JedisClientConfig) RedisClusterConfiguration(org.springframework.data.redis.connection.RedisClusterConfiguration) SSLContext(javax.net.ssl.SSLContext) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) HostnameVerifier(javax.net.ssl.HostnameVerifier) SSLParameters(javax.net.ssl.SSLParameters) JedisCluster(redis.clients.jedis.JedisCluster) JedisClusterConnectionHandler(redis.clients.jedis.JedisClusterConnectionHandler) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) JedisClusterInfoCache(redis.clients.jedis.JedisClusterInfoCache) Test(org.junit.jupiter.api.Test)

Aggregations

JedisClusterInfoCache (redis.clients.jedis.JedisClusterInfoCache)2 Attachment (com.pamirs.attach.plugin.dynamic.Attachment)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 HostnameVerifier (javax.net.ssl.HostnameVerifier)1 SSLContext (javax.net.ssl.SSLContext)1 SSLParameters (javax.net.ssl.SSLParameters)1 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)1 Test (org.junit.jupiter.api.Test)1 RedisClusterConfiguration (org.springframework.data.redis.connection.RedisClusterConfiguration)1 RedisClusterConnection (org.springframework.data.redis.connection.RedisClusterConnection)1 JedisClientConfig (redis.clients.jedis.JedisClientConfig)1 JedisCluster (redis.clients.jedis.JedisCluster)1 JedisClusterConnectionHandler (redis.clients.jedis.JedisClusterConnectionHandler)1 JedisPoolConfig (redis.clients.jedis.JedisPoolConfig)1 JedisSlotBasedConnectionHandler (redis.clients.jedis.JedisSlotBasedConnectionHandler)1