public static GetListResult <T> GetAllPropper <T>(this StackExchangeRedisCacheClient cacheClient, IEnumerable <string> keys) where T : class
        {
            var keysList = keys.ToList();

            if (!keysList.Any())
            {
                return(new GetListResult <T>(null, keysList));
            }

            var redisKeyArray    = new RedisKey[keysList.Count];
            var redisResultArray = (RedisResult[])cacheClient.Database.ScriptEvaluate(CreateLuaScriptForMget(redisKeyArray, keysList), redisKeyArray);
            var result           = new GetListResult <T>();

            for (var index = 0; index < redisResultArray.Length; ++index)
            {
                if (!redisResultArray[index].IsNull)
                {
                    var obj = cacheClient.Serializer.Deserialize <T>((byte[])redisResultArray[index]);
                    result.Add(obj);
                }
                else
                {
                    result.AddMissing(keysList[index]);
                }
            }

            return(result);
        }
Esempio n. 2
0
 public GetListResult <T> Add(GetListResult <T> other)
 {
     if (other == null)
     {
         return(this);
     }
     return(this.AddRange((IList <T>)other.Data).AddMissingRange((IList <string>)other.MissingKeys));
 }
        public static async Task <GetListResult <T> > GetAllPropperAsync <T>(this StackExchangeRedisCacheClient cacheClient, IEnumerable <string> keys)
            where T : class
        {
            var keysList = keys.ToList();

            if (!keysList.Any())
            {
                return(new GetListResult <T>(null, keysList));
            }

            var redisKeyArray    = new RedisKey[keysList.Count];
            var redisResultArray =
                (RedisResult[])await cacheClient.Database.ScriptEvaluateAsync(CreateLuaScriptForMget(redisKeyArray, keysList), redisKeyArray);

            var result = new GetListResult <T>();

            var deserializeTasks = new List <Task <T> >();

            for (var index = 0; index < redisResultArray.Length; ++index)
            {
                if (!redisResultArray[index].IsNull)
                {
                    deserializeTasks.Add(cacheClient.Serializer.DeserializeAsync <T>((byte[])redisResultArray[index]));
                }
                else
                {
                    result.AddMissing(keysList[index]);
                }
            }

            if (deserializeTasks.Any())
            {
                var res = await Task.WhenAll(deserializeTasks);

                result.AddRange(res);
            }

            return(result);
        }