Exemplo n.º 1
0
        public static void SendFromNewSocketRedis3(NewRedisClient3 client, IDatabase sedb)
        {
            var       tasks = new Task[100000];
            Stopwatch sw    = new Stopwatch();

            sw.Start();
            for (var a = 0; a < 100000; a += 1)
            {
                tasks[a] = Task.Run(async() =>
                {
                    var key    = a.ToString();
                    var result = await client.SetAsync(key, key);
                    if (!result)
                    {
                        throw new Exception("not equal");
                    }
                    //var val = await sedb.StringGetAsync(key); //valid
                    //if (val != key) throw new Exception("not equal");
                });
            }
            Task.WaitAll(tasks);
            sw.Stop();
            Console.WriteLine("NewRedisClient3(0-100000): " + sw.ElapsedMilliseconds + "ms");
            //client.Dispose();
        }
Exemplo n.º 2
0
        private static void InitClient()
        {
            //_useDelay = true;
            _delayCount = 3000;
            //Notice : Please use "//" comment "/*".

            ///*
            using (StreamReader stream = new StreamReader("Redis.rsf"))
            {
                ip   = stream.ReadLine();
                port = int.Parse(stream.ReadLine());
                //pwd = stream.ReadLine();
            }//*/

            /*
             * ip = "127.0.0.1";
             * port = 6379;
             * //*/

            // NewLife.Redis
            // _newLifeRedis = new NewLife.Caching.Redis($"{ip}:{port}",null, 1);
            //var result = newLifeRedis.Set("1", "1");
            //Console.WriteLine(result);
            //Console.ReadKey();
            //_beetleClient = new BeetleX.Redis.RedisDB(0);
            //var host = _beetleClient.Host.AddWriteHost(ip, port);
            //host.MaxConnections = 1000;
            //host.QueueMaxLength = 512;
            //_freeRedisClient = new RedisClient($"{ip}:{port},database=0,min pool size=100");
            //_redisClient0 = new NewRedisClient0(ip, port);

            _pool4        = new ClientPool1 <NewRedisClient4>(ip, port);
            _pool5        = new ClientPool1 <NewRedisClient5>(ip, port);
            _pool7        = new ClientPool1 <NewRedisClient7>(ip, port);
            _pool27       = new ClientPool2 <NewRedisClient7>(ip, port);
            _pool25       = new ClientPool2 <NewRedisClient5>(ip, port);
            _pool24       = new ClientPool2 <NewRedisClient4>(ip, port);
            _redisClient1 = new NewRedisClient1(ip, port);
            _redisClient2 = new NewRedisClient2(ip, port);
            _redisClient3 = new NewRedisClient3(ip, port);
            _redisClient4 = _pool4._node;
            _redisClient5 = _pool5._node;
            _redisClient7 = _pool7._node;
            _redisClient8 = new NewRedisClient8();
            _redisClient8.CreateConnection(ip, port);
            _redisClient9 = new NewRedisClient9();
            _redisClient9.CreateConnection(ip, port);
            //_redisClient5.SetAsync("a", "a");
            ConnectionMultiplexer seredis = ConnectionMultiplexer.Connect($"{ip}:{port}");

            _stackExnchangeClient = seredis.GetDatabase(0);
        }
Exemplo n.º 3
0
        private static void InitClient()
        {
            //Notice : Please use "//" comment "/*".

            ///*
            using (StreamReader stream = new StreamReader("Redis.rsf"))
            {
                ip   = stream.ReadLine();
                port = int.Parse(stream.ReadLine());
                //pwd = stream.ReadLine();
            }//*/

            /*
             * ip = "127.0.0.1";
             * port = 6379;
             * //*/
            _freeRedisClient = new RedisClient($"{ip}:{port},database=15,min pool size=100");
            _redisClient3    = new NewRedisClient3(ip, port);
            _redisClient4    = new NewRedisClient4(ip, port);
            ConnectionMultiplexer seredis = ConnectionMultiplexer.Connect("127.0.0.1:6379");

            _stackExnchangeClient = seredis.GetDatabase(1);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            //using (StreamReader stream = new StreamReader("Redis.rsf"))
            //{
            //    ip = stream.ReadLine();
            //    port = int.Parse(stream.ReadLine());
            //    //pwd = stream.ReadLine();
            //}
            ip   = "127.0.0.1";
            port = 6379;
            var endpoit = new IPEndPoint(IPAddress.Parse(ip), port);

            //NewRedisClient2 client = new NewRedisClient2(endpoit);
            //TestClient2(client);
            NewRedisClient3 client3 = new NewRedisClient3(endpoit);
            //TestClient3(client3);
            NewRedisClient4 client4 = new NewRedisClient4(endpoit);
            //TestClient3(client3);
            //TestClient2(client);
            //new
            //NewRedisClient client = new NewRedisClient(endpoit);
            //var result = client.SelectDB(0).Result;

            //client.Set("test01", "123123").Wait();

            //FreeRedis
            var redisClient = new RedisClient($"{ip}:{port},database=15,min pool size=100");

            //StackExchange
            ConnectionMultiplexer seredis = ConnectionMultiplexer.Connect("127.0.0.1:6379");
            IDatabase             sedb    = seredis.GetDatabase(1);

            redisClient.FlushDb();
            SendFromFreeRedis(redisClient);
            redisClient.FlushDb();
            SendFromStackExchangeRedis(sedb);
            redisClient.FlushDb();
            SendFromNewSocketRedis3(client3, sedb);
            redisClient.FlushDb();
            SendFromNewSocketRedis4(client4, sedb);
            Console.WriteLine("====== 以上预热 =======");
            //seredis.get
            //SendFromNewSocketRedis2(client, seredis.GetDatabase(0));
            redisClient.FlushDb();
            SendFromFreeRedis(redisClient);
            redisClient.FlushDb();
            SendFromStackExchangeRedis(sedb);
            redisClient.FlushDb();
            SendFromNewSocketRedis3(client3, sedb);
            redisClient.FlushDb();
            SendFromNewSocketRedis4(client4, sedb);
            //redisClient.FlushDb();
            //SendFromFreeRedis(redisClient);
            ////SendFromNewSocketRedis(client, seredis.GetDatabase(0));
            //SendFromStackExchangeRedis(sedb);

            //_sendQueue = new ConcurrentQueue<TaskWithBytes>();
            //_receiverQueue = new ConcurrentQueue<TaskCompletionSource<bool>>();

            ////NewSocketTest(endpoit);
            ////result = client.Set("newRedis", "natasha").Result;
            ////Console.WriteLine(result);
            //Server(endpoit);
            //Test(endpoit);
            //Task.Run(async () =>
            //{
            //    await Task.Delay(5000);
            //    Console.WriteLine();
            //    Console.WriteLine(_sendQueue.Count);
            //    Console.WriteLine(_receiverQueue.Count);

            //});
            Console.ReadKey();
        }
Exemplo n.º 5
0
        public static async void TestClient3(NewRedisClient3 client)
        {
            var result = await client.SetAsync("1", "1");

            Console.WriteLine(result);
        }