예제 #1
0
 public static byte[] GetClientList()
 {
     using (RedisClient client = GetClient())
     {
         return(client.ClientList());
     }
 }
예제 #2
0
        static void KeysTest(RedisClient redisClient)
        {
            //var a = redisClient.Auth("yswenli");

            var info = redisClient.Info();

            var serverInfo = redisClient.ServerInfo;

            //redisClient.Select(1);

            var dbsize = redisClient.DBSize();

            redisClient.SlaveOf();

            var pong = redisClient.Ping();

            var clist = redisClient.ClientList();

            var ck = "slowlog-max-len";

            //var cr1 = redisClient.SetConfig(ck, 1000);

            var cr2 = redisClient.GetConfig(ck);

            var t1 = redisClient.GetDataBase().Ttl("zaaa");
            var t2 = redisClient.GetDataBase().Ttl("haa22");
            var t3 = redisClient.GetDataBase().Pttl("key0");
            var t4 = redisClient.GetDataBase().Pttl("akey0");

            var isCluster = redisClient.IsCluster;
        }
예제 #3
0
        static void KeysTest(RedisClient redisClient)
        {
            var a = redisClient.Auth("yswenli");

            var info = redisClient.Info();

            var serverInfo = redisClient.ServerInfo;

            redisClient.Select(1);

            var dbsize = redisClient.DBSize();

            redisClient.SlaveOf();

            var pong = redisClient.Ping();

            var clist = redisClient.ClientList();

            var ck = "slowlog-max-len";

            var cr1 = redisClient.SetConfig(ck, 1000);

            var cr2 = redisClient.GetConfig(ck);

            var isCluster = redisClient.IsCluster;
        }
예제 #4
0
 public void ClientListTest()
 {
     using(var mock = new MockConnector("localhost", 9999, "$291\r\nid=3 addr=127.0.0.1:57656 fd=6 name= age=97 idle=81 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=client\nid=4 addr=127.0.0.1:57663 fd=7 name= age=5 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client\r\n"))
     using(var redis = new RedisClient(mock))
     {
         Assert.Equal("id=3 addr=127.0.0.1:57656 fd=6 name= age=97 idle=81 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=client\nid=4 addr=127.0.0.1:57663 fd=7 name= age=5 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client", redis.ClientList());
         Assert.Equal("*2\r\n$6\r\nCLIENT\r\n$4\r\nLIST\r\n", mock.GetMessage());
     }
 }
예제 #5
0
        void TestRedis()
        {
            var redisOp = RedisOption.BuildRedisOption(ConnectString);

            AppendLine(tb_Output, $"Current RedisOption is {redisOp}");
            var  client = new RedisClient(redisOp);
            bool flag   = client.IsConnected;

            AppendLine(tb_Output, $"Current RedisClient is IsConnected {flag},If False While Try Auth With Password({redisOp.Password})");

            if (!flag && !string.IsNullOrEmpty(redisOp.Password))
            {
                try
                {
                    var authRet = client.Auth(redisOp.Password);
                    AppendLine(tb_Output, $"client.Auth({redisOp.Password})->{authRet} [Success]");
                    flag = true;
                }
                catch (Exception ex)
                {
                    AppendLine(tb_Output, $"client.Auth({redisOp.Password})-> [Failed] Handler Error {ex.Message}\r\n{ex}");
                    flag = false;
                }
            }

            if (!flag)
            {
                return;
            }

            if (redisOp.DefaultDb > 0)
            {
                try
                {
                    var selectRet = client.Select(redisOp.DefaultDb);
                    AppendLine(tb_Output, $"client.Select(db:{redisOp.DefaultDb})->{selectRet} [Success]");
                    flag = true;
                }
                catch (Exception ex)
                {
                    AppendLine(tb_Output, $"client.Select(db:{redisOp.DefaultDb}) [Failed] Handler Error {ex.Message}\r\n{ex}");
                    flag = false;
                }
            }
            if (!flag)
            {
                return;
            }
            try
            {
                var clientListRet = client.ClientList().Replace("\n", "\r\n");
                AppendLine(tb_Output, $"client.ClientList()->\r\n{clientListRet}  ");
            }
            catch (Exception ex)
            {
                AppendLine(tb_Output, $"client.ClientList() [Failed] Handler Error {ex.Message}\r\n{ex}");
            }
            try
            {
                var clientInfoRet = client.Info();
                AppendLine(tb_Output, $"client.Info()->\r\n{clientInfoRet}");
            }
            catch (Exception ex)
            {
                AppendLine(tb_Output, $"client.Info() [Failed] Handler Error {ex.Message}\r\n{ex}");
            }

            try
            {
                var quitRet = client.Quit();
                AppendLine(tb_Output, $"{ConnectString} Close Success ->{quitRet}");
                flag = true;
            }
            catch (Exception ex)
            {
                AppendLine(tb_Output, $"{ConnectString} Close Handler Error {ex.Message}\r\n{ex}");
                flag = false;
            }
        }
