Пример #1
0
        static void Main(string[] args)
        {
            #region 入队的code
            {
                int index = 100;
                while (index > 0)
                {
                    // string msg = Console.ReadLine();
                    // 发布消息
                    new MyRedisSubPublishHelper().PublishMessage("hello", $"你好:Guid值是:{DateTime.Now}{Guid.NewGuid().ToString()}");
                    Console.WriteLine("发布成功!");

                    // 订阅消息
                    // new MyRedisSubPublishHelper().SubScribe("hello");
                    index -= 1;
                }

                Console.ReadKey();
            }
            #endregion

            #region 秒杀的code
            {
                try
                {
                    Console.WriteLine("秒杀开始。。。。。");
                    for (int i = 0; i < 200; i++)
                    {
                        Task.Run(() =>
                        {
                            MyRedisSubPublishHelper.LockByRedis("mstest");
                            string productCount = MyRedisHelper.StringGet("productcount");
                            int pcount          = int.Parse(productCount);
                            if (pcount > 0)
                            {
                                long dlong = MyRedisHelper.StringDec("productcount");
                                Console.WriteLine($"秒杀成功,商品库存:{dlong}");
                                pcount -= 1;
                                System.Threading.Thread.Sleep(30);
                            }
                            else
                            {
                                Console.WriteLine($"秒杀失败,商品库存为零了!");
                                throw new Exception("产品秒杀数量为零!");//加载这里会比较保险
                            }
                            MyRedisSubPublishHelper.UnLockByRedis("mstest");
                        }).Wait();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"产品已经秒杀完毕,原因:{ex.Message}");
                }
                Console.ReadKey();
            }
            #endregion
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 500000; i++)
            {
                Many m = new Many();
                m.Name     = "你哭着对我手啊是的减肥啦啥地方阿里那是来得及伐<embed src=\"/File/KindEditor/flash/20160504/20160504152346_3073.swf\" type=\"application/x-shockwave-flash\" width=\"200\" height=\"100\" quality=\"high\" />啊发生的是打发打发是打发打发ss<embed src=\"/File/KindEditor/media/20160506/20160506164834_9174.mp4\" type=\"video/x-ms-asf-plugin\" width=\"550\" height=\"400\" autostart=\"false\" loop=\"true\" />sdfss<embed src=\"/File/KindEditor/media/20160506/20160506153158_5436.mp4\" type=\"video/x-ms-asf-plugin\" width=\"550\" height=\"400\" autostart=\"false\" loop=\"true\" />sdfss<embed src=\"/File/KindEditor/media/20160506/20160506164834_9174.mp4\" type=\"video/x-ms-asf-plugin\" width=\"550\" height=\"400\" autostart=\"false\" loop=\"true\" />sdf";
                m.Email    = "你哭着对我手啊是的减肥啦啥地方阿里那是来得及伐<embed src=\"/File/KindEditor/flash/20160504/20160504152346_3073.swf\" type=\"application/x-shockwave-flash\" width=\"200\" height=\"100\" quality=\"high\" />啊发生的是打发打发是打发打发ss<embed src=\"/File/KindEditor/media/20160506/20160506164834_9174.mp4\" type=\"video/x-ms-asf-plugin\" width=\"550\" height=\"400\" autostart=\"false\" loop=\"true\" />sdfss<embed src=\"/File/KindEditor/media/20160506/20160506153158_5436.mp4\" type=\"video/x-ms-asf-plugin\" width=\"550\" height=\"400\" autostart=\"false\" loop=\"true\" />sdfss<embed src=\"/File/KindEditor/media/20160506/20160506164834_9174.mp4\" type=\"video/x-ms-asf-plugin\" width=\"550\" height=\"400\" autostart=\"false\" loop=\"true\" />sdf";
                m.ID       = 12345678;
                m.Adress   = "你哭着对我手啊是的减肥啦啥地方阿里那是来得及伐<embed src=\"/File/KindEditor/flash/20160504/20160504152346_3073.swf\" type=\"application/x-shockwave-flash\" width=\"200\" height=\"100\" quality=\"high\" />啊发生的是打发打发是打发打发ss<embed src=\"/File/KindEditor/media/20160506/20160506164834_9174.mp4\" type=\"video/x-ms-asf-plugin\" width=\"550\" height=\"400\" autostart=\"false\" loop=\"true\" />sdfss<embed src=\"/File/KindEditor/media/20160506/20160506153158_5436.mp4\" type=\"video/x-ms-asf-plugin\" width=\"550\" height=\"400\" autostart=\"false\" loop=\"true\" />sdfss<embed src=\"/File/KindEditor/media/20160506/20160506164834_9174.mp4\" type=\"video/x-ms-asf-plugin\" width=\"550\" height=\"400\" autostart=\"false\" loop=\"true\" />sdf";
                m.TrueName = "你哭着对我手啊是的减肥啦啥地方阿里那是来得及伐" + i.ToString();
                MyRedisHelper.Hash_Set <Many>("sss", i.ToString(), m);
            }

            // 移除
            MyRedisHelper.Hash_Remove("sss");
            // 获取
            Many xx = MyRedisHelper.Hash_Get <Many>("sss", "22");

            Many one = new Many();

            one.ID    = 1;
            one.Name  = "1st";
            one.Email = "1email";
            MyRedisHelper.Hash_Set <Many>("manytest", "1", one);
            MyRedisHelper.Hash_Remove("manytest");
            Many two = new Many();

            two.ID    = 2;
            two.Name  = "2st";
            two.Email = "2email";
            MyRedisHelper.Hash_Set <Many>("manytest", "2", two);

            Many        m1   = MyRedisHelper.Hash_Get <Many>("manytest", "2");
            List <Many> list = MyRedisHelper.Hash_GetAll <Many>("manytest");

            MyRedisHelper.Hash_Remove("sss");
            Many          m2 = MyRedisHelper.Hash_Get <Many>("manytest", "1");
            List <string> mm = new List <string>()
            {
                "11", "22"
            };
            List <int> sas = mm.ConvertAll <int>(p => Convert.ToInt32(p));
            // List<Many> list1 = new List<Many>() {new Many(){ ID=1, Name="1", One="1" } };
        }