JdkSerializationRedisSerializer、GenericJackson2JsonRedisSerializer、Jackson2JsonRedisSerializer序列化效率

发布时间:2020-05-09 18:57:07 作者:Mos 阅读量:16130

RedisTemplate序列化工具效率对比:

1.JdkSerializationRedisSerializer

2.GenericJackson2JsonRedisSerializer

3.Jackson2JsonRedisSerializer

测试代码片段:


@Test
public void test7(){
  Page<SysMessageEvent> page = sysMessageEventDao.findAll(Pages.Helper.pageable(1, 200, null));
  List<SysMessageEvent> list = page.getContent();
  JdkSerializationRedisSerializer j = new JdkSerializationRedisSerializer();
  GenericJackson2JsonRedisSerializer g = new GenericJackson2JsonRedisSerializer();
  Jackson2JsonRedisSerializer j2 = new Jackson2JsonRedisSerializer(List.class);
  TimeTest tt = new TimeTest();
  tt.setStartTime();
  byte[] bytesJ = j.serialize(list);
  tt.setEndTime();
  System.out.println("JdkSerializationRedisSerializer序列化时间:"+tt.getExcuteTime() + "ms,序列化后的长度:" + bytesJ.length);
  tt.setStartTime();
  j.deserialize(bytesJ);
  tt.setEndTime();
  System.out.println("JdkSerializationRedisSerializer反序列化时间:"+tt.getExcuteTime());
  tt.setStartTime();
  byte[] bytesG = g.serialize(list);
  tt.setEndTime();
  System.out.println("GenericJackson2JsonRedisSerializer序列化时间:"+tt.getExcuteTime() + "ms,序列化后的长度:" + bytesG.length);
  tt.setStartTime();
  g.deserialize(bytesG);
  tt.setEndTime();
  System.out.println("GenericJackson2JsonRedisSerializer反序列化时间:"+tt.getExcuteTime());
  tt.setStartTime();
  byte[] bytesJ2 = j2.serialize(list);
  tt.setEndTime();
  System.out.println("Jackson2JsonRedisSerializer序列化时间:"+tt.getExcuteTime() + "ms,序列化后的长度:" + bytesJ2.length);
  tt.setStartTime();
  j2.deserialize(bytesJ2);
  tt.setEndTime();
  System.out.println("Jackson2JsonRedisSerializer反序列化时间:"+tt.getExcuteTime());
}

测试数据(总共200条记录的List集合),单条类似:


{"channel":"USER_LOGIN@30-9C-23-83-D0-9C","createTime":1526973952000,"doneHost":"192.168.80.10:62016","doneServer":"he-pm","doneTime":1526973952000,"eventInfoJson":"{\"userName\":\"Mos.Jiang\",\"targetId\":\"250524c0-8869-4fc2-a4aa-278a5a5b3197\",\"localId\":\"250524c0-8869-4fc2-a4aa-278a5a5b3197\",\"first\":\"您好,您账号已经登录\",\"keyword1\":\"2018年05月22日 15:25\",\"keyword2\":\"127.0.0.1\",\"remark\":\"如果本次登录不是您本人所为,说明您的帐号已经被盗!为减少您的损失,请立即联系客服 4008271580。\"}","hasDone":1,"id":"006bdac0-0ba0-498d-b654-28fa6038f747","sendCount":1,"sendTime":1526973952000,"senderInfo":"com.mj.he800.pm.service.user.UserBaseInfoService#userLogin-215"}


测试结果:

JdkSerializationRedisSerializer序列化时间:11,序列化后的长度:94551,反序列化时间:15
GenericJackson2JsonRedisSerializer序列化时间:18,序列化后的长度:151108,反序列化时间:14
Jackson2JsonRedisSerializer序列化时间:5,序列化后的长度:125489,反序列化时间:3

简单地可以看出:Jackson2JsonRedisSerializer序列化和反序列化效率高,JdkSerializationRedisSerializer序列化后的结果最短

转载请注明出处:文思齐远博客,如果对您有帮助,请帮忙点一下右侧的广告,谢谢您了!
支付宝打赏 微信打赏

我要评论

猜你想搜

实时天气

©2020 i847.cn
部分内容转自网络,如有损害您的权益,致邮联系:jiang2008wen#126.com,一经证实,立即删除!    我要留言
备案号:蜀ICP备18020563号-1