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

deyfvvtc  于 8个月前  发布在  Redis
关注(0)|答案(3)|浏览(225)

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

具体说明如下:

  1. protected CacheGetResult<V> do_GET(K key) {
  2. try {
  3. byte[] newKey = buildKey(key);
  4. RedisFuture<byte[]> future = stringAsyncCommands.get(newKey);
  5. CacheGetResult<V> result = new CacheGetResult<>(future.handle((valueBytes, ex) -> {
  6. if (ex != null) {
  7. JetCacheExecutor.defaultExecutor().execute(() -> logError("GET", key, ex));
  8. return new ResultData(ex);
  9. } else {
  10. try {
  11. if (valueBytes != null) {
  12. CacheValueHolder<V> holder = (CacheValueHolder<V>) valueDecoder.apply(valueBytes);
  13. if (System.currentTimeMillis() >= holder.getExpireTime()) {
  14. return new ResultData(CacheResultCode.EXPIRED, null, null);
  15. } else {
  16. return new ResultData(CacheResultCode.SUCCESS, null, holder);
  17. }
  18. } else {
  19. return new ResultData(CacheResultCode.NOT_EXISTS, null, null);
  20. }
  21. } catch (Exception exception) {
  22. // 问题所在:这里应该处理的异常是 exception,而不是ex,ex是redis client返回的异常
  23. logError("GET", key, ex);
  24. return new ResultData(ex);
  25. }
  26. }
  27. }));
  28. setTimeout(result);
  29. return result;
  30. } catch (Exception ex) {
  31. logError("GET", key, ex);
  32. return new CacheGetResult(ex);
  33. }
  34. }
zxlwwiss

zxlwwiss1#

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

qlvxas9a

qlvxas9a2#

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

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

oyxsuwqo

oyxsuwqo3#

这个 issue 可以 close 了吧

相关问题