示例#1
0
 public void ScriptKillTest()
 {
     using (var mock = new FakeRedisSocket("+OK\r\n"))
         using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
         {
             Assert.Equal("OK", redis.ScriptKill());
             Assert.Equal("*2\r\n$6\r\nSCRIPT\r\n$4\r\nKILL\r\n", mock.GetMessage());
         }
 }
示例#2
0
 public void TestHLen()
 {
     using (var mock = new FakeRedisSocket(":5\r\n"))
         using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
         {
             Assert.Equal(5, redis.HLen("test"));
             Assert.Equal("*2\r\n$4\r\nHLEN\r\n$4\r\ntest\r\n", mock.GetMessage());
         }
 }
示例#3
0
 public void ConfigRewriteTest()
 {
     using (var mock = new FakeRedisSocket("+OK\r\n"))
         using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
         {
             Assert.Equal("OK", redis.ConfigRewrite());
             Assert.Equal("*2\r\n$6\r\nCONFIG\r\n$7\r\nREWRITE\r\n", mock.GetMessage());
         }
 }
示例#4
0
 public void TestSPop()
 {
     using (var mock = new FakeRedisSocket("$5\r\ntest1\r\n"))
         using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
         {
             Assert.AreEqual("test1", redis.SPop("test"));
             Assert.AreEqual("*2\r\n$4\r\nSPOP\r\n$4\r\ntest\r\n", mock.GetMessage());
         }
 }
示例#5
0
 public void DbSizeTest()
 {
     using (var mock = new FakeRedisSocket(":5\r\n"))
         using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
         {
             Assert.Equal(5, redis.DbSize());
             Assert.Equal("*1\r\n$6\r\nDBSIZE\r\n", mock.GetMessage());
         }
 }
示例#6
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());
         }
 }
示例#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.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());
         }
 }
示例#8
0
 public void SlowLogResetTest()
 {
     using (var mock = new FakeRedisSocket("+OK\r\n"))
         using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
         {
             Assert.Equal("OK", redis.SlowLogReset());
             Assert.Equal("*2\r\n$7\r\nSLOWLOG\r\n$5\r\nRESET\r\n", mock.GetMessage());
         }
 }
示例#9
0
 public void SlaveOfNoOneTest()
 {
     using (var mock = new FakeRedisSocket("+OK\r\n"))
         using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
         {
             Assert.Equal("OK", redis.SlaveOfNoOne());
             Assert.Equal("*3\r\n$7\r\nSLAVEOF\r\n$2\r\nNO\r\n$3\r\nONE\r\n", mock.GetMessage());
         }
 }
示例#10
0
 public void SlowLogLenTest()
 {
     using (var mock = new FakeRedisSocket(":5\r\n"))
         using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
         {
             Assert.Equal(5, redis.SlowLogLen());
             Assert.Equal("*2\r\n$7\r\nSLOWLOG\r\n$3\r\nLEN\r\n", mock.GetMessage());
         }
 }
示例#11
0
 public void SaveTest()
 {
     using (var mock = new FakeRedisSocket("+OK\r\n"))
         using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
         {
             Assert.Equal("OK", redis.Save());
             Assert.Equal("*1\r\n$4\r\nSAVE\r\n", mock.GetMessage());
         }
 }
示例#12
0
 public void LastSaveTest()
 {
     using (var mock = new FakeRedisSocket(":1404861064\r\n"))
         using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
         {
             Assert.Equal(new DateTime(2014, 7, 8, 23, 11, 04, DateTimeKind.Utc), redis.LastSave());
             Assert.Equal("*1\r\n$8\r\nLASTSAVE\r\n", mock.GetMessage());
         }
 }
示例#13
0
 public void FlushDbTest()
 {
     using (var mock = new FakeRedisSocket("+OK\r\n"))
         using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
         {
             Assert.Equal("OK", redis.FlushDb());
             Assert.Equal("*1\r\n$7\r\nFLUSHDB\r\n", mock.GetMessage());
         }
 }
示例#14
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());
         }
 }
示例#15
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.Equal(1, response.Length);
             Assert.Equal("hi", response[0]);
             Assert.Equal("*1\r\n$4\r\nEXEC\r\n", mock.GetMessage());
         }
 }
示例#16
0
 public void ClientGetNameTest()
 {
     using (var mock = new FakeRedisSocket("$6\r\nmyname\r\n"))
     {
         using (var redis = new RedisClient(mock, new DnsEndPoint("localhost", 9999)))
         {
             Assert.Equal("myname", redis.ClientGetName());
             Assert.Equal("*2\r\n$6\r\nCLIENT\r\n$7\r\nGETNAME\r\n", mock.GetMessage());
         }
     }
 }
示例#17
0
 public void BgRewriteAofTest()
 {
     using (var mock = new FakeRedisSocket("+OK\r\n"))
     {
         using (var redis = new RedisClient(mock, new DnsEndPoint("localhost", 9999)))
         {
             Assert.Equal("OK", redis.BgRewriteAof());
             Assert.Equal("*1\r\n$12\r\nBGREWRITEAOF\r\n", mock.GetMessage());
         }
     }
 }
