Reids StringRedisTemplate List<>存储 取出

public Result queryByGet() throws IOException {
        String key = "cache:shopty:";
       ListOperations listOperations = stringRedisTemplate.opsForList();
       List<String> typeJson = stringRedisTemplate.opsForList().range(key,0,-1);
       // list range(0,-1) 取
       System.err.println(typeJson);
       if(!typeJson.isEmpty()){
           List<ShopType> typeList = new ArrayList<>();
           // 转换 List -> List
           for(String jsonString : typeJson){
               ShopType shopType = JSONUtil.toBean(jsonString,ShopType.class);
               typeList.add(shopType);
           }
           return Result.ok(typeList);
       }
        List<ShopType> typeList1 = query().orderByAsc("sort").list();
        if(typeList1 == null){
            return Result.fail("商户无");
        }
        List<String> strList = typeList1.stream()
                .map(JSONUtil::toJsonStr)
                .collect(Collectors.toList());
        //List -> List 存储
        listOperations.leftPushAll(key,strList);
        return Result.ok(typeList1);
    }

你可能感兴趣的:(list,redis)