Skip to content

AbpRedisCache.TryGetValue(string key, out object value)遇到的bug #8

Description

@LFeYls

在AbpRedisCache类中的重写方法TryGetValue(string key, out object value)中
按照官方AbpRedisCache类的实现逻辑,如果没有缓存key,则该方法应该将返回值设置为false,并将value设置为null;
但是大佬实现的方法中

 public override bool TryGetValue(string key, out object value)
        {
            try
            {
                value = RedisHelper.Get(GetLocalizedRedisKey(key));
                return true;
            }
            catch
            {
                value = null;
                return false;
            }
        }

默认为只要是没有异常就返回true,这里会导致项目启动获取语言列表的时候如果没有缓存,将null设置到Dictionary中而抛出异常。
将代码改为:

 public override bool TryGetValue(string key, out object value)
        {
            try
            {
                var objbyte  = RedisHelper.Get(GetLocalizedRedisKey(key));
                 value = objbyte != null ? Deserialize(objbyte) : null;
                return objbyte != null;
            }
            catch
            {
                value = null;
                return false;
            }
        }

项目能正常启动,但是我不太确定这种写法有没有其他的隐患,还请大佬指正。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions