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

调用get<T>方法,如果T传入的是数组类型,如果KEY值不存在,返回的是一个长度为0的数组,正常应该返回NULL #183

Open
tihb666 opened this issue May 7, 2024 · 2 comments

Comments

@tihb666
Copy link

tihb666 commented May 7, 2024

类:RedisClient,方法:public T Get(string key);
调用:.Get<string[]>("fdfawerere");
只有数组有这个问题,其他list,或string或实体都是正常的返回NULL,就数组返回了一个长度为0的数组,而不是NULL。

@2881099
Copy link
Owner

2881099 commented May 7, 2024

        public TValue ThrowOrValue<TValue>(Func<object, TValue> value)
        {
            if (IsError) throw new RedisServerException(this.SimpleError);
            var newval = value(this.Value);
            if (newval == null && typeof(TValue).IsArray) newval = (TValue)typeof(TValue).CreateInstanceGetDefaultValue();
            this.Value = newval;
            return newval;
        }

if (newval == null && typeof(TValue).IsArray)

@tihb666
Copy link
Author

tihb666 commented May 7, 2024

好,自己加了一个判断:

        if (typeof(T).IsArray)
        {
            if(result == null || (result as Array).Length == 0)
            {
                return default(T);
            }
        }

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

2 participants