|
@@ -3,6 +3,8 @@ package com.zhongzheng.common.core.redis;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
+import cn.hutool.core.lang.Validator;
|
|
|
+import com.zhongzheng.common.utils.ServletUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -49,7 +51,13 @@ public class RedisCache
|
|
|
*/
|
|
|
public <T> void setCacheObject(final String key, final T value, final Integer timeout, final TimeUnit timeUnit)
|
|
|
{
|
|
|
- redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
|
|
|
+ String tenantId = ServletUtils.getRequest().getHeader("TenantId");
|
|
|
+ String unionKey = key;
|
|
|
+ if(Validator.isNotEmpty(tenantId)){
|
|
|
+ unionKey = tenantId + key;
|
|
|
+ }
|
|
|
+ redisTemplate.opsForValue().set(unionKey, value, timeout, timeUnit);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -86,7 +94,12 @@ public class RedisCache
|
|
|
public <T> T getCacheObject(final String key)
|
|
|
{
|
|
|
ValueOperations<String, T> operation = redisTemplate.opsForValue();
|
|
|
- return operation.get(key);
|
|
|
+ String tenantId = ServletUtils.getRequest().getHeader("TenantId");
|
|
|
+ String unionKey = key;
|
|
|
+ if(Validator.isNotEmpty(tenantId)){
|
|
|
+ unionKey = tenantId + key;
|
|
|
+ }
|
|
|
+ return operation.get(unionKey);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -96,7 +109,12 @@ public class RedisCache
|
|
|
*/
|
|
|
public boolean deleteObject(final String key)
|
|
|
{
|
|
|
- return redisTemplate.delete(key);
|
|
|
+ String tenantId = ServletUtils.getRequest().getHeader("TenantId");
|
|
|
+ String unionKey = key;
|
|
|
+ if(Validator.isNotEmpty(tenantId)){
|
|
|
+ unionKey = tenantId + key;
|
|
|
+ }
|
|
|
+ return redisTemplate.delete(unionKey);
|
|
|
}
|
|
|
|
|
|
/**
|