public abstract class AbstractRedisService<K, V> implements IRedisService<K, V> { @Autowired private RedisTemplate<K, V> redisTemplate; public RedisTemplate<K, V> getRedisTemplate() { return redisTemplate; } public void setRedisTemplate(RedisTemplate<K, V> redisTemplate) { this.redisTemplate = redisTemplate; } @Override public void set(final K key, final V value, final long expiredTime) { BoundValueOperations<K, V> valueOper = redisTemplate.boundValueOps(key); if (expiredTime <= 0) { valueOper.set(value); } else { valueOper.set(value, expiredTime, TimeUnit.MILLISECONDS); } } @Override public V get(final K key) { BoundValueOperations<K, V> valueOper = redisTemplate.boundValueOps(key); return valueOper.get(); } @Override public Object getHash(K key, String name){ Object res = redisTemplate.boundHashOps(key).get(name); return res; } @Override public void del(K key) { if (redisTemplate.hasKey(key)) { redisTemplate.delete(key); } } }
SSH框架和Redis的整合
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:https://www.heiqu.com/1c1f9f47e937232377aa93201198c9de.html