示例#1
0
        public void ClientKillTest()
        {
            var reply1 = "+OK\r\n";
            var reply2 = ":1\r\n";
            using(var mock = new MockConnector("localhost", 9999, reply1, reply2, reply2, reply2, reply2, reply2))
            using(var redis = new RedisClient(mock))
            {
                Assert.True(redis.ClientKill("1.1.1.1", 9999));
                Assert.Equal("*3\r\n$6\r\nCLIENT\r\n$4\r\nKILL\r\n$12\r\n1.1.1.1:9999\r\n", mock.GetMessage());

                Assert.Equal(1, redis.ClientKill(addr: "1.1.1.1:9999"));
                Assert.Equal("*4\r\n$6\r\nCLIENT\r\n$4\r\nKILL\r\n$4\r\nADDR\r\n$12\r\n1.1.1.1:9999\r\n", mock.GetMessage());

                Assert.Equal(1, redis.ClientKill(id: "123"));
                Assert.Equal("*4\r\n$6\r\nCLIENT\r\n$4\r\nKILL\r\n$2\r\nID\r\n$3\r\n123\r\n", mock.GetMessage());

                Assert.Equal(1, redis.ClientKill(type: "normal"));
                Assert.Equal("*4\r\n$6\r\nCLIENT\r\n$4\r\nKILL\r\n$4\r\nTYPE\r\n$6\r\nnormal\r\n", mock.GetMessage());

                Assert.Equal(1, redis.ClientKill(skipMe: true));
                Assert.Equal("*4\r\n$6\r\nCLIENT\r\n$4\r\nKILL\r\n$6\r\nSKIPME\r\n$3\r\nyes\r\n", mock.GetMessage());

                Assert.Equal(1, redis.ClientKill(skipMe: false));
                Assert.Equal("*4\r\n$6\r\nCLIENT\r\n$4\r\nKILL\r\n$6\r\nSKIPME\r\n$2\r\nno\r\n", mock.GetMessage());
            }
        }
示例#2
0
        public void TestHGetAll()
        {
            using(var mock = new MockConnector("localhost", 9999, "*2\r\n$6\r\nfield1\r\n$5\r\ntest1\r\n"))
            using(var redis = new RedisClient(mock))
            {
                var response = redis.HGetAll("test");
                Assert.Equal(1, response.Length);
                Assert.Equal("field1", response[0].Field);
                Assert.Equal("test1", (string)response[0].Value);
                Assert.Equal("*2\r\n$7\r\nHGETALL\r\n$4\r\ntest\r\n", mock.GetMessage());
            }

            this.RealCall(redis =>
            {
                redis.HSet("test", "field1", "value1");
                redis.HSet("test", "field2", "value2");

                var response = redis.HGetAll("test");
                Assert.Equal(2, response.Length);
                for(int i = 0; i < 2; i++)
                {
                    Assert.Equal("field" + (i + 1), response[i].Field);
                    Assert.Equal("value" + (i + 1), (string)response[i].Value);
                }
            });
        }
示例#3
0
 public void ScriptLoadTest()
 {
     using(var mock = new MockConnector("localhost", 9999, "$8\r\nchecksum\r\n"))
     using(var redis = new RedisClient(mock))
     {
         Assert.Equal("checksum", redis.ScriptLoad("return 1"));
         Assert.Equal("*3\r\n$6\r\nSCRIPT\r\n$4\r\nLOAD\r\n$8\r\nreturn 1\r\n", mock.GetMessage());
     }
 }
示例#4
0
 public void ScriptKillTest()
 {
     using(var mock = new MockConnector("localhost", 9999, "+OK\r\n"))
     using(var redis = new RedisClient(mock))
     {
         Assert.True(redis.ScriptKill());
         Assert.Equal("*2\r\n$6\r\nSCRIPT\r\n$4\r\nKILL\r\n", mock.GetMessage());
     }
 }
