| | |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; |
| | | import org.springframework.data.redis.core.BoundSetOperations; |
| | | import org.springframework.data.redis.core.HashOperations; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | |
| | | @Autowired |
| | | public RedisTemplate redisTemplate; |
| | | |
| | | public RedisTemplate setDataBase(int num) { |
| | | LettuceConnectionFactory connectionFactory = (LettuceConnectionFactory) redisTemplate.getConnectionFactory(); |
| | | if (connectionFactory != null && num != connectionFactory.getDatabase()) { |
| | | connectionFactory.setDatabase(num); |
| | | this.redisTemplate.setConnectionFactory(connectionFactory); |
| | | connectionFactory.resetConnection(); |
| | | connectionFactory.afterPropertiesSet(); |
| | | } |
| | | return redisTemplate; |
| | | } |
| | | |
| | | /** |
| | | * 缓存基本的对象,Integer、String、实体类等 |
| | | * |