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.AreEqual(2, redis.ZInterStore("destination", "key1", "key2")); Assert.AreEqual("*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.AreEqual(2, redis.ZInterStore("destination", weights: new[] { 1D, 2D }, keys: new[] { "key1", "key2" })); Assert.AreEqual("*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.AreEqual(2, redis.ZInterStore("destination", weights: new[] { 1D, 2D }, aggregate: RedisAggregate.Max, keys: new[] { "key1", "key2" })); Assert.AreEqual("*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.AreEqual(2, redis.ZInterStore("destination", weights: new[] { 1D, 2D }, aggregate: RedisAggregate.Min, keys: new[] { "key1", "key2" })); Assert.AreEqual("*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.AreEqual(2, redis.ZInterStore("destination", weights: new[] { 1D, 2D }, aggregate: RedisAggregate.Sum, keys: new[] { "key1", "key2" })); Assert.AreEqual("*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 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.AreEqual(2, redis.ZCount("test", 1, 3)); Assert.AreEqual("*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.AreEqual(2, redis.ZCount("test", Double.NegativeInfinity, Double.PositiveInfinity)); Assert.AreEqual("*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.AreEqual(2, redis.ZCount("test", 1, 3, exclusiveMin: true, exclusiveMax: true)); Assert.AreEqual("*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.AreEqual(2, redis.ZCount("test", "-inf", "+inf")); Assert.AreEqual("*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.AreEqual(2, redis.ZCount("test", "(1", "(3")); Assert.AreEqual("*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 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 TestHScan() { string reply = "*2\r\n$2\r\n23\r\n*2\r\n$6\r\nfield1\r\n$5\r\ntest1\r\n"; using (var mock = new FakeRedisSocket(reply, reply, reply, reply)) using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999))) { var response1 = redis.HScan("test", 0); Assert.AreEqual(23, response1.Cursor); Assert.AreEqual(1, response1.Items.Length); Assert.AreEqual("field1", response1.Items[0].Item1); Assert.AreEqual("test1", response1.Items[0].Item2); Assert.AreEqual("*3\r\n$5\r\nHSCAN\r\n$4\r\ntest\r\n$1\r\n0\r\n", mock.GetMessage(), "Basic test"); var response2 = redis.HScan("test", 0, pattern: "*"); Assert.AreEqual("*5\r\n$5\r\nHSCAN\r\n$4\r\ntest\r\n$1\r\n0\r\n$5\r\nMATCH\r\n$1\r\n*\r\n", mock.GetMessage(), "Pattern test"); var response3 = redis.HScan("test", 0, count: 5); Assert.AreEqual("*5\r\n$5\r\nHSCAN\r\n$4\r\ntest\r\n$1\r\n0\r\n$5\r\nCOUNT\r\n$1\r\n5\r\n", mock.GetMessage(), "Count test"); var response4 = redis.HScan("test", 0, "*", 5); Assert.AreEqual("*7\r\n$5\r\nHSCAN\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(), "Pattern + Count test"); } }