示例#18
0
 public void MGetTest()
 {
     using (var mock = new FakeRedisSocket("*2\r\n$4\r\nval1\r\n$4\r\nval2\r\n"))
         using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
         {
             var response = redis.MGet("key1", "key2");
             Assert.Equal(2, response.Length);
             Assert.Equal("val1", response[0]);
             Assert.Equal("val2", response[1]);
             Assert.Equal("*3\r\n$4\r\nMGET\r\n$4\r\nkey1\r\n$4\r\nkey2\r\n", mock.GetMessage());
         }
 }
示例#19
0
 public void TestHVals()
 {
     using (var mock = new FakeRedisSocket("*2\r\n$5\r\ntest1\r\n$5\r\ntest2\r\n"))
         using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
         {
             var response = redis.HVals("test");
             Assert.AreEqual(2, response.Length);
             Assert.AreEqual("test1", response[0]);
             Assert.AreEqual("test2", response[1]);
             Assert.AreEqual("*2\r\n$5\r\nHVALS\r\n$4\r\ntest\r\n", mock.GetMessage());
         }
 }
示例#20
0
        public void BitCountTest()
        {
            using (var mock = new FakeRedisSocket(":10\r\n", ":4\r\n"))
                using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
                {
                    Assert.Equal(10, redis.BitCount("key"));
                    Assert.Equal("*2\r\n$8\r\nBITCOUNT\r\n$3\r\nkey\r\n", mock.GetMessage());

                    Assert.Equal(4, redis.BitCount("key", 0, 1));
                    Assert.Equal("*4\r\n$8\r\nBITCOUNT\r\n$3\r\nkey\r\n$1\r\n0\r\n$1\r\n1\r\n", mock.GetMessage());
                }
        }
示例#21
0
 public void TestHGetAll_Dictionary()
 {
     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("test");
             Assert.AreEqual(1, response.Count);
             Assert.IsTrue(response.ContainsKey("field1"));
             Assert.AreEqual("test1", response["field1"]);
             Assert.AreEqual("*2\r\n$7\r\nHGETALL\r\n$4\r\ntest\r\n", mock.GetMessage());
         }
 }
示例#22
0
 public void TestSMembers()
 {
     using (var mock = new FakeRedisSocket("*2\r\n$5\r\ntest1\r\n$5\r\ntest2\r\n"))
         using (var redis = new PoolRedisClient(mock, new DnsEndPoint("fakehost", 9999)))
         {
             var response = redis.SMembers("test");
             Assert.Equal(2, response.Length);
             Assert.Equal("test1", response[0]);
             Assert.Equal("test2", response[1]);
             Assert.Equal("*2\r\n$8\r\nSMEMBERS\r\n$4\r\ntest\r\n", mock.GetMessage());
         }
 }
示例#23
0
 public void ConfigGetTest()
 {
     using (var mock = new FakeRedisSocket("*4\r\n$10\r\nmasterauth\r\n$-1\r\n$7\r\nlogfile\r\n$18\r\n/var/log/redis.log\r\n"))
         using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
         {
             var response = redis.ConfigGet("*");
             Assert.Equal(2, response.Length);
             Assert.Equal("masterauth", response[0].Item1);
             Assert.Equal(String.Empty, response[0].Item2);
             Assert.Equal("logfile", response[1].Item1);
             Assert.Equal("/var/log/redis.log", response[1].Item2);
             Assert.Equal("*3\r\n$6\r\nCONFIG\r\n$3\r\nGET\r\n$1\r\n*\r\n", mock.GetMessage());
         }
 }
示例#24
0
        public void TestSRandMember()
        {
            using (var mock = new FakeRedisSocket("$5\r\ntest1\r\n", "*2\r\n$5\r\ntest1\r\n$5\r\ntest2\r\n"))
                using (var redis = new PoolRedisClient(mock, new DnsEndPoint("fakehost", 9999)))
                {
                    Assert.Equal("test1", redis.SRandMember("test"));
                    Assert.Equal("*2\r\n$11\r\nSRANDMEMBER\r\n$4\r\ntest\r\n", mock.GetMessage());

                    var response = redis.SRandMember("test", 2);
                    Assert.Equal(2, response.Length);
                    Assert.Equal("test1", response[0]);
                    Assert.Equal("test2", response[1]);
                    Assert.Equal("*3\r\n$11\r\nSRANDMEMBER\r\n$4\r\ntest\r\n$1\r\n2\r\n", mock.GetMessage());
                }
        }
