mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-06-28 04:35:16 +08:00
refactor: 重构 sa-token-redis-template、sa-token-redis-template-jdk-serializer 插件中 update 方法 ttl 获取方式改为毫秒,以减少 update 时的 ttl 计算误差。
This commit is contained in:
parent
c22fb3efb1
commit
9913a901aa
@ -95,12 +95,18 @@ public class SaTokenDaoForRedisTemplate implements SaTokenDaoByObjectFollowStrin
|
||||
*/
|
||||
@Override
|
||||
public void update(String key, String value) {
|
||||
long expire = getTimeout(key);
|
||||
// -2 = 无此键
|
||||
if(expire == SaTokenDao.NOT_VALUE_EXPIRE) {
|
||||
@SuppressWarnings("all")
|
||||
long expireMs = stringRedisTemplate.getExpire(key, TimeUnit.MILLISECONDS);
|
||||
// -2 = 无此键
|
||||
if (expireMs == SaTokenDao.NOT_VALUE_EXPIRE) {
|
||||
return;
|
||||
}
|
||||
this.set(key, value, expire);
|
||||
// -1 = 永不过期
|
||||
if(expireMs == SaTokenDao.NEVER_EXPIRE) {
|
||||
stringRedisTemplate.opsForValue().set(key, value);
|
||||
} else {
|
||||
stringRedisTemplate.opsForValue().set(key, value, expireMs, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -95,12 +95,18 @@ public class SaTokenDaoForRedisTemplateUseJdkSerializer extends SaTokenDaoForRed
|
||||
*/
|
||||
@Override
|
||||
public void updateObject(String key, Object object) {
|
||||
long expire = getObjectTimeout(key);
|
||||
// -2 = 无此键
|
||||
if(expire == SaTokenDao.NOT_VALUE_EXPIRE) {
|
||||
@SuppressWarnings("all")
|
||||
long expireMs = stringRedisTemplate.getExpire(key, TimeUnit.MILLISECONDS);
|
||||
// -2 = 无此键
|
||||
if (expireMs == SaTokenDao.NOT_VALUE_EXPIRE) {
|
||||
return;
|
||||
}
|
||||
this.setObject(key, object, expire);
|
||||
// -1 = 永不过期
|
||||
if(expireMs == SaTokenDao.NEVER_EXPIRE) {
|
||||
objectRedisTemplate.opsForValue().set(key, object);
|
||||
} else {
|
||||
objectRedisTemplate.opsForValue().set(key, object, expireMs, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -94,12 +94,18 @@ public class SaTokenDaoForRedisTemplate implements SaTokenDaoByObjectFollowStrin
|
||||
*/
|
||||
@Override
|
||||
public void update(String key, String value) {
|
||||
long expire = getTimeout(key);
|
||||
// -2 = 无此键
|
||||
if(expire == SaTokenDao.NOT_VALUE_EXPIRE) {
|
||||
@SuppressWarnings("all")
|
||||
long expireMs = stringRedisTemplate.getExpire(key, TimeUnit.MILLISECONDS);
|
||||
// -2 = 无此键
|
||||
if (expireMs == SaTokenDao.NOT_VALUE_EXPIRE) {
|
||||
return;
|
||||
}
|
||||
this.set(key, value, expire);
|
||||
// -1 = 永不过期
|
||||
if(expireMs == SaTokenDao.NEVER_EXPIRE) {
|
||||
stringRedisTemplate.opsForValue().set(key, value);
|
||||
} else {
|
||||
stringRedisTemplate.opsForValue().set(key, value, expireMs, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user