Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RedisLettuceCache 在do_GET 等方法中对于valueDecoder.appyly() 异常没有打印到日志中 #805

Open
HHHHHHGGGGGG opened this issue Aug 18, 2023 · 3 comments

Comments

@HHHHHHGGGGGG
Copy link
Contributor

版本信息:jetcache-starter-redis-lettuce 2.7.3
问题:RedisLettuceCache实现类在do_GET 等方法(比如:do_GET_ALL也有同样的问题)中对于valueDecoder.appyly() 捕获的异常,并没有正确处理,导致打印到日志中异常是redis返回的异常而不是valueDecoder的异常,返回结果中也没有包含对应正常的异常,故导致如果decoder失败,在日志和结果信息中无法获取/看到预期的错误信息。

具体说明如下:

protected CacheGetResult<V> do_GET(K key) {
        try {
            byte[] newKey = buildKey(key);
            RedisFuture<byte[]> future = stringAsyncCommands.get(newKey);
            CacheGetResult<V> result = new CacheGetResult<>(future.handle((valueBytes, ex) -> {
                if (ex != null) {
                    JetCacheExecutor.defaultExecutor().execute(() -> logError("GET", key, ex));
                    return new ResultData(ex);
                } else {
                    try {
                        if (valueBytes != null) {
                            CacheValueHolder<V> holder = (CacheValueHolder<V>) valueDecoder.apply(valueBytes);
                            if (System.currentTimeMillis() >= holder.getExpireTime()) {
                                return new ResultData(CacheResultCode.EXPIRED, null, null);
                            } else {
                                return new ResultData(CacheResultCode.SUCCESS, null, holder);
                            }
                        } else {
                            return new ResultData(CacheResultCode.NOT_EXISTS, null, null);
                        }
                    } catch (Exception exception) {
                        // 问题所在:这里应该处理的异常是 exception,而不是ex,ex是redis client返回的异常
                        logError("GET", key, ex);
                        return new ResultData(ex);
                    }
                }
            }));
            setTimeout(result);
            return result;
        } catch (Exception ex) {
            logError("GET", key, ex);
            return new CacheGetResult(ex);
        }
    }
@areyouok
Copy link
Collaborator

你说的对,你要做个PR吗?还是我自己来?

@HHHHHHGGGGGG
Copy link
Contributor Author

你说的对,你要做个PR吗?还是我自己来?

好的,那我后面提个PR修复一下

@Roiocam
Copy link
Contributor

Roiocam commented Aug 13, 2024

这个 issue 可以 close 了吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants