|
|
@@ -1,71 +0,0 @@ |
|
|
|
package cn.com.taiji.settlew.tools; |
|
|
|
|
|
|
|
import cn.com.taiji.common.manager.AbstractManager; |
|
|
|
import cn.com.taiji.core.manager.cache.RedisManager; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.data.redis.core.HashOperations; |
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
/** |
|
|
|
* hash操作的方法以hash开头,如:hashGet<br> |
|
|
|
* |
|
|
|
* @author lijun <br> |
|
|
|
* Create Time:2018年12月9日 下午1:43:54<br> |
|
|
|
* mail:756915505@qq.com |
|
|
|
* @since 1.0 |
|
|
|
* @version 1.0 |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
public class RedisWrapManager extends AbstractManager implements RedisManager { |
|
|
|
|
|
|
|
@Autowired(required = false) |
|
|
|
private RedisTemplate<String, String> redisTemplate; |
|
|
|
|
|
|
|
public Boolean expire(String key, final long timeout, final TimeUnit unit) { |
|
|
|
return redisTemplate.expire(key, timeout, unit); |
|
|
|
} |
|
|
|
|
|
|
|
public Boolean hasKey(String key) { |
|
|
|
return redisTemplate.hasKey(key); |
|
|
|
} |
|
|
|
|
|
|
|
public String get(String key) { |
|
|
|
return redisTemplate.opsForValue().get(key); |
|
|
|
} |
|
|
|
|
|
|
|
public String getAndSet(String key, String value) { |
|
|
|
return redisTemplate.opsForValue().getAndSet(key, value); |
|
|
|
} |
|
|
|
|
|
|
|
public void set(String key, String value, long timeout, TimeUnit unit) { |
|
|
|
redisTemplate.opsForValue().set(key, value, timeout, unit); |
|
|
|
} |
|
|
|
/** |
|
|
|
* 往redis中存入数据 默认为不过期 |
|
|
|
* |
|
|
|
* @param key key |
|
|
|
* @param value value |
|
|
|
*/ |
|
|
|
public void setDefault(String key, String value) { |
|
|
|
redisTemplate.opsForValue().set(key, value); |
|
|
|
} |
|
|
|
|
|
|
|
public boolean setIfAbsent(String key, String value, long timeout, TimeUnit unit) { |
|
|
|
return redisTemplate.opsForValue().setIfAbsent(key, value, timeout, unit); |
|
|
|
} |
|
|
|
|
|
|
|
public Boolean delete(String key) { |
|
|
|
return redisTemplate.delete(key); |
|
|
|
} |
|
|
|
|
|
|
|
private <HK, HV> HashOperations<String, HK, HV> opsForHash() { |
|
|
|
return redisTemplate.opsForHash(); |
|
|
|
} |
|
|
|
|
|
|
|
private void set(String key, String value, int timeout) { |
|
|
|
redisTemplate.opsForValue().set(key, value, timeout, TimeUnit.SECONDS); |
|
|
|
} |
|
|
|
} |