<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
<version>1.3.8.RELEASE</version>
</dependency>
#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();