Java Code Examples for org.springframework.data.redis.connection.jedis.JedisConnectionFactory#setDatabase()

The following examples show how to use org.springframework.data.redis.connection.jedis.JedisConnectionFactory#setDatabase() . 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
Source File: RedisConfig.java    From demo-project with MIT License 6 votes vote down vote up
@Bean
public JedisConnectionFactory jedisConnectionFactory() {
    logger.info("jedisConnectionFactory:初始化了");
    JedisPoolConfig config = new JedisPoolConfig();
    config.setMaxIdle(maxIdle);
    config.setMinIdle(minIdle);
    config.setMaxWaitMillis(maxWaitMillis);
    config.setMaxTotal(maxActive);
    //链接耗尽时是否阻塞,默认true
    config.setBlockWhenExhausted(true);
    //是否启用pool的jmx管理功能,默认true
    config.setJmxEnabled(true);
    JedisConnectionFactory factory = new JedisConnectionFactory();
    factory.setPoolConfig(config);
    factory.setHostName(host);
    factory.setPort(port);
    factory.setPassword(password);
    factory.setDatabase(database);
    factory.setTimeout(timeout);
    return factory;
}
 
Example 2
Source File: RedisConfig.java    From Resource with GNU General Public License v3.0 5 votes vote down vote up
@Bean
public RedisConnectionFactory redisConnectionFactory()
{
    JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
    JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
    jedisConnectionFactory.setHostName(env.getProperty("redis.host").trim());
    jedisConnectionFactory.setPort(Integer.parseInt(env.getProperty("redis.port").trim()));
    jedisConnectionFactory.setPassword(env.getProperty("redis.password").trim());
    jedisConnectionFactory.setDatabase(Integer.parseInt(env.getProperty("redis.database").trim()));
    jedisConnectionFactory.setUsePool(true);
    jedisConnectionFactory.setPoolConfig(jedisPoolConfig);
    return jedisConnectionFactory;
}
 
Example 3
Source File: CacheService.java    From springboot-learn with MIT License 5 votes vote down vote up
/**
 * redis 数据库连接池
 *
 * @return
 */

@Bean
public JedisConnectionFactory redisConnectionFactory() {
    JedisConnectionFactory factory = new JedisConnectionFactory();
    factory.setHostName(redisConn.getHost());
    factory.setPort(redisConn.getPort());
    factory.setPassword(redisConn.getPassword());
    factory.setTimeout(redisConn.getTimeout()); // 设置连接超时时间
    factory.setDatabase(redisConn.getDatabase());
    return factory;
}
 
Example 4
Source File: RedisConfiguration.java    From spring-boot-with-multi-redis with MIT License 5 votes vote down vote up
@Primary
@Bean(name = "userRedisConnectionFactory")
public RedisConnectionFactory userRedisConnectionFactory() {
    JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
    redisConnectionFactory.setHostName(userRedisProperty.getHost());
    redisConnectionFactory.setPort(userRedisProperty.getPort());
    redisConnectionFactory.setDatabase(userRedisProperty.getDatabase());
    return redisConnectionFactory;
}
 
Example 5
Source File: RedisConfiguration.java    From spring-boot-with-multi-redis with MIT License 5 votes vote down vote up
@Bean(name = "roleRedisConnectionFactory")
public RedisConnectionFactory roleRedisConnectionFactory() {
    JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
    redisConnectionFactory.setHostName(roleRedisProperty.getHost());
    redisConnectionFactory.setPort(roleRedisProperty.getPort());
    redisConnectionFactory.setDatabase(roleRedisProperty.getDatabase());
    return redisConnectionFactory;
}
 
Example 6
Source File: RedisConfiguration.java    From WTFDYUM with Apache License 2.0 5 votes vote down vote up
@Bean
public RedisConnectionFactory redisConnectionFactory() {
    final JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
    jedisConnectionFactory.setHostName(env.getProperty("wtfdyum.redis.server"));
    jedisConnectionFactory.setPort(env.getProperty("wtfdyum.redis.port", Integer.class));
    jedisConnectionFactory.setDatabase(env.getProperty("wtfdyum.redis.database", Integer.class));
    return jedisConnectionFactory;
}
 
Example 7
Source File: RedisUtil.java    From spring_boot with Apache License 2.0 4 votes vote down vote up
public static RedisTemplate getSelect_0(){
    JedisConnectionFactory connectionFactory = (JedisConnectionFactory) redisTemplate.getConnectionFactory();
    connectionFactory.setDatabase(0);
    redisTemplate.setConnectionFactory(connectionFactory);
    return redisTemplate;
}
 
Example 8
Source File: RedisUtil.java    From spring_boot with Apache License 2.0 4 votes vote down vote up
public static RedisTemplate getSelect_1(){
    JedisConnectionFactory connectionFactory = (JedisConnectionFactory) redisTemplate.getConnectionFactory();
    connectionFactory.setDatabase(1);
    redisTemplate.setConnectionFactory(connectionFactory);
    return redisTemplate;
}