示例#5
0
 public void TestZAdd_Array()
 {
     using(var mock = new MockConnector("localhost", 9999, ":2\r\n"))
     using(var redis = new RedisClient(mock))
     {
         Assert.Equal(2, redis.ZAdd("test", new RedisScoreItem(1.1, "test1"), new RedisScoreItem(2.2, "test2")));
         Assert.Equal("*6\r\n$4\r\nZADD\r\n$4\r\ntest\r\n$3\r\n1.1\r\n$5\r\ntest1\r\n$3\r\n2.2\r\n$5\r\ntest2\r\n", mock.GetMessage());
     }
 }
示例#6
0
 public void SelectTest()
 {
     using(var mock = new MockConnector("localhost", 9999, "+OK\r\n"))
     using(var redis = new RedisClient(mock))
     {
         Assert.True( redis.Select(2));
         Assert.Equal("*2\r\n$6\r\nSELECT\r\n$1\r\n2\r\n", mock.GetMessage());
     }
 }
示例#7
0
 public void TestZCard()
 {
     using(var mock = new MockConnector("localhost", 9999, ":2\r\n"))
     using(var redis = new RedisClient(mock))
     {
         Assert.Equal(2, redis.ZCard("test"));
         Assert.Equal("*2\r\n$5\r\nZCARD\r\n$4\r\ntest\r\n", mock.GetMessage());
     }
 }
示例#8
0
 public void AppendTest()
 {
     using(var mock = new MockConnector("localhost", 9999, ":10\r\n"))
     using(var redis = new RedisClient(mock))
     {
         Assert.Equal(10, redis.Append("key", "x"));
         Assert.Equal("*3\r\n$6\r\nAPPEND\r\n$3\r\nkey\r\n$1\r\nx\r\n", mock.GetMessage());
     }
 }
示例#9
0
 public void GetSetTest()
 {
     using(var mock = new MockConnector("localhost", 9999, "$5\r\nhello\r\n"))
     using(var redis = new RedisClient(mock))
     {
         Assert.Equal("hello", (string)redis.GetSet("key", "new"));
         Assert.Equal("*3\r\n$6\r\nGETSET\r\n$3\r\nkey\r\n$3\r\nnew\r\n", mock.GetMessage());
     }
 }
示例#10
0
 public void IncrTest()
 {
     using(var mock = new MockConnector("localhost", 9999, ":5\r\n"))
     using(var redis = new RedisClient(mock))
     {
         Assert.Equal(5, redis.IncrBy("key"));
         Assert.Equal("*2\r\n$4\r\nINCR\r\n$3\r\nkey\r\n", mock.GetMessage());
     }
 }
示例#11
0
 public void DecrByTest()
 {
     using(var mock = new MockConnector("localhost", 9999, ":10\r\n"))
     using(var redis = new RedisClient(mock))
     {
         Assert.Equal(10, redis.DecrBy("key", 5));
         Assert.Equal("*3\r\n$6\r\nDECRBY\r\n$3\r\nkey\r\n$1\r\n5\r\n", mock.GetMessage());
     }
 }
示例#12
0
 public void ClientGetNameTest()
 {
     using(var mock = new MockConnector("localhost", 9999, "$6\r\nmyname\r\n"))
     using(var redis = new RedisClient(mock))
     {
         Assert.Equal("myname", redis.ClientGetName());
         Assert.Equal("*2\r\n$6\r\nCLIENT\r\n$7\r\nGETNAME\r\n", mock.GetMessage());
     }
 }
示例#13
0
 public void AuthTest()
 {
     using(var mock = new MockConnector("localhost", 9999, "+OK\r\n", "+OK\r\n"))
     using(var redis = new RedisClient(mock, "my password"))
     {
         redis._connector.Connect();
         Assert.Equal("*2\r\n$4\r\nAUTH\r\n$11\r\nmy password\r\n", mock.GetMessage());
     }
 }
示例#14
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());
     }
 }
