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

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

Open
LFeYls opened this issue Oct 8, 2021 · 0 comments
Open

Comments

@LFeYls
Copy link

LFeYls commented Oct 8, 2021

在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;
            }
        }

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

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

1 participant