예제 #6
0
파일: Program.cs 프로젝트: jingyiliu/SAEA
        static void Main(string[] args)
        {
            ConsoleHelper.Title = "SAEA.RedisSocketTest";
            ConsoleHelper.WriteLine("输入连接字符串连接RedisServer,格式为\r\nserver=127.0.0.1:6379;passwords=yswenli");

            var cnnStr = ConsoleHelper.ReadLine();

            if (string.IsNullOrEmpty(cnnStr))
            {
                cnnStr = "server=127.0.0.1:6379;passwords=yswenli";
            }
            RedisClient redisClient = new RedisClient(cnnStr, false);

            redisClient.Connect();

            redisClient.Select(1);

            var clist = redisClient.ClientList();


            var ck = "slowlog-max-len";

            var cr1 = redisClient.SetConfig(ck, 1000);

            var cr2 = redisClient.GetConfig(ck);

            var list = redisClient.GetDataBase().LRang("list1", 0, 10);

            //redisClient.GetDataBase().HSet("test", "", "2151");


            //var isCluster = redisClient.IsCluster;

            //var list = redisClient.ClusterNodes;

            var keys = redisClient.GetDataBase().Keys();

            var scan  = redisClient.GetDataBase().Scan();
            var hscan = redisClient.GetDataBase().HScan("haa22", 0);
            var sscan = redisClient.GetDataBase().SScan("aaa", 0);

            redisClient.GetDataBase().ZAdd("zaaa", "!#@%$^&*\r\n()^^%%&%@FSDH\r\n某月霜\r\n/.';lakdsfakdsf", 110);
            var zscan = redisClient.GetDataBase().ZScan("zaaa", 0);

            var zc = redisClient.GetDataBase().ZCount("zaaa");
            var zl = redisClient.GetDataBase().ZLen("zaaa");

            //var r = redisClient.GetDataBase().Rename("aaa", "aaa");

            //var l = redisClient.GetDataBase().LRang("testlist");

            //var z = redisClient.GetDataBase().ZRang("zaaa");

            var h = redisClient.GetDataBase().HGetAll("haa22");

            var t1 = redisClient.GetDataBase().Ttl("zaaa");
            var t2 = redisClient.GetDataBase().Ttl("haa22");
            var t3 = redisClient.GetDataBase().Pttl("key0");
            var t4 = redisClient.GetDataBase().Pttl("akey0");

            //var m = redisClient.ClusterInfo;
            //var n = redisClient.ClusterNodes;
            //var k = redisClient.KeySlot("aaa");
            //var g = redisClient.GetKeysInSlot(0);

            //redisClient.GetDataBase().SRemove("abcd", "12345");

            var info = redisClient.Info();

            var serverInfo = redisClient.ServerInfo;

            var r = redisClient.Console("scan 0");

            if (info.Contains("NOAUTH Authentication required."))
            {
                while (true)
                {
                    ConsoleHelper.WriteLine("请输入redis连接密码");
                    var auth = ConsoleHelper.ReadLine();
                    if (string.IsNullOrEmpty(auth))
                    {
                        auth = "yswenli";
                    }
                    var a = redisClient.Auth(auth);
                    if (a.Contains("OK"))
                    {
                        break;
                    }
                    else
                    {
                        ConsoleHelper.WriteLine(a);
                    }
                }
            }

            //redisClient.SlaveOf();

            var pong = redisClient.Ping();

            //redisClient.Select(1);

            PerformanceTest(redisClient);

            ConsoleHelper.WriteLine(redisClient.Type("key0"));

            ConsoleHelper.WriteLine("dbSize:{0}", redisClient.DBSize().ToString());

            RedisOperationTest(redisClient, true);
            ConsoleHelper.ReadLine();
        }
예제 #7
0
 public void ClientListTest()
 {
     using (var mock = new FakeRedisSocket("$291\r\nid=3 addr=127.0.0.1:57656 fd=6 name= age=97 idle=81 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=client\nid=4 addr=127.0.0.1:57663 fd=7 name= age=5 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client\r\n"))
         using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
         {
             Assert.AreEqual("id=3 addr=127.0.0.1:57656 fd=6 name= age=97 idle=81 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=client\nid=4 addr=127.0.0.1:57663 fd=7 name= age=5 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client", redis.ClientList());
             Assert.AreEqual("*2\r\n$6\r\nCLIENT\r\n$4\r\nLIST\r\n", mock.GetMessage());
         }
 }