fastJson&edis

2021-09-06 08:12

阅读:3524

标签:gif   用户体验   pid   image   技术   iba   查看   并发   直接   fastJson&redis 1. fastJson 1.1 依赖   com.alibaba fastjson 1.2.58       1.2 入门操作(相互之间转换)   @Test public void test() throws Exception{ Person zs = new Person(1L, "zs"); //单个对象--json对象 String jsonObj = JSONObject.toJSONString(zs); System.out.println(jsonObj); //集合---json数组 String jsonArray = JSONArray. toJSONString(Arrays.asList(zs, zs, new Person(2L, "ls"))); System.out.println(jsonArray); //json对象--单个对象 Person person = JSONObject.parseObject(jsonObj, Person.class); System.out.println(person); //json数组--集合 List persons = JSONArray.parseArray(jsonArray, Person.class); System.out.println(persons); } fastJson入门操作       2. Redis 2.1 使用缓存好处 1)减轻数据库压力 2)提高访问速度,增强用户体验 2.2 使用redis中央缓存集群的优点 1)主从复制-单主故障 2)哨兵模式-每个节点数据都是一样 3)redis-cluster: 单点故障,高并发,大量数据 2.3 缓存穿透、缓存击穿、缓存雪崩区别和解决方案 1)缓存穿透  描述:          缓存穿透是指缓存和数据库中都没有的数据,而用户不断发起请求,如发起为id为“-1”的数据或id为特别大不存在的数据。这时的用户很可能是攻击者,攻击会导致数据库压力过大。         解决方案:   接口层增加校验,如用户鉴权校验,id做基础校验,id


评论


亲,登录后才可以留言!