Exemplo n.º 1
0
 /// <summary>
 /// 消息加入缓存
 /// </summary>
 /// <param name="sendEntity">缓存消息实体</param>
 public static void SetSendData(TerResultEntiy sendEntity)
 {
     try
     {
         var listTer = HashOperator.Get <List <TerResultEntiy> >(RedisServerFlag + sendEntity.IMEI);
         if (listTer != null)
         {
             var singleModel = listTer.SingleOrDefault(p => p.OrderLogID == sendEntity.OrderLogID);
             //如果存在,先删除当前指令
             if (singleModel != null)
             {
                 listTer.Remove(singleModel);
             }
         }
         else
         {
             listTer = new List <TerResultEntiy>();
         }
         listTer.Add(sendEntity);
         HashOperator.Set <List <TerResultEntiy> >(RedisServerFlag + sendEntity.IMEI, listTer);
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 移除缓存数据
 /// </summary>
 /// <param name="sendEntity">缓存消息实体</param>
 /// <returns></returns>
 public static void RemoveSendData(TerResultEntiy sendEntity)
 {
     try
     {
         var listTer = HashOperator.Get <List <TerResultEntiy> >(RedisServerFlag + sendEntity.IMEI);
         if (listTer != null)
         {
             //仅剩下一条数据,移除整个key
             if (listTer.Count == 1)
             {
                 HashOperator.Remove(RedisServerFlag + sendEntity.IMEI);
             }
             else
             {
                 //移除指定指令数据
                 var singleModel = listTer.SingleOrDefault(p => p.OrderLogID == sendEntity.OrderLogID);
                 if (singleModel != null)
                 {
                     listTer.Remove(singleModel);
                     HashOperator.Set <List <TerResultEntiy> >(RedisServerFlag + sendEntity.IMEI, listTer);
                 }
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 测试主业务Removet耗时(6/ms)
        /// </summary>
        static void TestBusinessMainRemove()
        {
            string sourceData_Login     = "******"; //登陆包
            string sourceData_Heartbeat = "*VK2015{0},AH#"; //心跳包

            System.Console.WriteLine("****Set执行中......****");
            System.Diagnostics.Stopwatch sw      = new System.Diagnostics.Stopwatch();
            System.Diagnostics.Stopwatch swTotal = new System.Diagnostics.Stopwatch();
            swTotal.Start();
            try
            {
                for (int i = 0; i < IMEI_NUM; i++)
                {
                    TerResultEntiy entity = new TerResultEntiy((IMEI_PREX + i).ToString(),
                                                               Encoding.ASCII.GetBytes(sourceData_Login),
                                                               ORDERLOGIN_PREX_REMOVE + i,
                                                               1,
                                                               0,
                                                               1,
                                                               DateTime.Now.Ticks)
                    {
                    };
                    //sw.Restart();
                    SendDataCache.RemoveSendData(entity);
                    //sw.Stop();
                    //System.Console.WriteLine($"IMEI:{(IMEI_PREX + i).ToString()} takes {sw.Elapsed} ms");
                }
                swTotal.Stop();
                System.Console.WriteLine($"All IMEIS takes {swTotal.ElapsedMilliseconds} ms");
                ORDERLOGIN_PREX_REMOVE = ORDERLOGIN_PREX_REMOVE + 1000000;
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }
        }