private static void ClearRedisServer()
 {
     using (ServiceStack.Redis.IRedisClient client = GlobalVariable.RedisClient)
     {
         client.FlushAll();
     }
 }
        public static void DownScheduleHandler()
        {
            ServiceStack.Redis.IRedisClient client = GlobalVariable.RedisClient;
            while (true)
            {
                try
                {
                    int count = client.GetListCount(GlobalVariable.PAGE_SEND_CONTENT);
                    for (int i = 0; i < count; i++)
                    {
                        string strUserKey = client.DequeueItemFromList(GlobalVariable.PAGE_SEND_CONTENT);
                        int    machineId  = client.Get <int>(GlobalVariable.PRE_DOWN_INFO_MACHINE + strUserKey);
                        byte[] buff       = client.Get <byte[]>(GlobalVariable.PRE_DOWN_INFO + strUserKey);

                        string        strUser = strUserKey.Substring(0, strUserKey.LastIndexOf('-'));
                        int           intUser = int.Parse(strUser);
                        enumErrorCode result  = CommunicateWithClient(machineId, buff, intUser);
                        if (result != enumErrorCode.HandlerSuccess)
                        {
                            int intResult = (int)result;
                            client.Set <int>(GlobalVariable.PRE_RESP_DOWN_INFO + strUserKey, intResult);
                        }
                    }
                }
                catch (Exception ex)
                {
                    db.InsertErrorInfo(enumSystemErrorCode.TcpSenderException, ex, "outside", null);
                }
                Thread.Sleep(2000);
            }
        }
Exemple #3
0
 protected void setRedis(WMSModel.WMSData data)
 {
     //ServiceStack.Redis.RedisClient redisClient=new ServiceStack.Redis.RedisClient();
     //redisClient.
     ServiceStack.Redis.IRedisClient redisClient = RedisManager.GetClient();
     redisClient.Set <WMSModel.WMSData>("data", data);
 }
Exemple #4
0
        public byte[] HandlerClientData(byte[] buff)
        {
            NetStructure.ClientResp outInfo = this.DecodeData(buff);

            using (ServiceStack.Redis.IRedisClient client = GlobalVariable.RedisClient)
            {
                string strUserKey = client.Get <string>(GlobalVariable.PRE_INFO_TYPE_DISCARD + outInfo.MachineId.ToString());
                client.Set <int>(GlobalVariable.PRE_RESP_DOWN_INFO + strUserKey, (int)outInfo.RespResult);
            }
            return(null);
        }
 private static void ProcessList(string listId, string lockKey, ServiceStack.Redis.IRedisClient redisClient, string messageId)
 {
     using (redisClient.AcquireLock(lockKey, TimeSpan.FromMinutes(lockTime)))
     {
         if (redisClient.GetItemFromList(listId, 0) == messageId)
         {
             if (redisClient.RemoveStartFromList(listId) != messageId)
             {
                 throw new Exception("Neuskutocnitelne sa stalo !");
             }
         }
     }
 }
Exemple #6
0
        public static async Task Redis()
        {
            ServiceStack.Redis.IRedisClient client = null;

            client.SetValue("key", "value"); // ok

            var s = client.LoadLuaScript("script");

            client.ExecLua("script", new[] { "" }, new[] { "" });
            client.ExecLuaSha("SHA", new[] { "" }, new[] { "" }); // ok
            client.Custom("command", "arg");                      // false negative, params sinks doesn't work

            ServiceStack.Redis.IRedisClientAsync asyncClient = null;
            s = await asyncClient.LoadLuaScriptAsync("script");

            asyncClient.ExecLuaAsync("script", new[] { "" }, new[] { "" });
        }
Exemple #7
0
        public static ServiceStack.Redis.IRedisClient GetRedisClient(ReadOrWrite rw)
        {
            ServiceStack.Redis.IRedisClient client = null;
            switch (rw)
            {
            //读写
            case ReadOrWrite.Write:
                client = RadisManager.GetClient();
                break;

            //只读
            case ReadOrWrite.Read:
                client = RadisManager.GetReadOnlyClient();
                break;
            }

            return(client);
        }
