Java使用redis存取集合对象

List

使用Java存取List对象,将list转为json对象进行存取

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
 
 
  @Autowired
    private StringRedisTemplate stringRedisTemplate;
 
//存
List<Long> businessIdList = eeFreecarriageShopService.selectBusinessIdInPromotion();
 stringRedisTemplate.opsForValue().set(RedisConstants.FREECARRIAGE_BUSINESSIDLIST, JSON.toJSON(businessIdList).toString());
 
//取
String businessJsonArray = stringRedisTemplate.opsForValue().get(RedisConstants.FREECARRIAGE_BUSINESSIDLIST);
List<Long> businessIdList = JSONObject.parseArray(businessJsonArray, Long.class);
原文地址:https://www.cnblogs.com/hnxbp/p/14925422.html