springboot redis切换db


    org.springframework.boot
    spring-boot-starter-redis
    1.3.8.RELEASE


#redis配置
spring:
    redis: 
        database=0
        host=127.0.0.1
        port=6379
        password=pwd
        timeout=0
        pool: 
            max-active=8
            max-idle=8
            max-wait=-1
            min-idle=0

 
@Autowired
private StringRedisTemplate stringRedisTemplate;

int db = 1;
JedisConnectionFactory jedisConnectionFactory = (JedisConnectionFactory) stringRedisTemplate.getConnectionFactory();
jedisConnectionFactory.setDatabase(db);
stringRedisTemplate.setConnectionFactory(jedisConnectionFactory);
ValueOperations valueOperations = stringRedisTemplate.opsForValue();

 

你可能感兴趣的:(编程,java)