本文整理汇总了C#中RedisClient.MSet方法的典型用法代码示例。如果您正苦于以下问题:C# RedisClient.MSet方法的具体用法?C# RedisClient.MSet怎么用?C# RedisClient.MSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedisClient
的用法示例。
在下文中一共展示了RedisClient.MSet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestDel
public void TestDel()
{
using(var mock = new MockConnector("localhost", 9999, ":3\r\n"))
using(var redis = new RedisClient(mock))
{
Assert.Equal(3, redis.Del("test"));
Assert.Equal("*2\r\n$3\r\nDEL\r\n$4\r\ntest\r\n", mock.GetMessage());
}
this.RealCall(redis =>
{
redis.MSet(new RedisDictionary { { "key1", "value1" }, { "key2", "value2" } });
Assert.Equal(2, redis.Del("key1", "key2"));
});
}
示例2: TestExists
public void TestExists()
{
using(var mock = new MockConnector("localhost", 9999, ":1\r\n", ":0\r\n"))
using(var redis = new RedisClient(mock))
{
Assert.True(redis.Exists("test1"));
Assert.Equal("*2\r\n$6\r\nEXISTS\r\n$5\r\ntest1\r\n", mock.GetMessage());
Assert.False(redis.Exists("test2"));
Assert.Equal("*2\r\n$6\r\nEXISTS\r\n$5\r\ntest2\r\n", mock.GetMessage());
}
this.RealCall(redis =>
{
redis.MSet(new RedisDictionary { { "key1", "value1" }, { "key2", "value2" } });
Assert.True(redis.Exists("key1"));
Assert.True(redis.Exists("key2"));
Assert.False(redis.Exists("test3"));
});
}
示例3: TestExpire
public void TestExpire()
{
using(var mock = new MockConnector("localhost", 9999, ":1\r\n", ":0\r\n"))
using(var redis = new RedisClient(mock))
{
Assert.True(redis.Expire("test1", TimeSpan.FromSeconds(10)));
Assert.Equal("*3\r\n$6\r\nEXPIRE\r\n$5\r\ntest1\r\n$2\r\n10\r\n", mock.GetMessage());
Assert.False(redis.Expire("test2", 20));
Assert.Equal("*3\r\n$6\r\nEXPIRE\r\n$5\r\ntest2\r\n$2\r\n20\r\n", mock.GetMessage());
}
this.RealCall(redis =>
{
redis.MSet(new RedisDictionary { { "key1", "value1" }, { "key2", "value2" } });
Assert.True(redis.Expire("key1", TimeSpan.FromSeconds(10)));
Assert.True(redis.Expire("key2", 20));
Assert.True(redis.Ttl("key1") <= 10);
Assert.True(redis.Ttl("key2") <= 20);
});
}
示例4: TestExpireAt
public void TestExpireAt()
{
using(var mock = new MockConnector("localhost", 9999, ":1\r\n", ":0\r\n"))
using(var redis = new RedisClient(mock))
{
// 1402643208 = ISO 8601:2014-06-13T07:06:48Z
Assert.True(redis.ExpireAt("test1", new DateTime(2014, 6, 13, 7, 6, 48, DateTimeKind.Utc)));
Assert.Equal("*3\r\n$8\r\nEXPIREAT\r\n$5\r\ntest1\r\n$10\r\n1402643208\r\n", mock.GetMessage());
Assert.False(redis.ExpireAt("test2", 1402643208));
Assert.Equal("*3\r\n$8\r\nEXPIREAT\r\n$5\r\ntest2\r\n$10\r\n1402643208\r\n", mock.GetMessage());
}
this.RealCall(redis =>
{
redis.MSet(new RedisDictionary { { "key1", "value1" } });
var now = DateTime.Now;
Assert.True(redis.ExpireAt("key1", now.AddSeconds(10)));
var ttl = redis.Ttl("key1");
Assert.True(ttl <= 10);
});
}
示例5: MSetTest
public void MSetTest()
{
using(var mock = new MockConnector("localhost", 9999, "+OK\r\n"))
using(var redis = new RedisClient(mock))
{
Assert.True(redis.MSet(new RedisDictionary() { { "key1", "val1" }, { "key2", "val2" } }));
Assert.Equal("*5\r\n$4\r\nMSET\r\n$4\r\nkey1\r\n$4\r\nval1\r\n$4\r\nkey2\r\n$4\r\nval2\r\n", mock.GetMessage());
}
}
示例6: MSetTest
public void MSetTest()
{
using (var mock = new FakeRedisSocket("+OK\r\n", "+OK\r\n"))
using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
{
Assert.AreEqual("OK", redis.MSet("key1", "val1", "key2", "val2"));
Assert.AreEqual("*5\r\n$4\r\nMSET\r\n$4\r\nkey1\r\n$4\r\nval1\r\n$4\r\nkey2\r\n$4\r\nval2\r\n", mock.GetMessage());
Assert.AreEqual("OK", redis.MSet(Tuple.Create("key1", "val1"), Tuple.Create("key2", "val2")));
Assert.AreEqual("*5\r\n$4\r\nMSET\r\n$4\r\nkey1\r\n$4\r\nval1\r\n$4\r\nkey2\r\n$4\r\nval2\r\n", mock.GetMessage());
}
}
示例7: TestKeys
public void TestKeys()
{
using(var mock = new MockConnector("localhost", 9999, "*3\r\n$5\r\ntest1\r\n$5\r\ntest2\r\n$5\r\ntest3\r\n"))
using(var redis = new RedisClient(mock))
{
var response = redis.Keys("test*");
Assert.Equal(3, response.Length);
for(int i = 0; i < response.Length; i++)
Assert.Equal("test" + (i + 1), response[i]);
}
this.RealCall(redis =>
{
redis.MSet(new RedisDictionary { { "key1", "value1" }, { "key2", "value2" }, { "test1", "value2" } });
var response = redis.Keys("key*");
Assert.Equal(2, response.Length);
});
}
示例8: TestScan
public void TestScan()
{
var reply1 = "*2\r\n$1\r\n0\r\n*3\r\n$5\r\ntest1\r\n$5\r\ntest2\r\n$5\r\ntest3\r\n";
var reply2 = "*2\r\n$1\r\n0\r\n*0\r\n";
var reply3 = "*2\r\n$1\r\n0\r\n*0\r\n";
var reply4 = "*2\r\n$1\r\n0\r\n*0\r\n";
using(var mock = new MockConnector("localhost", 9999, reply1, reply2, reply3, reply4))
using(var redis = new RedisClient(mock))
{
var resp = (redis.Scan(0) as RedisScan<string>).GetEnumerator() as RedisScan<string>.Enumerator;
for(int i = 0; i < 3; i++)
{
resp.MoveNext();
Assert.Equal(3 - i - 1, resp.Items.Length);
Assert.Equal(0, resp.Cursor);
Assert.Equal("test" + (i + 1), resp.Current);
}
Assert.Equal("*2\r\n$4\r\nSCAN\r\n$1\r\n0\r\n", mock.GetMessage());
redis.Scan(1, pattern: "pattern").ToArray();
Assert.Equal("*4\r\n$4\r\nSCAN\r\n$1\r\n1\r\n$5\r\nMATCH\r\n$7\r\npattern\r\n", mock.GetMessage());
redis.Scan(2, count: 5).ToArray();
Assert.Equal("*4\r\n$4\r\nSCAN\r\n$1\r\n2\r\n$5\r\nCOUNT\r\n$1\r\n5\r\n", mock.GetMessage());
redis.Scan(3, pattern: "pattern", count: 5).ToArray();
Assert.Equal("*6\r\n$4\r\nSCAN\r\n$1\r\n3\r\n$5\r\nMATCH\r\n$7\r\npattern\r\n$5\r\nCOUNT\r\n$1\r\n5\r\n", mock.GetMessage());
}
this.RealCall(redis =>
{
var dict = new RedisDictionary();
for(int i = 1; i < 21; i++)
{
dict.Add("key" + i, "value" + i);
}
redis.MSet(dict);
Assert.Equal(20, redis.Scan().Count());
});
}
示例9: TestType
public void TestType()
{
using(var mock = new MockConnector("localhost", 9999, "+string\r\n"))
using(var redis = new RedisClient(mock))
{
Assert.Equal(RedisType.String, redis.Type("test"));
Assert.Equal("*2\r\n$4\r\nTYPE\r\n$4\r\ntest\r\n", mock.GetMessage());
}
this.RealCall(redis =>
{
redis.MSet(new RedisDictionary { { "key1", "value1" }, { "key2", "value2" } });
Assert.Equal(RedisType.String, redis.Type("key1"));
Assert.Equal(RedisType.String, redis.Type("key2"));
});
}
示例10: TestTtl
public void TestTtl()
{
using(var mock = new MockConnector("localhost", 9999, ":123\r\n"))
using(var redis = new RedisClient(mock))
{
Assert.Equal(123, redis.Ttl("test"));
Assert.Equal("*2\r\n$3\r\nTTL\r\n$4\r\ntest\r\n", mock.GetMessage());
}
this.RealCall(redis =>
{
redis.MSet(new RedisDictionary { { "key1", "value1" }, { "key2", "value2" } });
Assert.True(redis.Expire("key1", TimeSpan.FromSeconds(10)));
Assert.True(redis.Expire("key2", 20));
Assert.True(redis.Ttl("key1", RedisExpireTimeUnit.PX) <= 10 * 1000);
Assert.True(redis.Ttl("key2", RedisExpireTimeUnit.PX) <= 20 * 1000);
});
}
示例11: TestRenameNx
public void TestRenameNx()
{
using(var mock = new MockConnector("localhost", 9999, ":1\r\n"))
using(var redis = new RedisClient(mock))
{
Assert.True(redis.RenameNx("test1", "test2"));
Assert.Equal("*3\r\n$8\r\nRENAMENX\r\n$5\r\ntest1\r\n$5\r\ntest2\r\n", mock.GetMessage());
}
this.RealCall(redis =>
{
redis.MSet(new RedisDictionary { { "key1", "value1" }, { "key2", "value2" } });
Assert.False(redis.RenameNx("key1", "key2"));
Assert.False(redis.RenameNx("key3", "key4"));
Assert.True(redis.RenameNx("key1", "key3"));
Assert.Equal("value1", (string)redis.Get("key3"));
});
}
示例12: TestRandomKey
public void TestRandomKey()
{
using(var mock = new MockConnector("localhost", 9999, "$7\r\nsomekey\r\n"))
using(var redis = new RedisClient(mock))
{
Assert.Equal("somekey", redis.RandomKey());
Assert.Equal("*1\r\n$9\r\nRANDOMKEY\r\n", mock.GetMessage());
}
this.RealCall(redis =>
{
redis.MSet(new RedisDictionary { { "key1", "value1" }, { "key2", "value2" } });
var key = redis.RandomKey();
Assert.True(key == "key1" || key == "key2");
});
}
示例13: PExpireAt
public void PExpireAt()
{
using(var mock = new MockConnector("localhost", 9999, ":1\r\n", ":0\r\n"))
using(var redis = new RedisClient(mock))
{
// 1402643208123 = ISO 8601:2014-06-13T07:06:48Z +123ms
Assert.True(redis.ExpireAt("test1", new DateTime(2014, 6, 13, 7, 6, 48, 123, DateTimeKind.Utc), RedisExpireTimeUnit.PX));
Assert.Equal("*3\r\n$9\r\nPEXPIREAT\r\n$5\r\ntest1\r\n$13\r\n1402643208123\r\n", mock.GetMessage());
Assert.False(redis.ExpireAt("test2", 1402643208123, RedisExpireTimeUnit.PX));
Assert.Equal("*3\r\n$9\r\nPEXPIREAT\r\n$5\r\ntest2\r\n$13\r\n1402643208123\r\n", mock.GetMessage());
}
this.RealCall(redis =>
{
redis.MSet(new RedisDictionary { { "key1", "value1" } });
Assert.True(redis.ExpireAt("key1", DateTime.Now.AddSeconds(10), RedisExpireTimeUnit.PX));
Assert.True(redis.Ttl("key1") <= 10 * 1000);
});
}
示例14: PExpire
public void PExpire()
{
using(var mock = new MockConnector("localhost", 9999, ":1\r\n", ":0\r\n"))
using(var redis = new RedisClient(mock))
{
Assert.True(redis.Expire("test1", TimeSpan.FromMilliseconds(5000), RedisExpireTimeUnit.PX));
Assert.Equal("*3\r\n$7\r\nPEXPIRE\r\n$5\r\ntest1\r\n$4\r\n5000\r\n", mock.GetMessage());
Assert.False(redis.Expire("test2", 6000, RedisExpireTimeUnit.PX));
Assert.Equal("*3\r\n$7\r\nPEXPIRE\r\n$5\r\ntest2\r\n$4\r\n6000\r\n", mock.GetMessage());
}
this.RealCall(redis =>
{
redis.MSet(new RedisDictionary { { "key1", "value1" }, { "key2", "value2" } });
Assert.True(redis.Expire("key1", TimeSpan.FromSeconds(10), RedisExpireTimeUnit.PX));
Assert.True(redis.Expire("key2", 20 * 1000, RedisExpireTimeUnit.PX));
Assert.True(redis.Ttl("key1") <= 10 * 1000);
Assert.True(redis.Ttl("key2") <= 20 * 1000);
});
}
示例15: TestMove
public void TestMove()
{
using(var mock = new MockConnector("localhost", 9999, ":1\r\n"))
using(var redis = new RedisClient(mock))
{
Assert.True(redis.Move("test", 5));
Assert.Equal("*3\r\n$4\r\nMOVE\r\n$4\r\ntest\r\n$1\r\n5\r\n", mock.GetMessage());
}
this.RealCall(redis =>
{
redis.MSet(new RedisDictionary { { "key1", "value1" } });
Assert.True(redis.Move("key1", 5));
});
}