堕落不振功业废,勤耕不辍日月新

Redis 与 fastjson 实现存储与读取

Redis hailen 75℃

1、数组 list

Redis 结合 fastjson 存储

List<Home> home = new ArrayList<Home>();
String key = "redisKey";
redisUtil.set(key, JSON.toJSONString(home));

Redis 结合 fastjson 读取

String key = "redisKey";    
Object value = redisUtil.get(key);  
List<Home> home =  JSON.parseArray((String)value, Home.class);

2、HashMap

Redis 结合 fastjson 存储

Map<Integer, List<ItemsToTemplate>> itemMap = new HashMap<Integer, List<ItemsToTemplate>>();
String key = "redisKey";
redisUtil.set(key, JSON.toJSONString(itemMap));

Redis 结合 fastjson 读取

String key = "redisKey";
String value = redisUtil.getStr(key);   
Map<Integer, List<ItemsToTemplate>> itemMap = JSON.parseObject(value,new TypeReference<Map<Integer,List<ItemsToTemplate>>>(){}.getType());
B3log  Redis  Java 

转载请注明:我是IT » Redis 与 fastjson 实现存储与读取

喜欢 (0)or分享 (0)