mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-04-04 22:57:32 +00:00
@@ -15,7 +15,8 @@ import java.util.Objects;
|
||||
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
@Bean
|
||||
|
||||
@Bean("myRedisTemplate")
|
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
||||
// 创建模板
|
||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||
@@ -30,10 +31,11 @@ public class RedisConfig {
|
||||
// value和 hashValue采用 JSON序列化
|
||||
redisTemplate.setValueSerializer(jsonRedisSerializer);
|
||||
redisTemplate.setHashValueSerializer(jsonRedisSerializer);
|
||||
redisTemplate.afterPropertiesSet();
|
||||
return redisTemplate;
|
||||
}
|
||||
|
||||
public class MyRedisSerializerCustomized extends GenericJackson2JsonRedisSerializer {
|
||||
private static class MyRedisSerializerCustomized extends GenericJackson2JsonRedisSerializer {
|
||||
@Override
|
||||
public byte[] serialize(Object source) throws SerializationException {
|
||||
if (Objects.nonNull(source)) {
|
||||
|
||||
@@ -44,7 +44,7 @@ public class CursorUtils {
|
||||
.map(String::valueOf)
|
||||
.orElse(null);
|
||||
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) {
|
||||
@@ -60,7 +60,7 @@ public class CursorUtils {
|
||||
.map(String::valueOf)
|
||||
.orElse(null);
|
||||
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
|
||||
private JwtUtils jwtUtils;
|
||||
@Autowired
|
||||
private RedisUtils redisUtils;
|
||||
//token过期时间
|
||||
private static final Integer TOKEN_EXPIRE_DAYS = 5;
|
||||
//token续期时间
|
||||
@@ -37,6 +35,7 @@ public class LoginServiceImpl implements LoginService {
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean verify(String token) {
|
||||
Long uid = jwtUtils.getUidOrNull(token);
|
||||
if (Objects.isNull(uid)) {
|
||||
@@ -48,25 +47,26 @@ public class LoginServiceImpl implements LoginService {
|
||||
}
|
||||
|
||||
@Async
|
||||
@Override
|
||||
public void renewalTokenIfNecessary(String token) {
|
||||
Long uid = jwtUtils.getUidOrNull(token);
|
||||
if (Objects.isNull(uid)) {
|
||||
return;
|
||||
}
|
||||
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
|
||||
return;
|
||||
}
|
||||
if (expireDays < TOKEN_RENEWAL_DAYS) {//小于一天的token帮忙续期
|
||||
redisUtils.expire(key, TOKEN_EXPIRE_DAYS, TimeUnit.DAYS);
|
||||
RedisUtils.expire(key, TOKEN_EXPIRE_DAYS, TimeUnit.DAYS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String login(Long uid) {
|
||||
String key = RedisKey.getKey(RedisKey.USER_TOKEN_STRING, uid);
|
||||
String token = redisUtils.getStr(key);
|
||||
String token = RedisUtils.getStr(key);
|
||||
if (StrUtil.isNotBlank(token)) {
|
||||
return token;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user