コード例 #1
0
        /// <summary>
        /// Retrieve cached item
        /// </summary>
        /// <typeparam name="T">Type of cached item</typeparam>
        /// <param name="key">Name of cached item</param>
        /// <param name="value">Cached value. Default(T) if item doesn't exist.</param>
        /// <returns>Cached item as type</returns>
        public static bool Get <T>(string key, int clientId, int countryId, int buId, out T value)
        {
            try
            {
                string consolidatedKey = clientId.ToString() + countryId.ToString() + buId.ToString() + key;
                if (EntityChangeObserverMaster.DataGetObserver(key, clientId, countryId, buId))
                {
                    Clear(consolidatedKey);
                }

                if (!Exists(consolidatedKey))
                {
                    value = default(T);
                    return(false);
                }

                value = Redishelper.GetItem <T>(consolidatedKey);
            }
            catch (Exception ex)
            {
                value = default(T);
                return(false);
            }

            return(true);
        }
コード例 #2
0
ファイル: RedisDbWrapper.cs プロジェクト: HomeFood-SSKV/API
        /// <summary>
        /// Retrieve cached item
        /// </summary>
        /// <typeparam name="T">Type of cached item</typeparam>
        /// <param name="key">Name of cached item</param>
        /// <param name="value">Cached value. Default(T) if item doesn't exist.</param>
        /// <returns>Cached item as type</returns>
        public static bool Get <T>(string key, int clientId, int countryId, int buId, out T value)
        {
            try
            {
                var result         = DotnetCoreSvr.GetObserve();
                var individualItem = result.FirstOrDefault(s => s.TableName == key && s.Changed == true);
                if (individualItem != null)
                {
                    Clear(key, individualItem);
                }

                if (!Exists(key))
                {
                    value = default(T);
                    return(false);
                }
                value = Redishelper.GetItem <T>(key);
            }
            catch (Exception ex)
            {
                value = default(T);
                return(false);
            }
            return(true);
        }
コード例 #3
0
ファイル: RedisDbWrapper.cs プロジェクト: HomeFood-SSKV/API
        /// <summary>
        /// Insert value into the cache using
        /// appropriate name/value pairs
        /// </summary>
        /// <typeparam name="T">Type of cached item</typeparam>
        /// <param name="o">Item to be cached</param>
        /// <param name="key">Name of item</param>
        public static void Add <T>(T o, string key, int clientId, int countryId, int buId)
        {
            string consolidatedKey = clientId.ToString() + countryId.ToString() + buId.ToString() + key;

            Redishelper.SetItem(consolidatedKey,
                                DateTime.Now.AddMinutes(1440).TimeOfDay,
                                o);
        }
コード例 #4
0
        public void PopFromRedisTest()
        {
            Redishelper.Delete("testRedisList");
            Redishelper.Push("testRedisList", "test1");
            Redishelper.Push("testRedisList", "test2");
            var popObject = Redishelper.Pop <string>("testRedisList");

            Assert.AreEqual(popObject, "test1");
        }
コード例 #5
0
        public void GetPeriodSortingInfoSqlToRedisTest()
        {
            List <AAGetModel> peroidLists = SqlDal.GetPeriodAAModelList();

            if (peroidLists.Any())
            {
                Redishelper.PushList <AAGetModel>("SortingList", peroidLists);
            }
        }
コード例 #6
0
        public void RedisToApi()
        {
            Redishelper.Delete("SortingList");
            var peroidLists = SqlDal.GetPeriodAAModelList();

            if (peroidLists.Count <= 0)
            {
                return;
            }
            Redishelper.PushList <AAGetModel>("SortingList", peroidLists);
            var peroidListsPop = Redishelper.PopList <AAGetModel>("SortingList", Convert.ToInt16(ConfigurationManager.AppSettings["OncRedisPopNumber"]));
            var a = peroidListsPop.First();

            Assert.IsNotNull(a.BillNumber);
        }
コード例 #7
0
        public async Task ProcessAsync()
        {
            List <AAGetModel> peroidLists = SqlDal.GetPeriodAAModelList();

            Console.WriteLine($"TestTask:{DateTime.Now}");
            if (peroidLists.Any())
            {
                bool pushSuccess = await Redishelper.BoolPushList <AAGetModel>("SortingList", peroidLists);

                if (pushSuccess)
                {
                    SqlDal.ChangePeriodAAModelInfoListStatusInSql(peroidLists);
                    Console.WriteLine($"ChangeStatus:{DateTime.Now}");
                }
            }
            else
            {
                Console.WriteLine($"sleep:{DateTime.Now}");
                Thread.Sleep(20000);
            }
        }
コード例 #8
0
 public void PushToRedisTest()
 {
     Redishelper.Delete("testRedisList");
     Redishelper.Push("testRedisList", new AAGetModel());
     //Assert.AreEqual(resultnumber,1);
 }
コード例 #9
0
ファイル: RedisDbWrapper.cs プロジェクト: HomeFood-SSKV/API
 /// <summary>
 /// Check for item in cache
 /// </summary>
 /// <param name="key">Name of cached item</param>
 /// <returns></returns>
 public static bool Exists(string key)
 {
     return(Redishelper.KeyExists(key));
 }
コード例 #10
0
ファイル: RedisDbWrapper.cs プロジェクト: HomeFood-SSKV/API
 /// <summary>
 /// Remove item from cache
 /// </summary>
 /// <param name="key">Name of cached item</param>
 public static void Clear(string key, ObserveDto observe)
 {
     observe.Changed = false;
     DotnetCoreSvr.UpdateObserve(observe, true);
     Redishelper.DeleteItem(key);
 }
コード例 #11
0
        public List <AAGetModel> GetPeroidListsFromRedis()
        {
            List <AAGetModel> peroidLists = Redishelper.PopList <AAGetModel>("SortingList", Convert.ToInt16(ConfigurationManager.AppSettings["OncRedisPopNumber"]));

            return(peroidLists);
        }
コード例 #12
0
 /// <summary>
 /// Remove item from cache
 /// </summary>
 /// <param name="key">Name of cached item</param>
 public static void Clear(string key)
 {
     Redishelper.DeleteItem(consolidatedKey);
 }