2881099 / FreeRedis

🦄 FreeRedis is .NET40+ redis client. supports cluster, sentinel, master-slave, pub-sub, lua, pipeline, transaction, streams, client-side-caching, and pooling.
MIT License
911 stars 160 forks source link

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

Open tihb666 opened 4 months ago

tihb666 commented 4 months ago

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

2881099 commented 4 months ago
        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 commented 4 months ago

好,自己加了一个判断:

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