redis Set 类型操作工具类

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 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 get(Object key) {
        Set members = this.redisTemplate.opsForSet().members(key);
        List  strings = new ArrayList<>();
        for (Object object : members) {
            if(object instanceof  List){
                for (Object o : (List) object)
                {
                    strings.add(o);
                }
            }

        }
        return strings;

    }
   
} 
  

                            
                        
                    
                    
                    

你可能感兴趣的:(redis,数据库,缓存)