| | |
| | | } |
| | | |
| | | /** |
| | | * 缓存List数据 |
| | | * |
| | | * @param key 缓存的键值 |
| | | * @param dataList 待缓存的List数据 |
| | | * @return 缓存的对象 |
| | | */ |
| | | public <T> ListOperations<String, T> setCacheList(String key, List<T> dataList) { |
| | | ListOperations listOperation = redisTemplate.opsForList(); |
| | | if (null != dataList) { |
| | | int size = dataList.size(); |
| | | for (int i = 0; i < size; i++) { |
| | | listOperation.leftPush(key, dataList.get(i)); |
| | | } |
| | | * 缓存List数据,并设置过期时间 |
| | | * |
| | | * @param key 缓存的键值 |
| | | * @param dataList 待缓存的List数据 |
| | | * @param timeout 过期时间 |
| | | * @param timeUnit 时间单位 |
| | | * @return 缓存的对象 |
| | | */ |
| | | public <T> ListOperations<String, T> setCacheList(String key, List<T> dataList, Integer timeout, TimeUnit timeUnit) { |
| | | ListOperations listOperation = redisTemplate.opsForList(); |
| | | if (null != dataList) { |
| | | int size = dataList.size(); |
| | | for (int i = 0; i < size; i++) { |
| | | listOperation.leftPush(key, dataList.get(i)); |
| | | } |
| | | return listOperation; |
| | | } |
| | | // 设置过期时间 |
| | | if (timeout > 0) { |
| | | redisTemplate.expire(key, timeout, timeUnit); |
| | | } |
| | | return listOperation; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获得缓存的list对象 |