public void Add_Multiple_Object_With_A_Single_Roundtrip_To_Redis_Must_Store_Data_Correctly_Into_Database()
        {
            IList <Tuple <string, string> > values = new List <Tuple <string, string> >();

            values.Add(new Tuple <string, string>("key1", "value1"));
            values.Add(new Tuple <string, string>("key2", "value2"));
            values.Add(new Tuple <string, string>("key3", "value3"));

            bool added = Sut.AddAll(values);

            Assert.True(added);

            Assert.True(Db.KeyExists("key1"));
            Assert.True(Db.KeyExists("key2"));
            Assert.True(Db.KeyExists("key3"));

            Assert.Equal(Serializer.Deserialize <string>(Db.StringGet("key1")), "value1");
            Assert.Equal(Serializer.Deserialize <string>(Db.StringGet("key2")), "value2");
            Assert.Equal(Serializer.Deserialize <string>(Db.StringGet("key3")), "value3");
        }
        public bool AddAll<T>(IList<Tuple<string, T>> items)
        {
            var result = false;

            var pages = items.Count / 1000.0;

            for (int i = 0; i < pages; i++)
            {
                var newItems = items.Skip(i * 1000).Take(1000).ToList();
                result = ExecuteWithRetry(() => cacheClient.AddAll(newItems));
            }

            return result;
        }
        public static void SaveBigData <T>(List <T> list, string keyField)
        {
            #region Basic
            //var cache = Connection.GetDatabase();
            //foreach (var item in list)
            //{
            //    cache.StringSet(item.GetType().GetProperty(keyField).GetValue(item).ToString(), JsonConvert.SerializeObject(item));
            //}
            #endregion
            var values = new List <Tuple <string, string> >();
            foreach (var item in list)
            {
                values.Add(new Tuple <string, string>(item.GetType().GetProperty(keyField).GetValue(item).ToString(), JsonConvert.SerializeObject(item)));
            }

            cacheClient.AddAll(values);
        }
Пример #4
0
 public void Set <T>(CacheItemList <T> items) where T : class => Client.AddAll(items.Data, items.ExpiresAt, items.ExpiresIn, items.FireAndForget);
Пример #5
0
 public void Set <T>(IList <Tuple <string, T> > keyData) where T : class
 {
     _retryPolicy.ExecuteAction(() => _cacheClient.AddAll(keyData));
 }