C# redis StackExchange

1.Install-Package StackExchange -v 2.0.601

2.using StackExchange.Redis;

3.

static  void StackExchangeRedisDemo()
        {
            using(ConnectionMultiplexer redis=ConnectionMultiplexer.Connect("localhost,allowAdmin=true"))
            {
                var endPoint = redis.GetEndPoints().FirstOrDefault();
                var redisServer = redis.GetServer(endPoint);
                redisServer.FlushDatabase();
                IDatabase db = redis.GetDatabase(0);             
                
                DateTime dt = DateTime.Now;
                DateTime dtEnd = dt.AddSeconds(60);

                int num = 0; 
                List<string> keysList = new List<string>();
                while (DateTime.Now<dtEnd)
                {
                    num++;
                    string redisKey = Guid.NewGuid().ToString();
                    keysList.Add(redisKey);
                    db.StringSetAsync(redisKey, Guid.NewGuid().ToString());
                }
                ThreadPool.SetMinThreads(200, 200);
                System.Diagnostics.Debug.WriteLine($"redisServer.Keys().Count():{redisServer.Keys().Count()}\n,num:{num}");
            }
        }

 

posted @ 2019-11-19 21:32  FredGrit  阅读(208)  评论(0编辑  收藏  举报