Exemple #8
0
 public ActionResult GetData()
 {
     try
     {
         string name    = Request.QueryString["data"];
         bool   ret     = Regex.IsMatch(name, "[0-9]+");
         string channel = "";
         if (ret)
         {
             channel = name + "#阀室";
             using (ServiceStack.Redis.IRedisClient redis = RedisHelper.CreateRedisPool().GetClient())
             {
                 double[] rest = JsonConvert.DeserializeObject <double[]>(redis.Get <string>(channel));
                 return(Content(JsonConvert.SerializeObject(new Vala {
                     loggerName = channel, Data = rest[0].ToString("f2")
                 })));
             }
         }
         else
         {
             channel = name;
             List <string> list = new List <string>();
             using (ServiceStack.Redis.IRedisClient redis = RedisHelper.CreateRedisPool().GetClient())
             {
                 double[] rest = JsonConvert.DeserializeObject <double[]>(redis.Get <string>(channel));
                 foreach (double item in rest)
                 {
                     list.Add(item.ToString("f2"));
                 }
                 return(Content(JsonConvert.SerializeObject(new Station {
                     loggerName = channel, Data = list.ToArray()
                 })));
             }
         }
     }
     catch (System.Exception ex)
     {
         LogHelper.WriteLog(typeof(MapController), ex.StackTrace + ex.Message);
         return(null);
     }
 }
        public ActionResult vrlist()
        {
            List <string> list      = null;
            List <string> sortList  = null;
            long          count     = 0;
            long          sortcount = 0;

            using (ServiceStack.Redis.IRedisClient cl = Common.Common.RedisPool.GetClient())
            {
                count = cl.GetListCount(Common.ConfigSettings.RedisListKey);

                list = cl.GetRangeFromList(Common.ConfigSettings.RedisListKey, count > 100 ? (int)(count - 100) : 0, (int)count - 1);

                sortList = cl.GetRangeFromSortedSetDesc(Common.ConfigSettings.RedisSortListKey, 1, 10);

                sortcount = cl.GetSortedSetCount(Common.ConfigSettings.RedisSortListKey);
            }
            ViewBag.list      = string.Join(",", list.ToArray());
            ViewBag.count     = count.ToString();
            ViewBag.qcount    = Common.Common.GetQueueCount().ToString();
            ViewBag.sortlist  = string.Join(",", sortList.ToArray());
            ViewBag.sortcount = sortcount;

            int maxthreadcount = 0;
            //int currthreadcount = 0;
            int availthreadcount = 0;
            int iocouint         = 0;

            ThreadPool.GetMaxThreads(out maxthreadcount, out iocouint);
            ThreadPool.GetAvailableThreads(out availthreadcount, out iocouint);

            ViewBag.maxthreadcount = maxthreadcount;

            ViewBag.availthreadcount = availthreadcount;



            return(View());
        }
Exemple #10
0
        private void RefreshOnlineInfo(Machines machine)
        {
            const string ONLINE_FACTRORY_ROOM = "ONLINEFACTORYROOM", PRE_ROOM_NAME_NUMBER = "PREROOMNAMENUMBER", PRE_ONLINE_MACHINE = "PREONLINEMACHINE",
                         PRE_MACHINE_NAME_NUMBER = "PREMACHINENAMENUMBER", PRE_ONLINE_TIME = "PREONLINETIME";

            using (ServiceStack.Redis.IRedisClient client = GlobalVariable.RedisClient)
            {
                HashSet <string> roomList = client.GetAllItemsFromSet(ONLINE_FACTRORY_ROOM);
                if (!roomList.Contains(machine.RoomNumber))
                {
                    client.AddItemToSet(ONLINE_FACTRORY_ROOM, machine.RoomNumber);
                    client.Set <string>(PRE_ROOM_NAME_NUMBER + machine.RoomNumber, machine.RoomName);
                }
                string           strMachineValue = PRE_ONLINE_MACHINE + machine.RoomNumber;
                HashSet <string> machineList     = client.GetAllItemsFromSet(strMachineValue);
                if (!machineList.Contains(machine.Number))
                {
                    client.AddItemToSet(strMachineValue, machine.Number);
                    client.Set <string>(PRE_MACHINE_NAME_NUMBER + machine.Number, machine.Name);
                }
                client.Set <long>(PRE_ONLINE_TIME + machine.Number, DateTime.Now.Ticks);
            }
        }
Exemple #11
0
 public void Connect(RedisConnectionStringBuilder connectionString)
 {
     _client = new ServiceStack.Redis.RedisClient(((IPEndPoint)connectionString.EndPoint).Address.ToString(),
                                                  ((IPEndPoint)connectionString.EndPoint).Port);
 }