Search in sources :

Example 6 with JedisConnectionFactory

use of org.springframework.data.redis.connection.jedis.JedisConnectionFactory in project camel by apache.

the class RedisConfiguration method createDefaultConnectionFactory.

private RedisConnectionFactory createDefaultConnectionFactory() {
    JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
    managedConnectionFactory = true;
    if (host != null) {
        jedisConnectionFactory.setHostName(host);
    }
    if (port != null) {
        jedisConnectionFactory.setPort(port);
    }
    jedisConnectionFactory.afterPropertiesSet();
    connectionFactory = jedisConnectionFactory;
    return jedisConnectionFactory;
}
Also used : JedisConnectionFactory(org.springframework.data.redis.connection.jedis.JedisConnectionFactory)

Example 7 with JedisConnectionFactory

use of org.springframework.data.redis.connection.jedis.JedisConnectionFactory in project spring-cloud-connectors by spring-cloud.

the class RedisConnectionFactoryCreator method create.

@Override
public RedisConnectionFactory create(RedisServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) {
    if (hasClass(JEDIS_CLASS_NAME)) {
        RedisConnectionFactoryConfigurer configurer = new RedisConnectionFactoryConfigurer();
        JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
        connectionFactory.setHostName(serviceInfo.getHost());
        connectionFactory.setPort(serviceInfo.getPort());
        connectionFactory.setPassword(serviceInfo.getPassword());
        if (serviceConnectorConfig instanceof RedisConnectionFactoryConfig) {
            configurer.configure(connectionFactory, (RedisConnectionFactoryConfig) serviceConnectorConfig);
        } else {
            configurer.configure(connectionFactory, (PooledServiceConnectorConfig) serviceConnectorConfig);
        }
        connectionFactory.afterPropertiesSet();
        return connectionFactory;
    } else if (hasClass(LETTUCE_CLASS_NAME)) {
        RedisLettuceConnectionFactoryConfigurer configurer = new RedisLettuceConnectionFactoryConfigurer();
        LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory();
        connectionFactory.setHostName(serviceInfo.getHost());
        connectionFactory.setPort(serviceInfo.getPort());
        connectionFactory.setPassword(serviceInfo.getPassword());
        configurer.configure(connectionFactory, (RedisConnectionFactoryConfig) serviceConnectorConfig);
        connectionFactory.afterPropertiesSet();
        return connectionFactory;
    } else {
        throw new ServiceConnectorCreationException(String.format("Failed to create cloud Redis connection factory " + "for %s service. No client implementation classes " + " of jedis or lettuce clients implementation (%s, %s) not found", serviceInfo.getId(), JEDIS_CLASS_NAME, LETTUCE_CLASS_NAME));
    }
}
Also used : ServiceConnectorCreationException(org.springframework.cloud.service.ServiceConnectorCreationException) JedisConnectionFactory(org.springframework.data.redis.connection.jedis.JedisConnectionFactory) LettuceConnectionFactory(org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory)

Example 8 with JedisConnectionFactory

use of org.springframework.data.redis.connection.jedis.JedisConnectionFactory in project OpenClinica by OpenClinica.

the class DistributedSessionConfig method jedisConnectionFactory.

@Bean
public JedisConnectionFactory jedisConnectionFactory() throws Exception {
    String port = null;
    String host = null;
    String password = null;
    try {
        // Redis URL should be of the format redis://h:<PASSWORD>@<HOSTNAME>:<PORT>
        String redisUrl = environment.getProperty(REDIS_URL);
        port = redisUrl.substring(redisUrl.lastIndexOf(":") + 1, redisUrl.length());
        host = redisUrl.substring(redisUrl.lastIndexOf("@") + 1, redisUrl.lastIndexOf(":"));
        password = redisUrl.substring(redisUrl.indexOf("h:") + 2, redisUrl.lastIndexOf("@"));
        if (port == null || port.equals("") || host == null || host.equals("") || password == null || password.equals(""))
            throw new Exception();
    } catch (Exception e) {
        throw new Exception("Error:  REDIS_URL environment variable not defined or improperly formatted.");
    }
    JedisConnectionFactory jedisConnFactory = new JedisConnectionFactory();
    jedisConnFactory.setHostName(host);
    jedisConnFactory.setPort(Integer.valueOf(port));
    jedisConnFactory.setPassword(password);
    return jedisConnFactory;
}
Also used : JedisConnectionFactory(org.springframework.data.redis.connection.jedis.JedisConnectionFactory) Bean(org.springframework.context.annotation.Bean)

Aggregations

JedisConnectionFactory (org.springframework.data.redis.connection.jedis.JedisConnectionFactory)8 Before (org.junit.Before)2 Bean (org.springframework.context.annotation.Bean)2 JedisShardInfo (redis.clients.jedis.JedisShardInfo)2 RedisTicketRegistryProperties (org.apereo.cas.configuration.model.support.redis.RedisTicketRegistryProperties)1 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)1 ServiceConnectorCreationException (org.springframework.cloud.service.ServiceConnectorCreationException)1 LettuceConnectionFactory (org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory)1 JedisPoolConfig (redis.clients.jedis.JedisPoolConfig)1