统计数据归档查询、商品数据分类缓存、已知问题修复

This commit is contained in:
Tankaikai
2025-04-16 15:24:32 +08:00
parent ff8a1e5de2
commit 954f2329bc
29 changed files with 611 additions and 273 deletions

View File

@@ -1,5 +1,7 @@
package com.czg.service;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -598,4 +600,54 @@ public class RedisService {
return redisTemplate.opsForList().rightPop(key);
}
/**
* 右模糊查找key
*
* @param key 模糊匹配的key前缀
* @return 匹配的keys
*/
public Set<String> rightLikeKey(String key) {
return redisTemplate.keys(key + "*");
}
/**
* JsonString缓存放入
*
* @param key 键
* @param value 值
* @return true成功 false失败
*/
public boolean setJsonStr(String key, Object value) {
try {
redisTemplate.opsForValue().set(key, JSON.toJSONString(value, JSONWriter.Feature.WriteMapNullValue));
return true;
} catch (Exception e) {
log.error("redis error:{}", e + "");
return false;
}
}
/**
* JsonString缓存获取
*
* @param key 键
* @return 值
*/
public String getJsonStr(String key) {
return key == null ? null : (String) redisTemplate.opsForValue().get(key);
}
/**
* JsonString缓存获取
*
* @param key 键
* @return 值
*/
public <T> List<T> getJsonToBeanList(String key, Class<T> type) {
String jsonStr = getJsonStr(key);
if (jsonStr == null) {
return null;
}
return JSON.parseArray(jsonStr, type);
}
}