示例#15
0
 public void QuitTest()
 {
     using(var mock = new MockConnector("localhost", 9999, "+OK\r\n"))
     using(var redis = new RedisClient(mock))
     {
         Assert.True(redis.Quit());
         Assert.Equal("*1\r\n$4\r\nQUIT\r\n", mock.GetMessage());
     }
 }
示例#16
0
 public void TestZIncrby()
 {
     using(var mock = new MockConnector("localhost", 9999, "$4\r\n3.14\r\n"))
     using(var redis = new RedisClient(mock))
     {
         Assert.Equal(3.14, redis.ZIncrBy("test", 1.5, "test1"));
         Assert.Equal("*4\r\n$7\r\nZINCRBY\r\n$4\r\ntest\r\n$3\r\n1.5\r\n$5\r\ntest1\r\n", mock.GetMessage());
     }
 }
示例#17
0
 public void BgRewriteAofTest()
 {
     using(var mock = new MockConnector("localhost", 9999, "+OK\r\n"))
     using(var redis = new RedisClient(mock))
     {
         Assert.True(redis.BgRewriteAof());
         Assert.Equal("*1\r\n$12\r\nBGREWRITEAOF\r\n", mock.GetMessage());
     }
 }
示例#18
0
 public void PingTest()
 {
     using(var mock = new MockConnector("localhost", 9999, "+PONG\r\n"))
     using(var redis = new RedisClient(mock))
     {
         Assert.True(redis.Ping());
         Assert.Equal("*1\r\n$4\r\nPING\r\n", mock.GetMessage());
     }
 }
示例#19
0
 public void TestSAdd()
 {
     using(var mock = new MockConnector("localhost", 9999, ":3\r\n"))
     using(var redis = new RedisClient(mock))
     {
         Assert.Equal(3, redis.SAdd("test", "test1"));
         Assert.Equal("*3\r\n$4\r\nSADD\r\n$4\r\ntest\r\n$5\r\ntest1\r\n", mock.GetMessage());
     }
 }
示例#20
0
 public void TestSIsMember()
 {
     using(var mock = new MockConnector("localhost", 9999, ":1\r\n"))
     using(var redis = new RedisClient(mock))
     {
         Assert.True(redis.SIsMember("test", "test1"));
         Assert.Equal("*3\r\n$9\r\nSISMEMBER\r\n$4\r\ntest\r\n$5\r\ntest1\r\n", mock.GetMessage());
     }
 }
示例#21
0
 public void TestSInterStore()
 {
     using(var mock = new MockConnector("localhost", 9999, ":3\r\n"))
     using(var redis = new RedisClient(mock))
     {
         Assert.Equal(3, redis.SInterStore("destination", "key1", "key2"));
         Assert.Equal("*4\r\n$11\r\nSINTERSTORE\r\n$11\r\ndestination\r\n$4\r\nkey1\r\n$4\r\nkey2\r\n", mock.GetMessage());
     }
 }
示例#22
0
 public void BgSaveTest()
 {
     using(var mock = new MockConnector("localhost", 9999, "+OK\r\n"))
     using(var redis = new RedisClient(mock))
     {
         Assert.True(redis.BgSave());
         Assert.Equal("*1\r\n$6\r\nBGSAVE\r\n", mock.GetMessage());
     }
 }
示例#23
0
 public void GetRangeTest()
 {
     using(var mock = new MockConnector("localhost", 9999, "$5\r\nhello\r\n"))
     using(var redis = new RedisClient(mock))
     {
         Assert.Equal("hello", (string)redis.GetRange("key", 0, 10));
         Assert.Equal("*4\r\n$8\r\nGETRANGE\r\n$3\r\nkey\r\n$1\r\n0\r\n$2\r\n10\r\n", mock.GetMessage());
     }
 }
