缓存的概念



public Users getByUsers(Long id) {// 1.先查询redisString key = this.getClass().getName() + "-" + Thread.currentThread().getStackTrace()[1].getMethodName()+ "-id:" + id;String userJson = redisService.getString(key);if (!StringUtils.isEmpty(userJson)) {Users users = JSONObject.parseObject(userJson, Users.class);return users;}Users user = null;try {lock.lock();// 查询dbuser = userMapper.getUser(id);redisService.setSet(key, JSONObject.toJSONString(user));} catch (Exception e) {} finally {lock.unlock(); // 释放锁}return user;}
文章转载自东神殿下,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




