コード例 #1
0
ファイル: Program.cs プロジェクト: linchangsheng89/FreeRedis
        public static void NewLifeRedisSetTest()
        {
            var       tasks = new Task[frequence];
            Stopwatch sw    = new Stopwatch();

            sw.Start();
            for (var a = 0; a < frequence; a += 1)
            {
                tasks[a] = Task.Run(async() =>
                {
                    var key    = a.ToString();
                    var result = _newLifeRedis.Set(key, key);
                    if (!result)
                    {
                        throw new Exception("not equal");
                    }
                });
            }
            Task.WaitAll(tasks);
            sw.Stop();
            Console.WriteLine($"NewlifeRedis(0-{frequence}): {sw.ElapsedMilliseconds}ms");
        }
コード例 #2
0
        public static async Task ThreadOnly()
        {
            var a = await client.ConnectAsync();

            if (!a)
            {
                Console.WriteLine("连接服务器失败");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("连接服务器成功");
            Console.WriteLine("单线程测试,3000 个请求/ 3000 接收");

            var       stringClient = client.GetStringClient();
            Stopwatch watch        = new Stopwatch();

            watch.Start();
            int errorNum = 0;

            for (int i = 0; i < 3000; i++)
            {
                var guid = Guid.NewGuid().ToString();
                _ = await stringClient.Set(guid, guid);

                var tmp = await stringClient.Get(guid);

                if (tmp != guid)
                {
                    errorNum += 1;
                }
            }

            watch.Stop();
            Console.WriteLine($"CZGL.RedisClient 总共耗时:{watch.ElapsedMilliseconds} ms,错误次数 {errorNum}");

            errorNum = 0;
            sedb.SetAdd("testetst", "abcd");

            watch.Reset();
            watch.Start();
            for (int i = 0; i < 3000; i++)
            {
                var guid = Guid.NewGuid().ToString();
                _ = sedb.StringSet(guid, guid);
                var tmp = sedb.StringGet(guid);
                if (tmp != guid)
                {
                    errorNum += 1;
                }
            }

            watch.Stop();
            Console.WriteLine($"StackExchange.Redis 总共耗时:{watch.ElapsedMilliseconds} ms,错误次数 {errorNum}");

            errorNum = 0;

            await freeClient.SAddAsync("testetetstets", "testtest");

            watch.Reset();
            watch.Start();
            for (int i = 0; i < 3000; i++)
            {
                var guid = Guid.NewGuid().ToString();
                await freeClient.SetAsync(guid, guid);

                var tmp = await freeClient.GetAsync(guid);

                if (tmp != guid)
                {
                    errorNum += 1;
                }
            }

            watch.Stop();
            Console.WriteLine($"FreeRedis 总共耗时:{watch.ElapsedMilliseconds} ms,错误次数 {errorNum}");

            errorNum  = 0;
            ic.Server = "192.168.0.126:9999";

            watch.Reset();
            watch.Start();
            for (int i = 0; i < 3000; i++)
            {
                var guid = Guid.NewGuid().ToString();
                ic.Set(guid, guid);
                var tmp = ic.Get <string>(guid);
                if (tmp != guid)
                {
                    errorNum += 1;
                }
            }

            watch.Stop();
            Console.WriteLine($"NewLife.Redis 总共耗时:{watch.ElapsedMilliseconds} ms,错误次数 {errorNum}");
        }