|
|
@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; |
|
|
|
import org.springframework.data.redis.core.HashOperations; |
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import java.util.Collection; |
|
|
@ -30,6 +31,9 @@ public class RedisUtils { |
|
|
|
@Autowired |
|
|
|
private RedisTemplate<String, Object> redisTemplate; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private StringRedisTemplate stringRedisTemplate; |
|
|
|
|
|
|
|
/** |
|
|
|
* 默认过期时长为24小时,单位:秒 |
|
|
|
*/ |
|
|
@ -171,4 +175,39 @@ public class RedisUtils { |
|
|
|
return redisTemplate.opsForList().rightPop(key); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取String |
|
|
|
* @param key |
|
|
|
* @param expire |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public String getString(String key, long expire) { |
|
|
|
String value = stringRedisTemplate.opsForValue().get(key); |
|
|
|
if (expire != NOT_EXPIRE) { |
|
|
|
expire(key, expire); |
|
|
|
} |
|
|
|
return value; |
|
|
|
} |
|
|
|
|
|
|
|
public String getString(String key) { |
|
|
|
return getString(key, DEFAULT_EXPIRE); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 存储String |
|
|
|
* @param key |
|
|
|
* @param value |
|
|
|
* @param expire |
|
|
|
*/ |
|
|
|
public void setString(String key, String value, long expire) { |
|
|
|
stringRedisTemplate.opsForValue().set(key, value); |
|
|
|
if (expire != NOT_EXPIRE) { |
|
|
|
expire(key, expire); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void setString(String key, String value) { |
|
|
|
setString(key, value, DEFAULT_EXPIRE); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|