生成token存入redis
package com
.mayikt
.core
.token
;
import com
.mayikt
.core
.utils
.RedisUtil
;
import org
.apache
.commons
.lang3
.StringUtils
;
import org
.springframework
.beans
.factory
.annotation
.Autowired
;
import org
.springframework
.stereotype
.Component
;
import java
.util
.UUID
;
@Component
public class GenerateToken {
@Autowired
private RedisUtil redisUtil
;
public String
createToken(String keyPrefix
, String redisValue
) {
return createToken(keyPrefix
, redisValue
, null
);
}
public String
createToken(String keyPrefix
, String redisValue
, Long time
) {
if (StringUtils
.isEmpty(redisValue
)) {
new Exception("redisValue Not nul");
}
String token
= keyPrefix
+ UUID
.randomUUID().toString().replace("-", "");
redisUtil
.setString(token
, redisValue
, time
);
return token
;
}
public String
getToken(String token
) {
if (StringUtils
.isEmpty(token
)) {
return null
;
}
String value
= redisUtil
.getString(token
);
return value
;
}
public Boolean
removeToken(String token
) {
if (StringUtils
.isEmpty(token
)) {
return null
;
}
return redisUtil
.delKey(token
);
}
}
转载请注明原文地址: https://mac.8miu.com/read-491948.html