本文整理汇总了C#中Aoite.Redis.MockConnector类的典型用法代码示例。如果您正苦于以下问题:C# MockConnector类的具体用法?C# MockConnector怎么用?C# MockConnector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MockConnector类属于Aoite.Redis命名空间,在下文中一共展示了MockConnector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClientKillTest
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: TestHGetAll
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: ScriptLoadTest
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: ScriptKillTest
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: TestZAdd_Array
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: SelectTest
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: TestZCard
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: ClientGetNameTest
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());
}
}
示例9: IncrTest
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());
}
}
示例10: AppendTest
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());
}
}
示例11: ClientListTest
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());
}
}
示例12: GetSetTest
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());
}
}
示例13: AuthTest
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: DecrByTest
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());
}
}
示例15: QuitTest
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());
}
}