Esempio n. 1
0
        public void ClientKillTest()
        {
            var reply1 = "+OK\r\n";
            var reply2 = ":1\r\n";
            using (var mock = new FakeRedisSocket(reply1, reply2, reply2, reply2, reply2, reply2))
            using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
            {
                Assert.AreEqual("OK", redis.ClientKill("1.1.1.1", 9999));
                Assert.AreEqual("*4\r\n$6\r\nCLIENT\r\n$4\r\nKILL\r\n$7\r\n1.1.1.1\r\n$4\r\n9999\r\n", mock.GetMessage());

                Assert.AreEqual(1, redis.ClientKill(addr: "1.1.1.1:9999"));
                Assert.AreEqual("*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.AreEqual(1, redis.ClientKill(id: "123"));
                Assert.AreEqual("*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.AreEqual(1, redis.ClientKill(type: "normal"));
                Assert.AreEqual("*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.AreEqual(1, redis.ClientKill(skipMe: true));
                Assert.AreEqual("*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.AreEqual(1, redis.ClientKill(skipMe: false));
                Assert.AreEqual("*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());
            }
        }
Esempio n. 2
0
 public void BgSaveTest()
 {
     using (var mock = new FakeRedisSocket("+OK\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.AreEqual("OK", redis.BgSave());
         Assert.AreEqual("*1\r\n$6\r\nBGSAVE\r\n", mock.GetMessage());
     }
 }
Esempio n. 3
0
 public void BgRewriteAofTest()
 {
     using (var mock = new FakeRedisSocket("+OK\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.AreEqual("OK", redis.BgRewriteAof());
         Assert.AreEqual("*1\r\n$12\r\nBGREWRITEAOF\r\n", mock.GetMessage());
     }
 }
Esempio n. 4
0
 public void TestSInterStore()
 {
     using (var mock = new FakeRedisSocket(":3\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.AreEqual(3, redis.SInterStore("destination", "key1", "key2"));
         Assert.AreEqual("*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());
     }
 }
Esempio n. 5
0
 public void TestSAdd()
 {
     using (var mock = new FakeRedisSocket(":3\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.AreEqual(3, redis.SAdd("test", "test1"));
         Assert.AreEqual("*3\r\n$4\r\nSADD\r\n$4\r\ntest\r\n$5\r\ntest1\r\n", mock.GetMessage());
     }
 }
Esempio n. 6
0
 public void WatchTest()
 {
     using (var mock = new FakeRedisSocket("+OK\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.AreEqual("OK", redis.Watch());
         Assert.AreEqual("*1\r\n$5\r\nWATCH\r\n", mock.GetMessage());
     }
 }
Esempio n. 7
0
 public void DiscardTest()
 {
     using (var mock = new FakeRedisSocket("+OK\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.AreEqual("OK", redis.Discard());
         Assert.AreEqual("*1\r\n$7\r\nDISCARD\r\n", mock.GetMessage());
     }
 }
Esempio n. 8
0
 public void PfMergeTest()
 {
     using (var mock = new FakeRedisSocket("+OK\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.AreEqual("OK", redis.PfMerge("destination", "source1", "source2"));
         Assert.AreEqual("*4\r\n$7\r\nPFMERGE\r\n$11\r\ndestination\r\n$7\r\nsource1\r\n$7\r\nsource2\r\n", mock.GetMessage());
     }
 }
Esempio n. 9
0
 public void ClientGetNameTest()
 {
     using (var mock = new FakeRedisSocket("$6\r\nmyname\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.AreEqual("myname", redis.ClientGetName());
         Assert.AreEqual("*2\r\n$6\r\nCLIENT\r\n$7\r\nGETNAME\r\n", mock.GetMessage());
     }
 }
Esempio n. 10
0
 public void TestHGet()
 {
     using (var mock = new FakeRedisSocket("$4\r\ntest\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.AreEqual("test", redis.HGet("test", "field"));
         Assert.AreEqual("*3\r\n$4\r\nHGET\r\n$4\r\ntest\r\n$5\r\nfield\r\n", mock.GetMessage());
     }
 }
Esempio n. 11
0
 public void ScriptKillTest()
 {
     using (var mock = new FakeRedisSocket("+OK\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.AreEqual("OK", redis.ScriptKill());
         Assert.AreEqual("*2\r\n$6\r\nSCRIPT\r\n$4\r\nKILL\r\n", mock.GetMessage());
     }
 }
Esempio n. 12
0
 public void TestHExists()
 {
     using (var mock = new FakeRedisSocket(":1\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.IsTrue(redis.HExists("test", "field"));
         Assert.AreEqual("*3\r\n$7\r\nHEXISTS\r\n$4\r\ntest\r\n$5\r\nfield\r\n", mock.GetMessage());
     }
 }
Esempio n. 13
0
 public void PfCountTest()
 {
     using (var mock = new FakeRedisSocket(":2\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.AreEqual(2, redis.PfCount("test1", "test2"));
         Assert.AreEqual("*3\r\n$7\r\nPFCOUNT\r\n$5\r\ntest1\r\n$5\r\ntest2\r\n", mock.GetMessage());
     }
 }
Esempio n. 14
0
 public void TestHDel()
 {
     using (var mock = new FakeRedisSocket(":2\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.AreEqual(2, redis.HDel("test", "test1", "test2"));
         Assert.AreEqual("*4\r\n$4\r\nHDEL\r\n$4\r\ntest\r\n$5\r\ntest1\r\n$5\r\ntest2\r\n", mock.GetMessage());
     }
 }
Esempio n. 15
0
 public void TestDump()
 {
     using (var mock = new FakeRedisSocket("$4\r\ntest\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.AreEqual("test", redis.Encoding.GetString(redis.Dump("test")));
         Assert.AreEqual("*2\r\n$4\r\nDUMP\r\n$4\r\ntest\r\n", mock.GetMessage());
     }
 }
Esempio n. 16
0
 public void TestZIncrby()
 {
     using (var mock = new FakeRedisSocket("$4\r\n3.14\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.AreEqual(3.14, redis.ZIncrBy("test", 1.5, "test1"));
         Assert.AreEqual("*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());
     }
 }
Esempio n. 17
0
 public void PfAddTest()
 {
     using (var mock = new FakeRedisSocket(":1\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.IsTrue(redis.PfAdd("test", "test1", "test2"));
         Assert.AreEqual("*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());
     }
 }
Esempio n. 18
0
 public void TestZAdd_Tuple()
 {
     using (var mock = new FakeRedisSocket(":2\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.AreEqual(2, redis.ZAdd("test", Tuple.Create(1.1, "test1"), Tuple.Create(2.2, "test2")));
         Assert.AreEqual("*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());
     }
 }
Esempio n. 19
0
 public void TestZCard()
 {
     using (var mock = new FakeRedisSocket(":2\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.AreEqual(2, redis.ZCard("test"));
         Assert.AreEqual("*2\r\n$5\r\nZCARD\r\n$4\r\ntest\r\n", mock.GetMessage());
     }
 }
Esempio n. 20
0
 public void AppendTest()
 {
     using (var mock = new FakeRedisSocket(":10\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.AreEqual(10, redis.Append("key", "x"));
         Assert.AreEqual("*3\r\n$6\r\nAPPEND\r\n$3\r\nkey\r\n$1\r\nx\r\n", mock.GetMessage());
     }
 }
Esempio n. 21
0
 public void DecrTest()
 {
     using (var mock = new FakeRedisSocket(":10\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.AreEqual(10, redis.Decr("key"));
         Assert.AreEqual("*2\r\n$4\r\nDECR\r\n$3\r\nkey\r\n", mock.GetMessage());
     }
 }
Esempio n. 22
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());
     }
 }
Esempio n. 23
0
 public void PublishTest()
 {
     using (var mock = new FakeRedisSocket(":3\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.AreEqual(3, redis.Publish("test", "message"));
         Assert.AreEqual("*3\r\n$7\r\nPUBLISH\r\n$4\r\ntest\r\n$7\r\nmessage\r\n", mock.GetMessage());
     }
 }
Esempio n. 24
0
 public void TestDel()
 {
     using (var mock = new FakeRedisSocket(":3\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.AreEqual(3, redis.Del("test"));
         Assert.AreEqual("*2\r\n$3\r\nDEL\r\n$4\r\ntest\r\n", mock.GetMessage());
     }
 }
Esempio n. 25
0
 public void TestHIncrBy()
 {
     using (var mock = new FakeRedisSocket(":5\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.AreEqual(5, redis.HIncrBy("test", "field", 1));
         Assert.AreEqual("*4\r\n$7\r\nHINCRBY\r\n$4\r\ntest\r\n$5\r\nfield\r\n$1\r\n1\r\n", mock.GetMessage());
     }
 }
Esempio n. 26
0
 public void TestHGetAll_Generic()
 {
     using (var mock = new FakeRedisSocket("*2\r\n$6\r\nfield1\r\n$5\r\ntest1\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         var response = redis.HGetAll<MyGeneric>("test");
         Assert.AreEqual("test1", response.field1);
         Assert.AreEqual("*2\r\n$7\r\nHGETALL\r\n$4\r\ntest\r\n", mock.GetMessage());
     }
 }
Esempio n. 27
0
 public void TestKeys()
 {
     using (var mock = new FakeRedisSocket("*3\r\n$5\r\ntest1\r\n$5\r\ntest2\r\n$5\r\ntest3\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         var response = redis.Keys("test*");
         Assert.AreEqual(3, response.Length);
         for (int i = 0; i < response.Length; i++)
             Assert.AreEqual("test" + (i + 1), response[i]);
     }
 }
Esempio n. 28
0
 public void TestExpire()
 {
     using (var mock = new FakeRedisSocket(":1\r\n", ":0\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.IsTrue(redis.Expire("test1", TimeSpan.FromSeconds(10)));
         Assert.AreEqual("*3\r\n$6\r\nEXPIRE\r\n$5\r\ntest1\r\n$2\r\n10\r\n", mock.GetMessage());
         Assert.IsFalse(redis.Expire("test2", 20));
         Assert.AreEqual("*3\r\n$6\r\nEXPIRE\r\n$5\r\ntest2\r\n$2\r\n20\r\n", mock.GetMessage());
     }
 }
Esempio n. 29
0
 public void TestExists()
 {
     using (var mock = new FakeRedisSocket(":1\r\n", ":0\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.IsTrue(redis.Exists("test1"));
         Assert.AreEqual("*2\r\n$6\r\nEXISTS\r\n$5\r\ntest1\r\n", mock.GetMessage());
         Assert.IsFalse(redis.Exists("test2"));
         Assert.AreEqual("*2\r\n$6\r\nEXISTS\r\n$5\r\ntest2\r\n", mock.GetMessage());
     }
 }
Esempio n. 30
0
 public void ExecTest()
 {
     using (var mock = new FakeRedisSocket("*1\r\n$2\r\nhi\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         var response = redis.Exec();
         Assert.AreEqual(1, response.Length);
         Assert.AreEqual("hi", response[0]);
         Assert.AreEqual("*1\r\n$4\r\nEXEC\r\n", mock.GetMessage());
     }
 }