public SessionInfo getSessionInfo(String accessToken) { if (StringUtils.isBlank(accessToken)) { return null; } else { String redisKey = "accessToken:" + accessToken; if (this.redisUtil.hasKey(redisKey)) { SessionInfo sessionInfo = (SessionInfo)this.redisUtil.get(redisKey); sessionInfo.setExpireFreshTime(System.currentTimeMillis()); if (EquipmentTypeEnum.PC.getType().equals(sessionInfo.getEquipmentType())) { sessionInfo.setExpireMinute(this.timeout); this.redisUtil.set(redisKey, sessionInfo, this.timeout); } else { sessionInfo.setExpireMinute(this.appTimeout); this.redisUtil.set(redisKey, sessionInfo, this.appTimeout); } return sessionInfo; } else { return null; } } }中文讲解
时间: 2024-02-14 14:31:16 浏览: 110
这段代码是一个方法 `getSessionInfo`,它接受一个 `accessToken` 参数并返回一个 `SessionInfo` 对象。
首先,它会检查 `accessToken` 是否为空,如果为空,则返回 `null`。
如果 `accessToken` 不为空,则会生成一个 Redis 的键名 `redisKey`,格式为 `"accessToken:" + accessToken`。
接下来,它会检查 Redis 中是否存在该键名(即检查是否存在对应的 `accessToken` 的缓存)。如果存在,将从 Redis 中获取对应的 `SessionInfo` 对象,并更新其刷新时间(`expireFreshTime`)为当前时间戳。
然后,它会根据 `sessionInfo` 对象中的 `equipmentType` 属性判断设备类型。如果是 PC 设备类型(通过 `EquipmentTypeEnum.PC.getType().equals(sessionInfo.getEquipmentType())` 判断),将设置过期时间为 `timeout` 分钟,并将更新后的 `sessionInfo` 对象重新存入 Redis 中。如果是其他设备类型,则设置过期时间为 `appTimeout` 分钟,并将更新后的 `sessionInfo` 对象重新存入 Redis 中。
最后,如果 Redis 中不存在该键名,则返回 `null`。
总体来说,这段代码的作用是从 Redis 中获取指定 `accessToken` 对应的 `SessionInfo` 对象,并更新其缓存时间。如果缓存不存在,则返回 `null`。
阅读全文
相关推荐


















