|
@@ -1,5 +1,6 @@
|
|
package cn.com.qmth.examcloud.app.service;
|
|
package cn.com.qmth.examcloud.app.service;
|
|
|
|
|
|
|
|
+import cn.com.qmth.examcloud.app.core.exception.ApiException;
|
|
import cn.com.qmth.examcloud.app.core.utils.JsonMapper;
|
|
import cn.com.qmth.examcloud.app.core.utils.JsonMapper;
|
|
import cn.com.qmth.examcloud.app.model.UserToken;
|
|
import cn.com.qmth.examcloud.app.model.UserToken;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
@@ -39,10 +40,16 @@ public class RedisService {
|
|
}
|
|
}
|
|
|
|
|
|
public void cacheUserToken(String key, UserToken value, long seconds) {
|
|
public void cacheUserToken(String key, UserToken value, long seconds) {
|
|
|
|
+ if (key == null) {
|
|
|
|
+ throw new ApiException("Key must be not null.");
|
|
|
|
+ }
|
|
this.set(REDIS_KEY_PREFIX + key, new JsonMapper().toJson(value), seconds);
|
|
this.set(REDIS_KEY_PREFIX + key, new JsonMapper().toJson(value), seconds);
|
|
}
|
|
}
|
|
|
|
|
|
public UserToken getUserToken(String key) {
|
|
public UserToken getUserToken(String key) {
|
|
|
|
+ if (key == null) {
|
|
|
|
+ throw new ApiException("Key must be not null.");
|
|
|
|
+ }
|
|
String value = this.get(REDIS_KEY_PREFIX + key);
|
|
String value = this.get(REDIS_KEY_PREFIX + key);
|
|
if (value != null) {
|
|
if (value != null) {
|
|
return new JsonMapper().fromJson(value, UserToken.class);
|
|
return new JsonMapper().fromJson(value, UserToken.class);
|