private LoginResponse redisCacheResponse() { String sessionId = "LOGINRESPONSESESSIONID"; LoginResponse loginResponse = (LoginResponse) redisTemplate.opsForValue().get(sessionId); if (ObjectUtil.isNull(loginResponse)) { loginResponse = azkabanApi.login(); String status = loginResponse.getStatus(); redisTemplate.opsForValue().set(sessionId, loginResponse,1,TimeUnit.DAYS); redisTemplate.opsForValue().set("LOGINRESPONSSTATUS", status,1,TimeUnit.DAYS); return loginResponse; } loginResponse.setStatus((String) redisTemplate.opsForValue().get("LOGINRESPONSSTATUS")); return loginResponse; }
这是存储登录的sessionid和status,存储于redis,避免再次调用login接口,时长一天。
keys * 查看所有
flushall 清楚所有,详细百度redis教程