package com.xmzs.common.tenant.core;
|
|
import com.xmzs.common.core.constant.GlobalConstants;
|
import com.xmzs.common.redis.utils.RedisUtils;
|
import com.xmzs.common.satoken.core.dao.PlusSaTokenDao;
|
|
import java.time.Duration;
|
import java.util.List;
|
|
/**
|
* SaToken 认证数据持久层 适配多租户
|
*
|
* @author Lion Li
|
*/
|
public class TenantSaTokenDao extends PlusSaTokenDao {
|
|
@Override
|
public String get(String key) {
|
return super.get(GlobalConstants.GLOBAL_REDIS_KEY + key);
|
}
|
|
@Override
|
public void set(String key, String value, long timeout) {
|
super.set(GlobalConstants.GLOBAL_REDIS_KEY + key, value, timeout);
|
}
|
|
/**
|
* 修修改指定key-value键值对 (过期时间不变)
|
*/
|
@Override
|
public void update(String key, String value) {
|
long expire = getTimeout(key);
|
// -2 = 无此键
|
if (expire == NOT_VALUE_EXPIRE) {
|
return;
|
}
|
this.set(key, value, expire);
|
}
|
|
/**
|
* 删除Value
|
*/
|
@Override
|
public void delete(String key) {
|
super.delete(GlobalConstants.GLOBAL_REDIS_KEY + key);
|
}
|
|
/**
|
* 获取Value的剩余存活时间 (单位: 秒)
|
*/
|
@Override
|
public long getTimeout(String key) {
|
return super.getTimeout(GlobalConstants.GLOBAL_REDIS_KEY + key);
|
}
|
|
/**
|
* 修改Value的剩余存活时间 (单位: 秒)
|
*/
|
@Override
|
public void updateTimeout(String key, long timeout) {
|
// 判断是否想要设置为永久
|
if (timeout == NEVER_EXPIRE) {
|
long expire = getTimeout(key);
|
if (expire == NEVER_EXPIRE) {
|
// 如果其已经被设置为永久,则不作任何处理
|
} else {
|
// 如果尚未被设置为永久,那么再次set一次
|
this.set(key, this.get(key), timeout);
|
}
|
return;
|
}
|
RedisUtils.expire(GlobalConstants.GLOBAL_REDIS_KEY + key, Duration.ofSeconds(timeout));
|
}
|
|
|
/**
|
* 获取Object,如无返空
|
*/
|
@Override
|
public Object getObject(String key) {
|
return super.getObject(GlobalConstants.GLOBAL_REDIS_KEY + key);
|
}
|
|
/**
|
* 写入Object,并设定存活时间 (单位: 秒)
|
*/
|
@Override
|
public void setObject(String key, Object object, long timeout) {
|
super.setObject(GlobalConstants.GLOBAL_REDIS_KEY + key, object, timeout);
|
}
|
|
/**
|
* 更新Object (过期时间不变)
|
*/
|
@Override
|
public void updateObject(String key, Object object) {
|
long expire = getObjectTimeout(key);
|
// -2 = 无此键
|
if (expire == NOT_VALUE_EXPIRE) {
|
return;
|
}
|
this.setObject(key, object, expire);
|
}
|
|
/**
|
* 删除Object
|
*/
|
@Override
|
public void deleteObject(String key) {
|
super.deleteObject(GlobalConstants.GLOBAL_REDIS_KEY + key);
|
}
|
|
/**
|
* 获取Object的剩余存活时间 (单位: 秒)
|
*/
|
@Override
|
public long getObjectTimeout(String key) {
|
return super.getObjectTimeout(GlobalConstants.GLOBAL_REDIS_KEY + key);
|
}
|
|
/**
|
* 修改Object的剩余存活时间 (单位: 秒)
|
*/
|
@Override
|
public void updateObjectTimeout(String key, long timeout) {
|
// 判断是否想要设置为永久
|
if (timeout == NEVER_EXPIRE) {
|
long expire = getObjectTimeout(key);
|
if (expire == NEVER_EXPIRE) {
|
// 如果其已经被设置为永久,则不作任何处理
|
} else {
|
// 如果尚未被设置为永久,那么再次set一次
|
this.setObject(key, this.getObject(key), timeout);
|
}
|
return;
|
}
|
RedisUtils.expire(GlobalConstants.GLOBAL_REDIS_KEY + key, Duration.ofSeconds(timeout));
|
}
|
|
|
/**
|
* 搜索数据
|
*/
|
@Override
|
public List<String> searchData(String prefix, String keyword, int start, int size, boolean sortType) {
|
return super.searchData(GlobalConstants.GLOBAL_REDIS_KEY + prefix, keyword, start, size, sortType);
|
}
|
}
|