示例#24
0
 public void ClientSetNameTest()
 {
     string reply = "+OK\r\n";
     using(var mock = new MockConnector("localhost", 9999, reply, reply))
     using(var redis = new RedisClient(mock))
     {
         Assert.True(redis.ClientSetName("myname"));
         Assert.Equal("*3\r\n$6\r\nCLIENT\r\n$7\r\nSETNAME\r\n$6\r\nmyname\r\n", mock.GetMessage());
     }
 }
示例#25
0
        public void ExecTests()
        {
            var okReply = "+OK\r\n";
            using(var mock = new MockConnector("localhost", 9999, okReply, "+QUEUED\r\n", "+QUEUED\r\n", "*2\r\n" + okReply + okReply))
            using(var redis = new RedisClient(mock))
            {
                int x = 0;
                using(var tran = redis.BeginTransaction())
                {
                    Assert.Equal("*1\r\n$5\r\nMULTI\r\n", mock.GetMessage());
                    tran.On(tran.Set("key1", "value1"), r =>
                    {
                        Assert.True(r);
                        x += 1;
                    });
                    Assert.Equal("*3\r\n$3\r\nSET\r\n$4\r\nkey1\r\n$6\r\nvalue1\r\n", mock.GetMessage());
                    tran.On(tran.Set("key2", "value2"), r =>
                    {
                        Assert.True(r);
                        Assert.Equal(1, x);
                        x += 2;
                    });
                    Assert.Equal("*3\r\n$3\r\nSET\r\n$4\r\nkey2\r\n$6\r\nvalue2\r\n", mock.GetMessage());
                    tran.Commit();
                    Assert.Equal("*1\r\n$4\r\nEXEC\r\n", mock.GetMessage());
                }
                Assert.Equal(string.Empty, mock.GetMessage());
                Assert.Equal(3, x);
            }

            this.RealCall(redis =>
            {
                int x = 0;
                using(var tran = redis.BeginTransaction())
                {
                    tran.On(tran.Set("key1", "value1"), r =>
                    {
                        Assert.True(r);
                        x += 1;
                    });
                    tran.On(tran.Set("key2", "value2"), r =>
                    {
                        Assert.True(r);
                        Assert.Equal(1, x);
                        x += 2;
                    });
                    tran.Commit();
                }
                Assert.Equal(3, x);

                Assert.Equal("value1", (string)redis.Get("key1"));
                Assert.Equal("value2", (string)redis.Get("key2"));
            });
        }
示例#26
0
        public void MyTestMethod3()
        {
            using(var mock = new MockConnector("localhost", 9999, "+OK\r\n", "+OK\r\n"))
            using(var redis = new RedisClient(mock))
            {
                Assert.True(redis.Set("key", "value"));
                Assert.Equal("*3\r\n$3\r\nSET\r\n$3\r\nkey\r\n$5\r\nvalue\r\n", mock.GetMessage());

                Assert.True(redis.Set("key", "value"));
                Assert.Equal("*3\r\n$3\r\nSET\r\n$3\r\nkey\r\n$5\r\nvalue\r\n", mock.GetMessage());
            }
        }
示例#27
0
 public void TestInter()
 {
     using(var mock = new MockConnector("localhost", 9999, "*2\r\n$5\r\ntest1\r\n$5\r\ntest2\r\n"))
     using(var redis = new RedisClient(mock))
     {
         var response = redis.SInter("test", "another");
         Assert.Equal(2, response.Length);
         Assert.Equal("test1", (string)response[0]);
         Assert.Equal("test2", (string)response[1]);
         Assert.Equal("*3\r\n$6\r\nSINTER\r\n$4\r\ntest\r\n$7\r\nanother\r\n", mock.GetMessage());
     }
 }
示例#28
0
 public void MultiTest()
 {
     var okReply = "+OK\r\n";
     using(var mock = new MockConnector("localhost", 9999, okReply, okReply))
     using(var redis = new RedisClient(mock))
     {
         using(var tran = redis.BeginTransaction())
         {
             Assert.Equal("*1\r\n$5\r\nMULTI\r\n", mock.GetMessage());
         }
     }
 }
