Search in sources :

Example 1 with RedisStandaloneConfiguration

use of org.springframework.data.redis.connection.RedisStandaloneConfiguration in project thingsboard by thingsboard.

the class TBRedisStandaloneConfiguration method loadFactory.

public JedisConnectionFactory loadFactory() {
    RedisStandaloneConfiguration standaloneConfiguration = new RedisStandaloneConfiguration();
    standaloneConfiguration.setHostName(host);
    standaloneConfiguration.setPort(port);
    standaloneConfiguration.setDatabase(db);
    standaloneConfiguration.setPassword(password);
    if (useDefaultClientConfig) {
        return new JedisConnectionFactory(standaloneConfiguration);
    } else {
        return new JedisConnectionFactory(standaloneConfiguration, buildClientConfig());
    }
}
Also used : JedisConnectionFactory(org.springframework.data.redis.connection.jedis.JedisConnectionFactory) RedisStandaloneConfiguration(org.springframework.data.redis.connection.RedisStandaloneConfiguration)

Example 2 with RedisStandaloneConfiguration

use of org.springframework.data.redis.connection.RedisStandaloneConfiguration in project spring-integration by spring-projects.

the class RedisAvailableRule method apply.

public Statement apply(final Statement base, final FrameworkMethod method, Object target) {
    RedisAvailable redisAvailable = method.getAnnotation(RedisAvailable.class);
    if (redisAvailable != null) {
        JedisConnectionFactory connectionFactory = null;
        try {
            RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
            redisStandaloneConfiguration.setPort(REDIS_PORT);
            JedisClientConfiguration clientConfiguration = JedisClientConfiguration.builder().connectTimeout(Duration.ofSeconds(20)).readTimeout(Duration.ofSeconds(20)).build();
            connectionFactory = new JedisConnectionFactory(redisStandaloneConfiguration, clientConfiguration);
            connectionFactory.afterPropertiesSet();
            connectionFactory.getConnection();
            connectionFactoryResource.set(connectionFactory);
        } catch (Exception e) {
            if (connectionFactory != null) {
                connectionFactory.destroy();
            }
            return new Statement() {

                @Override
                public void evaluate() throws Throwable {
                    Assume.assumeTrue("Skipping test due to Redis not being available on port: " + REDIS_PORT, false);
                }
            };
        }
        return new Statement() {

            @Override
            public void evaluate() throws Throwable {
                try {
                    base.evaluate();
                } finally {
                    JedisConnectionFactory connectionFactory = connectionFactoryResource.get();
                    connectionFactoryResource.remove();
                    if (connectionFactory != null) {
                        connectionFactory.destroy();
                    }
                }
            }
        };
    }
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            base.evaluate();
        }
    };
}
Also used : Statement(org.junit.runners.model.Statement) JedisConnectionFactory(org.springframework.data.redis.connection.jedis.JedisConnectionFactory) RedisStandaloneConfiguration(org.springframework.data.redis.connection.RedisStandaloneConfiguration) JedisClientConfiguration(org.springframework.data.redis.connection.jedis.JedisClientConfiguration)

Example 3 with RedisStandaloneConfiguration

use of org.springframework.data.redis.connection.RedisStandaloneConfiguration in project spring-boot by spring-projects.

the class RedisConnectionConfiguration method getStandaloneConfig.

protected final RedisStandaloneConfiguration getStandaloneConfig() {
    if (this.standaloneConfiguration != null) {
        return this.standaloneConfiguration;
    }
    RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
    if (StringUtils.hasText(this.properties.getUrl())) {
        ConnectionInfo connectionInfo = parseUrl(this.properties.getUrl());
        config.setHostName(connectionInfo.getHostName());
        config.setPort(connectionInfo.getPort());
        config.setUsername(connectionInfo.getUsername());
        config.setPassword(RedisPassword.of(connectionInfo.getPassword()));
    } else {
        config.setHostName(this.properties.getHost());
        config.setPort(this.properties.getPort());
        config.setUsername(this.properties.getUsername());
        config.setPassword(RedisPassword.of(this.properties.getPassword()));
    }
    config.setDatabase(this.properties.getDatabase());
    return config;
}
Also used : RedisStandaloneConfiguration(org.springframework.data.redis.connection.RedisStandaloneConfiguration)

