Java Code Examples for org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration

The following examples show how to use org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public LettuceConnectionFactory createFactory(ClientResources clientResources) {
    LettuceClientConfiguration clientConfig = getLettuceClientConfiguration(clientResources,
        this.properties.getLettuce().getPool());
    LettuceConnectionFactory factory = createLettuceConnectionFactory(clientConfig);
    factory.afterPropertiesSet();
    return factory;
}
 
Example 2
private LettuceConnectionFactory createLettuceConnectionFactory(LettuceClientConfiguration clientConfiguration) {
    if (getSentinelConfig() != null) {
        return new LettuceConnectionFactory(getSentinelConfig(), clientConfiguration);
    }
    if (getClusterConfiguration() != null) {
        return new LettuceConnectionFactory(getClusterConfiguration(), clientConfiguration);
    }
    return new LettuceConnectionFactory(getStandaloneConfig(), clientConfiguration);
}
 
Example 3
private LettuceClientConfiguration getLettuceClientConfiguration(ClientResources clientResources,
                                                                 Pool pool) {
    LettuceClientConfigurationBuilder builder = createBuilder(pool);
    applyProperties(builder);
    if (StringUtils.hasText(this.properties.getUrl())) {
        customizeConfigurationFromUrl(builder);
    }
    builder.clientResources(clientResources);
    return builder.build();
}
 
Example 4
Source Project: unimall   Source File: RedisAutoConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**** 缓存专用数据源 ****/
@Bean
public LettuceConnectionFactory defaultLettuceConnectionFactory(
        RedisStandaloneConfiguration defaultRedisConfig,GenericObjectPoolConfig defaultPoolConfig) {
    LettuceClientConfiguration clientConfig =
            LettucePoolingClientConfiguration.builder().commandTimeout(Duration.ofMillis(5000))
                    .poolConfig(defaultPoolConfig).build();
    return new LettuceConnectionFactory(defaultRedisConfig, clientConfig);
}
 
Example 5
Source Project: unimall   Source File: RedisAutoConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**** 用户SESSION专用数据源 ****/
@Bean
public LettuceConnectionFactory userLettuceConnectionFactory(
        RedisStandaloneConfiguration userRedisConfig,GenericObjectPoolConfig userPoolConfig) {
    LettuceClientConfiguration clientConfig =
            LettucePoolingClientConfiguration.builder().commandTimeout(Duration.ofMillis(5000))
                    .poolConfig(userPoolConfig).build();
    return new LettuceConnectionFactory(userRedisConfig, clientConfig);
}
 
Example 6
Source Project: unimall   Source File: RedisAutoConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**** 锁专用数据源 ****/
@Bean
public LettuceConnectionFactory lockLettuceConnectionFactory(
        RedisStandaloneConfiguration lockRedisConfig,GenericObjectPoolConfig lockPoolConfig) {
    LettuceClientConfiguration clientConfig =
            LettucePoolingClientConfiguration.builder().commandTimeout(Duration.ofMillis(5000))
                    .poolConfig(lockPoolConfig).build();
    return new LettuceConnectionFactory(lockRedisConfig, clientConfig);
}
 
Example 7
Source Project: soul   Source File: RateLimiterPluginDataHandler.java    License: Apache License 2.0 5 votes vote down vote up
private LettuceConnectionFactory createLettuceConnectionFactory(final RateLimiterConfig rateLimiterConfig) {
    LettuceClientConfiguration lettuceClientConfiguration = getLettuceClientConfiguration(rateLimiterConfig);
    if (RedisModeEnum.SENTINEL.getName().equals(rateLimiterConfig.getMode())) {
        return new LettuceConnectionFactory(redisSentinelConfiguration(rateLimiterConfig), lettuceClientConfiguration);
    } else if (RedisModeEnum.CLUSTER.getName().equals(rateLimiterConfig.getMode())) {
        return new LettuceConnectionFactory(redisClusterConfiguration(rateLimiterConfig), lettuceClientConfiguration);
    }
    return new LettuceConnectionFactory(redisStandaloneConfiguration(rateLimiterConfig), lettuceClientConfiguration);
}
 
Example 8
@Bean
public LettuceConnectionFactory lettuceConnectionFactory()
{
    LettuceClientConfigurationBuilder builder = LettuceClientConfiguration.builder();
    if(Boolean.parseBoolean( (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 );
}
 
Example 9
@Bean
@Primary
public LettuceConnectionFactory factoryA(GenericObjectPoolConfig config, RedisStandaloneConfiguration redisConfigA) {
    LettuceClientConfiguration clientConfiguration = LettucePoolingClientConfiguration.builder()
            .poolConfig(config).commandTimeout(Duration.ofMillis(config.getMaxWaitMillis())).build();
    return new LettuceConnectionFactory(redisConfigA, clientConfiguration);
}
 
Example 10
public static void assertNoPoolProperties(RedisConnectionFactory connector) {
	if (connector instanceof JedisConnectionFactory) {
		assertFalse(((JedisConnectionFactory) connector).getUsePool());
	} else if (connector instanceof LettuceConnectionFactory) {
		LettuceClientConfiguration config = ((LettuceConnectionFactory) connector).getClientConfiguration();
		assertThat(config, instanceOf(LettuceClientConfiguration.class));
	}
}
 
Example 11
public static void assertPoolProperties(RedisConnectionFactory connector, int maxActive, int minIdle, long maxWait) {
	GenericObjectPoolConfig poolConfig = null;
	if (connector instanceof JedisConnectionFactory) {
		poolConfig = ((JedisConnectionFactory) connector).getPoolConfig();
	} else if (connector instanceof LettuceConnectionFactory) {
		LettuceClientConfiguration config = ((LettuceConnectionFactory) connector).getClientConfiguration();
		assertThat(config, instanceOf(LettucePoolingClientConfiguration.class));
		poolConfig = ((LettucePoolingClientConfiguration) config).getPoolConfig();
	}
	assertCommonsPoolProperties(poolConfig, maxActive, minIdle, maxWait);
}
 
Example 12
private LettuceClientConfigurationBuilder createBuilder(Pool pool) {
    if (pool == null) {
        return LettuceClientConfiguration.builder();
    }
    return new PoolBuilderFactory().createBuilder(pool);
}
 
Example 13
Source Project: soul   Source File: RateLimiterPluginDataHandler.java    License: Apache License 2.0 4 votes vote down vote up
private LettuceClientConfiguration getLettuceClientConfiguration(final RateLimiterConfig rateLimiterConfig) {
    return LettucePoolingClientConfiguration.builder().poolConfig(getPoolConfig(rateLimiterConfig)).build();
}
 
Example 14
@Bean
public LettuceConnectionFactory factoryB(GenericObjectPoolConfig config, RedisStandaloneConfiguration redisConfigB) {
    LettuceClientConfiguration clientConfiguration = LettucePoolingClientConfiguration.builder()
            .poolConfig(config).commandTimeout(Duration.ofMillis(config.getMaxWaitMillis())).build();
    return new LettuceConnectionFactory(redisConfigB, clientConfiguration);
}
 
Example 15
public @Bean RedisConnectionFactory connectionFactory() {
	return new LettuceConnectionFactory(sentinelConfig(), LettuceClientConfiguration.defaultConfiguration());
}