示例#25
0
        public void BitPosTest()
        {
            using (var mock = new FakeRedisSocket(":10\r\n", ":10\r\n", ":10\r\n"))
                using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
                {
                    Assert.Equal(10, redis.BitPos("key", true));
                    Assert.Equal("*3\r\n$6\r\nBITPOS\r\n$3\r\nkey\r\n$1\r\n1\r\n", mock.GetMessage());

                    Assert.Equal(10, redis.BitPos("key", true, start: 0));
                    Assert.Equal("*4\r\n$6\r\nBITPOS\r\n$3\r\nkey\r\n$1\r\n1\r\n$1\r\n0\r\n", mock.GetMessage());

                    Assert.Equal(10, redis.BitPos("key", true, start: 0, end: 1));
                    Assert.Equal("*5\r\n$6\r\nBITPOS\r\n$3\r\nkey\r\n$1\r\n1\r\n$1\r\n0\r\n$1\r\n1\r\n", mock.GetMessage());
                }
        }
        public void TestZScan()
        {
            string reply = "*2\r\n$2\r\n23\r\n*4\r\n$7\r\nmember1\r\n$3\r\n1.1\r\n$7\r\nmember2\r\n$3\r\n2.2\r\n";

            using (var mock = new FakeRedisSocket(reply, reply, reply, reply))
                using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
                {
                    var response1 = redis.ZScan("test", 0);
                    Assert.Equal(23, response1.Cursor);
                    Assert.Equal(2, response1.Items.Length);
                    Assert.Equal("member1", response1.Items[0].Item1);
                    Assert.Equal(1.1, response1.Items[0].Item2);
                    Assert.Equal("*3\r\n$5\r\nZSCAN\r\n$4\r\ntest\r\n$1\r\n0\r\n", mock.GetMessage());

                    var response2 = redis.ZScan("test", 0, pattern: "*");
                    Assert.Equal("*5\r\n$5\r\nZSCAN\r\n$4\r\ntest\r\n$1\r\n0\r\n$5\r\nMATCH\r\n$1\r\n*\r\n", mock.GetMessage());

                    var response3 = redis.ZScan("test", 0, count: 5);
                    Assert.Equal("*5\r\n$5\r\nZSCAN\r\n$4\r\ntest\r\n$1\r\n0\r\n$5\r\nCOUNT\r\n$1\r\n5\r\n", mock.GetMessage());

                    var response4 = redis.ZScan("test", 0, "*", 5);
                    Assert.Equal("*7\r\n$5\r\nZSCAN\r\n$4\r\ntest\r\n$1\r\n0\r\n$5\r\nMATCH\r\n$1\r\n*\r\n$5\r\nCOUNT\r\n$1\r\n5\r\n", mock.GetMessage());
                }
        }
        public void TestZInterStore()
        {
            string reply = ":2\r\n";

            using (var mock = new FakeRedisSocket(reply, reply, reply, reply, reply))
                using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
                {
                    Assert.Equal(2, redis.ZInterStore("destination", "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());

                    Assert.Equal(2, redis.ZInterStore("destination", weights: new[] { 1D, 2D }, keys: new[] { "key1", "key2" }));
                    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", weights: new[] { 1D, 2D }, aggregate: RedisAggregate.Max, keys: new[] { "key1", "key2" }));
                    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", weights: new[] { 1D, 2D }, aggregate: RedisAggregate.Min, keys: new[] { "key1", "key2" }));
                    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", weights: new[] { 1D, 2D }, aggregate: RedisAggregate.Sum, keys: new[] { "key1", "key2" }));
                    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());
                }
        }
 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.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());
         }
 }
        public void TestZCount()
        {
            string reply = ":2\r\n";

            using (var mock = new FakeRedisSocket(reply, reply, reply, reply, reply))
                using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
                {
                    Assert.Equal(2, redis.ZCount("test", 1, 3));
                    Assert.Equal("*4\r\n$6\r\nZCOUNT\r\n$4\r\ntest\r\n$1\r\n1\r\n$1\r\n3\r\n", mock.GetMessage());

                    Assert.Equal(2, redis.ZCount("test", Double.NegativeInfinity, Double.PositiveInfinity));
                    Assert.Equal("*4\r\n$6\r\nZCOUNT\r\n$4\r\ntest\r\n$4\r\n-inf\r\n$4\r\n+inf\r\n", mock.GetMessage());

                    Assert.Equal(2, redis.ZCount("test", 1, 3, exclusiveMin: true, exclusiveMax: true));
                    Assert.Equal("*4\r\n$6\r\nZCOUNT\r\n$4\r\ntest\r\n$2\r\n(1\r\n$2\r\n(3\r\n", mock.GetMessage());

                    Assert.Equal(2, redis.ZCount("test", "-inf", "+inf"));
                    Assert.Equal("*4\r\n$6\r\nZCOUNT\r\n$4\r\ntest\r\n$4\r\n-inf\r\n$4\r\n+inf\r\n", mock.GetMessage());

                    Assert.Equal(2, redis.ZCount("test", "(1", "(3"));
                    Assert.Equal("*4\r\n$6\r\nZCOUNT\r\n$4\r\ntest\r\n$2\r\n(1\r\n$2\r\n(3\r\n", mock.GetMessage());
                }
        }
 public void TestZScore()
 {
     using (var mock = new FakeRedisSocket("$3\r\n1.1\r\n"))
         using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
         {
             Assert.Equal(1.1, redis.ZScore("test", "member1"));
             Assert.Equal("*3\r\n$6\r\nZSCORE\r\n$4\r\ntest\r\n$7\r\nmember1\r\n", mock.GetMessage());
         }
 }