示例#29
0
 public void PfAddTest()
 {
     using(var mock = new MockConnector("localhost", 9999, ":1\r\n"))
     using(var redis = new RedisClient(mock))
     {
         Assert.True(redis.PFAdd("test", "test1", "test2"));
         Assert.Equal("*4\r\n$5\r\nPFADD\r\n$4\r\ntest\r\n$5\r\ntest1\r\n$5\r\ntest2\r\n", mock.GetMessage());
     }
     this.RealCall(redis =>
     {
         Assert.True(redis.PFAdd("key1", "value1", "value2"));
     });
 }
示例#30
0
        public void ScriptExistsTests()
        {
            using(var mock = new MockConnector("localhost", 9999, "*2\r\n:1\r\n:0\r\n"))
            using(var redis = new RedisClient(mock))
            {
                var response = redis.ScriptExists("checksum1", "checksum2");
                Assert.Equal(2, response.Length);
                Assert.True(response[0]);
                Assert.False(response[1]);

                Assert.Equal("*4\r\n$6\r\nSCRIPT\r\n$6\r\nEXISTS\r\n$9\r\nchecksum1\r\n$9\r\nchecksum2\r\n", mock.GetMessage());
            }
        }
示例#31
0
        public void TestZInterStore()
        {
            string reply = ":2\r\n";

            using (var mock = new MockConnector("localhost", 9999, reply, reply, reply, reply, reply))
                using (var redis = new RedisClient(mock))
                {
                    Assert.Equal(2, redis.ZInterStore("destination", new RedisWeightDictionary("key1", "key2")));
                    Assert.Equal("*5\r\n$11\r\nZINTERSTORE\r\n$11\r\ndestination\r\n$1\r\n2\r\n$4\r\nkey1\r\n$4\r\nkey2\r\n", mock.GetMessage());

                    var dict = new RedisWeightDictionary(new[] { "key1", "key2" }, new[] { 1D, 2D });
                    Assert.Equal(2, redis.ZInterStore("destination", dict));
                    Assert.Equal("*8\r\n$11\r\nZINTERSTORE\r\n$11\r\ndestination\r\n$1\r\n2\r\n$4\r\nkey1\r\n$4\r\nkey2\r\n$7\r\nWEIGHTS\r\n$1\r\n1\r\n$1\r\n2\r\n", mock.GetMessage());

                    Assert.Equal(2, redis.ZInterStore("destination", dict, RedisAggregate.Max));
                    Assert.Equal("*10\r\n$11\r\nZINTERSTORE\r\n$11\r\ndestination\r\n$1\r\n2\r\n$4\r\nkey1\r\n$4\r\nkey2\r\n$7\r\nWEIGHTS\r\n$1\r\n1\r\n$1\r\n2\r\n$9\r\nAGGREGATE\r\n$3\r\nMAX\r\n", mock.GetMessage());

                    Assert.Equal(2, redis.ZInterStore("destination", dict, RedisAggregate.Min));
                    Assert.Equal("*10\r\n$11\r\nZINTERSTORE\r\n$11\r\ndestination\r\n$1\r\n2\r\n$4\r\nkey1\r\n$4\r\nkey2\r\n$7\r\nWEIGHTS\r\n$1\r\n1\r\n$1\r\n2\r\n$9\r\nAGGREGATE\r\n$3\r\nMIN\r\n", mock.GetMessage());

                    Assert.Equal(2, redis.ZInterStore("destination", dict, RedisAggregate.Sum));
                    Assert.Equal("*10\r\n$11\r\nZINTERSTORE\r\n$11\r\ndestination\r\n$1\r\n2\r\n$4\r\nkey1\r\n$4\r\nkey2\r\n$7\r\nWEIGHTS\r\n$1\r\n1\r\n$1\r\n2\r\n$9\r\nAGGREGATE\r\n$3\r\nSUM\r\n", mock.GetMessage());
                }
        }