org.yes.tools.pay.redis.RedisTemplateRedisOps Maven / Gradle / Ivy
package org.yes.tools.pay.redis;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.StringRedisTemplate;
import java.util.concurrent.TimeUnit;
@RequiredArgsConstructor
public class RedisTemplateRedisOps implements RedisOps {
private final StringRedisTemplate redisTemplate;
@Override
public String getValue(String key) {
return redisTemplate.opsForValue().get(key);
}
@Override
public void setValue(String key, String value, int expire, TimeUnit timeUnit) {
if (expire <= 0) {
redisTemplate.opsForValue().set(key, value);
} else {
redisTemplate.opsForValue().set(key, value, expire, timeUnit);
}
}
@Override
public Long getExpire(String key) {
return redisTemplate.getExpire(key);
}
@Override
public Boolean exists(String key) {
try {
return redisTemplate.hasKey(key);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}