fix: avoid NPE when previewing images with redis cache

CacheServiceRedisImpl#getImgCache(String) passed the key straight to Redisson, which throws NullPointerException (map key can't be null) for a null key. Every single-image preview hits this path because compressFileKey is only set for images inside an archive, so with cache.type=redis the preview endpoint always returned HTTP 500. Return an empty list for empty keys, matching CacheServiceJDKImpl.

Fixes #793
This commit is contained in:
baiyu-jujuc
2026-09-23 14:01:57 +08:00
parent cd127fd855
commit c1b9daa561
2 changed files with 70 additions and 0 deletions

View File

@@ -1,12 +1,14 @@
package cn.keking.service.cache.impl;
import cn.keking.service.cache.CacheService;
import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RBlockingQueue;
import org.redisson.api.RMapCache;
import org.redisson.api.RedissonClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -68,6 +70,9 @@ public class CacheServiceRedisImpl implements CacheService {
@Override
public List<String> getImgCache(String key) {
if (StringUtils.isEmpty(key)) {
return new ArrayList<>();
}
RMapCache<String, List<String>> convertedList = redissonClient.getMapCache(FILE_PREVIEW_IMGS_KEY);
return convertedList.get(key);
}