he2802 2 年 前
コミット
6a94d6aba1

+ 14 - 4
zhongzheng-common/src/main/java/com/zhongzheng/common/core/redis/RedisCache.java

@@ -38,7 +38,14 @@ public class RedisCache
      */
     public <T> void setCacheObject(final String key, final T value)
     {
-        redisTemplate.opsForValue().set(key, value);
+        String unionKey = key;
+        if(Validator.isNotEmpty(ServletUtils.getRequest())){
+            String tenantId = ServletUtils.getRequest().getHeader("TenantId");
+            if(Validator.isNotEmpty(tenantId)){
+                unionKey = tenantId + key;
+            }
+        }
+        redisTemplate.opsForValue().set(unionKey, value);
     }
 
     /**
@@ -113,11 +120,14 @@ public class RedisCache
      */
     public boolean deleteObject(final String key)
     {
-        String tenantId = ServletUtils.getRequest().getHeader("TenantId");
         String unionKey = key;
-        if(Validator.isNotEmpty(tenantId)){
-            unionKey = tenantId + key;
+        if(Validator.isNotEmpty(ServletUtils.getRequest())){
+            String tenantId = ServletUtils.getRequest().getHeader("TenantId");
+            if(Validator.isNotEmpty(tenantId)){
+                unionKey = tenantId + key;
+            }
         }
+
         return redisTemplate.delete(unionKey);
     }