mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-06-15 17:57:07 +00:00
fix:RedisUtils相关修改
This commit is contained in:
@@ -15,7 +15,8 @@ import java.util.Objects;
|
|||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class RedisConfig {
|
public class RedisConfig {
|
||||||
@Bean
|
|
||||||
|
@Bean("myRedisTemplate")
|
||||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
||||||
// 创建模板
|
// 创建模板
|
||||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||||
@@ -30,10 +31,11 @@ public class RedisConfig {
|
|||||||
// value和 hashValue采用 JSON序列化
|
// value和 hashValue采用 JSON序列化
|
||||||
redisTemplate.setValueSerializer(jsonRedisSerializer);
|
redisTemplate.setValueSerializer(jsonRedisSerializer);
|
||||||
redisTemplate.setHashValueSerializer(jsonRedisSerializer);
|
redisTemplate.setHashValueSerializer(jsonRedisSerializer);
|
||||||
|
redisTemplate.afterPropertiesSet();
|
||||||
return redisTemplate;
|
return redisTemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MyRedisSerializerCustomized extends GenericJackson2JsonRedisSerializer {
|
private static class MyRedisSerializerCustomized extends GenericJackson2JsonRedisSerializer {
|
||||||
@Override
|
@Override
|
||||||
public byte[] serialize(Object source) throws SerializationException {
|
public byte[] serialize(Object source) throws SerializationException {
|
||||||
if (Objects.nonNull(source)) {
|
if (Objects.nonNull(source)) {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class CursorUtils {
|
|||||||
.map(String::valueOf)
|
.map(String::valueOf)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
Boolean isLast = result.size() != cursorPageBaseReq.getPageSize();
|
Boolean isLast = result.size() != cursorPageBaseReq.getPageSize();
|
||||||
return new CursorPageBaseResp(cursor, isLast, result);
|
return new CursorPageBaseResp<>(cursor, isLast, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> CursorPageBaseResp<T> getCursorPageByMysql(IService<T> mapper, CursorPageBaseReq request, Consumer<LambdaQueryWrapper<T>> initWrapper, SFunction<T, ?> cursorColumn) {
|
public <T> CursorPageBaseResp<T> getCursorPageByMysql(IService<T> mapper, CursorPageBaseReq request, Consumer<LambdaQueryWrapper<T>> initWrapper, SFunction<T, ?> cursorColumn) {
|
||||||
@@ -60,7 +60,7 @@ public class CursorUtils {
|
|||||||
.map(String::valueOf)
|
.map(String::valueOf)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
Boolean isLast = page.getRecords().size() != request.getPageSize();
|
Boolean isLast = page.getRecords().size() != request.getPageSize();
|
||||||
return new CursorPageBaseResp(cursor, isLast, page.getRecords());
|
return new CursorPageBaseResp<>(cursor, isLast, page.getRecords());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -24,8 +24,6 @@ public class LoginServiceImpl implements LoginService {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private JwtUtils jwtUtils;
|
private JwtUtils jwtUtils;
|
||||||
@Autowired
|
|
||||||
private RedisUtils redisUtils;
|
|
||||||
//token过期时间
|
//token过期时间
|
||||||
private static final Integer TOKEN_EXPIRE_DAYS = 5;
|
private static final Integer TOKEN_EXPIRE_DAYS = 5;
|
||||||
//token续期时间
|
//token续期时间
|
||||||
@@ -37,6 +35,7 @@ public class LoginServiceImpl implements LoginService {
|
|||||||
* @param token
|
* @param token
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public boolean verify(String token) {
|
public boolean verify(String token) {
|
||||||
Long uid = jwtUtils.getUidOrNull(token);
|
Long uid = jwtUtils.getUidOrNull(token);
|
||||||
if (Objects.isNull(uid)) {
|
if (Objects.isNull(uid)) {
|
||||||
@@ -48,25 +47,26 @@ public class LoginServiceImpl implements LoginService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
|
@Override
|
||||||
public void renewalTokenIfNecessary(String token) {
|
public void renewalTokenIfNecessary(String token) {
|
||||||
Long uid = jwtUtils.getUidOrNull(token);
|
Long uid = jwtUtils.getUidOrNull(token);
|
||||||
if (Objects.isNull(uid)) {
|
if (Objects.isNull(uid)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String key = RedisKey.getKey(RedisKey.USER_TOKEN_STRING, uid);
|
String key = RedisKey.getKey(RedisKey.USER_TOKEN_STRING, uid);
|
||||||
long expireDays = redisUtils.getExpire(key, TimeUnit.DAYS);
|
long expireDays = RedisUtils.getExpire(key, TimeUnit.DAYS);
|
||||||
if (expireDays == -2) {//不存在的key
|
if (expireDays == -2) {//不存在的key
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (expireDays < TOKEN_RENEWAL_DAYS) {//小于一天的token帮忙续期
|
if (expireDays < TOKEN_RENEWAL_DAYS) {//小于一天的token帮忙续期
|
||||||
redisUtils.expire(key, TOKEN_EXPIRE_DAYS, TimeUnit.DAYS);
|
RedisUtils.expire(key, TOKEN_EXPIRE_DAYS, TimeUnit.DAYS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String login(Long uid) {
|
public String login(Long uid) {
|
||||||
String key = RedisKey.getKey(RedisKey.USER_TOKEN_STRING, uid);
|
String key = RedisKey.getKey(RedisKey.USER_TOKEN_STRING, uid);
|
||||||
String token = redisUtils.getStr(key);
|
String token = RedisUtils.getStr(key);
|
||||||
if (StrUtil.isNotBlank(token)) {
|
if (StrUtil.isNotBlank(token)) {
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user