1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
| @Service public class RedisUtil { @Autowired private RedisTemplate<String, Object> redisTemplate; public void set(String key, Object value, long time) { redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS); }
public void set(String key, Object value) { redisTemplate.opsForValue().set(key, value); }
public Object get(String key) { return redisTemplate.opsForValue().get(key); }
public Boolean del(String key) { return redisTemplate.delete(key); }
public Long del(List<String> keys) { return redisTemplate.delete(keys); }
public Boolean expire(String key, long time) { return redisTemplate.expire(key, time, TimeUnit.SECONDS); }
public Long getExpire(String key) { return redisTemplate.getExpire(key, TimeUnit.SECONDS); }
public Boolean hasKey(String key) { return redisTemplate.hasKey(key); }
public Long incr(String key, long delta) { return redisTemplate.opsForValue().increment(key, delta); }
public Long decr(String key, long delta) { return redisTemplate.opsForValue().increment(key, -delta); }
public Object hGet(String key, String hashKey) { return redisTemplate.opsForHash().get(key, hashKey); }
public Boolean hSet(String key, String hashKey, Object value, long time) { redisTemplate.opsForHash().put(key, hashKey, value); return expire(key, time); }
public void hSet(String key, String hashKey, Object value) { redisTemplate.opsForHash().put(key, hashKey, value); }
public Map<Object, Object> hGetAll(String key) { return redisTemplate.opsForHash().entries(key); }
public Boolean hSetAll(String key, Map<String, Object> map, long time) { redisTemplate.opsForHash().putAll(key, map); return expire(key, time); }
public void hSetAll(String key, Map<String, ?> map) { redisTemplate.opsForHash().putAll(key, map); }
public void hDel(String key, Object... hashKey) { redisTemplate.opsForHash().delete(key, hashKey); }
public Boolean hHasKey(String key, String hashKey) { return redisTemplate.opsForHash().hasKey(key, hashKey); }
public Long hIncr(String key, String hashKey, Long delta) { return redisTemplate.opsForHash().increment(key, hashKey, delta); }
public Long hDecr(String key, String hashKey, Long delta) { return redisTemplate.opsForHash().increment(key, hashKey, -delta); }
public Set<Object> sMembers(String key) { return redisTemplate.opsForSet().members(key); }
public Long sAdd(String key, Object... values) { return redisTemplate.opsForSet().add(key, values); }
public Long sAdd(String key, long time, Object... values) { Long count = redisTemplate.opsForSet().add(key, values); expire(key, time); return count; }
public Boolean sIsMember(String key, Object value) { return redisTemplate.opsForSet().isMember(key, value); }
public Long sSize(String key) { return redisTemplate.opsForSet().size(key); }
public Long sRemove(String key, Object... values) { return redisTemplate.opsForSet().remove(key, values); }
public List<Object> lRange(String key, long start, long end) { return redisTemplate.opsForList().range(key, start, end); }
public Long lSize(String key) { return redisTemplate.opsForList().size(key); }
public Object lIndex(String key, long index) { return redisTemplate.opsForList().index(key, index); }
public Long lPush(String key, Object value) { return redisTemplate.opsForList().rightPush(key, value); }
public Long lPush(String key, Object value, long time) { Long index = redisTemplate.opsForList().rightPush(key, value); expire(key, time); return index; }
public Long lPushAll(String key, Object... values) { return redisTemplate.opsForList().rightPushAll(key, values); }
public Long lPushAll(String key, Long time, Object... values) { Long count = redisTemplate.opsForList().rightPushAll(key, values); expire(key, time); return count; }
public Long lRemove(String key, long count, Object value) { return redisTemplate.opsForList().remove(key, count, value); } }
|