Example 4 with RedisStandaloneConfiguration

use of org.springframework.data.redis.connection.RedisStandaloneConfiguration in project dhis2-core by dhis2.

the class RedisConfiguration method lettuceConnectionFactory.

@Bean
public LettuceConnectionFactory lettuceConnectionFactory() {
    LettuceClientConfigurationBuilder builder = LettuceClientConfiguration.builder();
    if (DhisConfigurationProvider.isOn((String) redisSslEnabled().getObject())) {
        builder.useSsl();
    }
    LettuceClientConfiguration clientConfiguration = builder.build();
    RedisStandaloneConfiguration standaloneConfig = new RedisStandaloneConfiguration();
    standaloneConfig.setHostName((String) redisHost().getObject());
    standaloneConfig.setPassword((String) redisPassword().getObject());
    standaloneConfig.setPort(Integer.parseInt((String) redisPort().getObject()));
    return new LettuceConnectionFactory(standaloneConfig, clientConfiguration);
}
Also used : LettuceClientConfiguration(org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration) LettuceConnectionFactory(org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory) RedisStandaloneConfiguration(org.springframework.data.redis.connection.RedisStandaloneConfiguration) LettuceClientConfigurationBuilder(org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration.LettuceClientConfigurationBuilder) ConfigurationPropertyFactoryBean(org.hisp.dhis.external.conf.ConfigurationPropertyFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 5 with RedisStandaloneConfiguration

use of org.springframework.data.redis.connection.RedisStandaloneConfiguration in project cas by apereo.

the class RedisObjectFactory method getStandaloneConfig.

private static RedisConfiguration getStandaloneConfig(final BaseRedisProperties redis) {
    LOGGER.debug("Setting Redis standalone configuration on host [{}] and port [{}]", redis.getHost(), redis.getPort());
    val standaloneConfig = new RedisStandaloneConfiguration(redis.getHost(), redis.getPort());
    standaloneConfig.setDatabase(redis.getDatabase());
    if (StringUtils.hasText(redis.getPassword())) {
        standaloneConfig.setPassword(RedisPassword.of(redis.getPassword()));
    }
    return standaloneConfig;
}
Also used : lombok.val(lombok.val) RedisStandaloneConfiguration(org.springframework.data.redis.connection.RedisStandaloneConfiguration)

Aggregations

RedisStandaloneConfiguration (org.springframework.data.redis.connection.RedisStandaloneConfiguration)7 JedisConnectionFactory (org.springframework.data.redis.connection.jedis.JedisConnectionFactory)3 LettuceConnectionFactory (org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory)3 LettuceClientConfigurationBuilder (org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration.LettuceClientConfigurationBuilder)2 LoadingCacheTest (com.alicp.jetcache.LoadingCacheTest)1 RefreshCacheTest (com.alicp.jetcache.RefreshCacheTest)1 AbstractExternalCacheTest (com.alicp.jetcache.test.external.AbstractExternalCacheTest)1 lombok.val (lombok.val)1 ConfigurationPropertyFactoryBean (org.hisp.dhis.external.conf.ConfigurationPropertyFactoryBean)1 Test (org.junit.Test)1 Statement (org.junit.runners.model.Statement)1 PooledServiceConnectorConfig (org.springframework.cloud.service.PooledServiceConnectorConfig)1 ServiceConnectorCreationException (org.springframework.cloud.service.ServiceConnectorCreationException)1 Bean (org.springframework.context.annotation.Bean)1 JedisClientConfiguration (org.springframework.data.redis.connection.jedis.JedisClientConfiguration)1 JedisClientConfigurationBuilder (org.springframework.data.redis.connection.jedis.JedisClientConfiguration.JedisClientConfigurationBuilder)1 LettuceClientConfiguration (org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration)1