Exemple #1
0
 public static string BlockingRemoveStartFromList(string listId, TimeSpan?timeOut)
 {
     using (RedisClient client = GetClient())
     {
         return(client.BlockingRemoveStartFromList(listId, timeOut));
     }
 }
 /// <summary>
 /// 阻塞命令:从list中key的头部移除一个值,并返回移除的值,阻塞时间为sp
 /// </summary>
 public string BlockingRemoveStartFromList(string keys, TimeSpan?sp)
 {
     return(RedisClient.BlockingRemoveStartFromList(keys, sp));
 }
 public string BlockingRemoveStartFromList(string listId, TimeSpan?timeOut)
 {
     return(redisClient.BlockingRemoveStartFromList(listId, timeOut));
 }
Exemple #4
0
        //处理异步队列
        private void RunQueue()
        {
            RedisClient RC = FMDBHelperClass.RedisClass.GetRedisClient(null);

            while (runing)
            {
                Thread.Sleep(1);
                string LeftOneGUID = "0";
                try
                {
                    //队列中,从左边开始,取出1个,按顺序进行处理
                    //从这里直接连接Redis,写入异步处理队列

                    //取出并删除最左边的元素。没有的话,会阻塞这个线程和此项目的连接。
                    LeftOneGUID = RC.BlockingRemoveStartFromList("L:queIPC:RUN", new TimeSpan(0, 5, 0));
                    if (LeftOneGUID == null)
                    {
                    }
                    else
                    {
                        //根据这个GUID,获取接口数据进行调用。 调用完成且接口没返回null(不代表业务成功),就删除。否则保留下来。

                        //调用目标的基本信息
                        Dictionary <string, string> FF = RC.GetAllEntriesFromHash("H:queIPC:FF:" + LeftOneGUID);

                        //参数
                        byte[][] CS       = RC.ZRange("Z:queIPC:CS:" + LeftOneGUID, 0, -1);
                        int      CScount  = CS.Count();
                        object[] objectCS = new object[CScount];
                        for (int i = 0; i < CScount; i++)
                        {
                            MemoryStream ms = new MemoryStream(CS[i]);
                            IFormatter   bf = new BinaryFormatter();
                            objectCS[i] = bf.Deserialize(ms);
                            ms.Close();
                            ms.Dispose();
                        }

                        //开始调用
                        object     re    = null;
                        string     Durls = "http://" + FF["JKhost"] + "/" + FF["JKpath"];
                        FMWScenter wsd   = new FMWScenter(Durls + "?wsdl");
                        re = wsd.ExecuteQuery(FF["FFname"], objectCS);
                        if (re != null)
                        {
                            //异步执行完成没有返回null,删除关联数据
                            RC.Del(new string[] { "H:queIPC:FF:" + LeftOneGUID, "Z:queIPC:CS:" + LeftOneGUID });
                        }
                        else
                        {
                            //异步执行返回了null,通常都是没有成功
                            RC.PushItemToList("L:queIPC:RUNERR", LeftOneGUID);
                        }
                    }
                }
                catch (Exception ex)
                {
                    //发生了错误,记录一下。目前只是简单的记录。以后再说
                    RC.PushItemToList("L:queIPC:RUNERR", LeftOneGUID);
                }
            }
            MessageBox.Show("。。。。。停了。。。。。。");
            //
        }