| | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * list 获取 |
| | | * list 获取索引下的值 |
| | | * |
| | | * @param key 键 |
| | | * @param index 索引 |
| | |
| | | public Object listGet(String key, long index) { |
| | | try { |
| | | return redisTemplate.opsForList().index(key,index); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * list 获取索引下的值 |
| | | * |
| | | * @param key 键 |
| | | * @param start 开始位置 0是开始位置 |
| | | * @param end 结束位置,-1返回所有 |
| | | * @return true成功 false 失败 |
| | | */ |
| | | public List<Object> listGetRange(String key, long start , long end) { |
| | | try { |
| | | return redisTemplate.opsForList().range(key, start, end); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @param key 键 |
| | | * @param value 值 |
| | | * @param timeOut 时间 |
| | | * @param unit 时间单位 |
| | | */ |
| | | public Boolean setIfAbsent(String key, Object value, long timeOut, TimeUnit unit) { |
| | | try { |
| | | return redisTemplate.opsForValue().setIfAbsent(key, value, timeOut, unit); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | } |