public class RedisSetUtils {
@Autowired(required = true)
private RedisTemplate redisTemplate;
/**
* 是否包含
*
* @param key
* @return
*/
public Boolean hasKey(Object key) {
return this.redisTemplate.hasKey(key);
}
/**
* 添加记录
*
* @param key
* @param stringList
* @return
*/
public void add(Object key, List<String> stringList) {
this.redisTemplate.opsForSet().add(key, stringList);
//过期时间10分钟
this.redisTemplate.expire(key, RedisKeyConstant.RANGE_REDIS_EXPIRE_TIME, TimeUnit.MINUTES);
}
/**
* 删除
*
* @param key
* @return
*/
public void remove(Object key) {
this.redisTemplate.delete(key);
}
/**
* 获取记录
*
* @param key
* @return
*/
public List<Object> get(Object key) {
Set<Object> members = this.redisTemplate.opsForSet().members(key);
List<Object > strings = new ArrayList<>();
for (Object object : members) {
if(object instanceof List){
for (Object o : (List<?>) object)
{
strings.add(o);
}
}
}
return strings;
}
}
06-27
3040
08-19
1095
08-10
732