Search in sources :

Example 26 with JedisPoolConfig

use of redis.clients.jedis.JedisPoolConfig in project cas by apereo.

the class RedisTicketRegistryConfiguration method jedisPoolConfig.

private JedisPoolConfig jedisPoolConfig() {
    final RedisTicketRegistryProperties redis = casProperties.getTicket().getRegistry().getRedis();
    final JedisPoolConfig config = new JedisPoolConfig();
    final RedisTicketRegistryProperties.Pool props = redis.getPool();
    config.setMaxTotal(props.getMaxActive());
    config.setMaxIdle(props.getMaxIdle());
    config.setMinIdle(props.getMinIdle());
    config.setMaxWaitMillis(props.getMaxWait());
    return config;
}
Also used : RedisTicketRegistryProperties(org.apereo.cas.configuration.model.support.redis.RedisTicketRegistryProperties) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig)

Example 27 with JedisPoolConfig

use of redis.clients.jedis.JedisPoolConfig in project cas by apereo.

the class RedisTicketRegistryConfiguration method redisConnectionFactory.

@Bean
@RefreshScope
public RedisConnectionFactory redisConnectionFactory() {
    final RedisTicketRegistryProperties redis = casProperties.getTicket().getRegistry().getRedis();
    final JedisPoolConfig poolConfig = redis.getPool() != null ? jedisPoolConfig() : new JedisPoolConfig();
    final JedisConnectionFactory factory = new JedisConnectionFactory(poolConfig);
    factory.setHostName(redis.getHost());
    factory.setPort(redis.getPort());
    if (redis.getPassword() != null) {
        factory.setPassword(redis.getPassword());
    }
    factory.setDatabase(redis.getDatabase());
    if (redis.getTimeout() > 0) {
        factory.setTimeout(redis.getTimeout());
    }
    return factory;
}
Also used : RedisTicketRegistryProperties(org.apereo.cas.configuration.model.support.redis.RedisTicketRegistryProperties) JedisConnectionFactory(org.springframework.data.redis.connection.jedis.JedisConnectionFactory) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Bean(org.springframework.context.annotation.Bean)

Example 28 with JedisPoolConfig

use of redis.clients.jedis.JedisPoolConfig in project cachecloud by sohutv.

the class JedisPoolTest method testCloseConnectionOnMakeObject.

@Test
public void testCloseConnectionOnMakeObject() {
    JedisPoolConfig config = new JedisPoolConfig();
    config.setTestOnBorrow(true);
    JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000, "wrong pass");
    Jedis jedis = new Jedis("redis://:foobared@localhost:6379/");
    int currentClientCount = getClientCount(jedis.clientList());
    try {
        pool.getResource();
        fail("Should throw exception as password is incorrect.");
    } catch (Exception e) {
        assertEquals(currentClientCount, getClientCount(jedis.clientList()));
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) URISyntaxException(java.net.URISyntaxException) JedisException(redis.clients.jedis.exceptions.JedisException) InvalidURIException(redis.clients.jedis.exceptions.InvalidURIException) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException) Test(org.junit.Test)

Example 29 with JedisPoolConfig

use of redis.clients.jedis.JedisPoolConfig in project cachecloud by sohutv.

the class JedisPoolTest method checkConnectionWithDefaultPort.

@Test
public void checkConnectionWithDefaultPort() {
    JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort());
    Jedis jedis = pool.getResource();
    jedis.auth("foobared");
    jedis.set("foo", "bar");
    assertEquals("bar", jedis.get("foo"));
    jedis.close();
    pool.destroy();
    assertTrue(pool.isClosed());
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) Test(org.junit.Test)

Example 30 with JedisPoolConfig

use of redis.clients.jedis.JedisPoolConfig in project spring-cloud-connectors by spring-cloud.

the class RedisConnectionFactoryConfigurer method configurePool.

private void configurePool(JedisConnectionFactory connectionFactory, PooledServiceConnectorConfig config) {
    if (config.getPoolConfig() != null) {
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        BeanWrapper target = new BeanWrapperImpl(poolConfig);
        BeanWrapper source = new BeanWrapperImpl(config.getPoolConfig());
        Util.setCorrespondingProperties(target, source);
        connectionFactory.setPoolConfig(poolConfig);
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig)

Aggregations

JedisPoolConfig (redis.clients.jedis.JedisPoolConfig)43 JedisPool (redis.clients.jedis.JedisPool)35 Test (org.junit.Test)30 Jedis (redis.clients.jedis.Jedis)28 HostAndPort (redis.clients.jedis.HostAndPort)6 JedisCluster (redis.clients.jedis.JedisCluster)6 LinkedHashSet (java.util.LinkedHashSet)4 HashSet (java.util.HashSet)3 URISyntaxException (java.net.URISyntaxException)2 RedisTicketRegistryProperties (org.apereo.cas.configuration.model.support.redis.RedisTicketRegistryProperties)2 Before (org.junit.Before)2 InvalidURIException (redis.clients.jedis.exceptions.InvalidURIException)2 JedisException (redis.clients.jedis.exceptions.JedisException)2 BeanWrapper (org.springframework.beans.BeanWrapper)1 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)1 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)1 Bean (org.springframework.context.annotation.Bean)1 JedisConnectionFactory (org.springframework.data.redis.connection.jedis.JedisConnectionFactory)1 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)1 JedisExhaustedPoolException (redis.clients.jedis.exceptions.JedisExhaustedPoolException)1