redis存储list
把List转换成JSON,存储到Redis,取出来的时候,再把JSON转换成List。
User user = new User(); user.setId(123); user.setName("fighter"); User user1 = new User(); user1.setId(1232); user1.setName("ssss"); List list = new ArrayList(); list.add(user); list.add(user1); String json=JSONObject.toJSONString(list); System.out.println(json); redisService.set("user",json); String username = redisService.get("user"); List newList=JSONObject.parseArray(username, User.class); System.out.println(newList.size());
其中用到阿里的fastjson,maven的pom:
<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.4</version> </dependency>
相关推荐
王道革 2020-11-25
wangdonghello 2020-11-03
Langeldep 2020-11-16
chenhualong0 2020-11-16
聚合室 2020-11-16
koushr 2020-11-12
MRFENGG 2020-11-11
guoyanga 2020-11-10
fackyou00 2020-11-10
Orangesss 2020-11-03
dongCSDN 2020-10-31
rainandtear 2020-10-30
Quietboy 2020-10-30
liuyulong 2020-10-29
fansili 2020-10-29
温攀峰 2020-10-23
jackbon 2020-10-19
kaixinfelix 2020-10-04