本文整理汇总了C#中RedisClient.HKeys方法的典型用法代码示例。如果您正苦于以下问题:C# RedisClient.HKeys方法的具体用法?C# RedisClient.HKeys怎么用?C# RedisClient.HKeys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedisClient
的用法示例。
在下文中一共展示了RedisClient.HKeys方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
// You may download Redis for Windows from https://github.com/MSOpenTech/redis/tree/2.6/bin/release
// Start the Redis server by double-click on redis-server.exe
// Start the Redis client by double-click on the redis-cli.exe
// Then start the VS project to see the result on the Console
using (var redisClient = new RedisClient())
{
// -----------------------------------------------------------
// Adds words and their translations to our EnBg dictionary
// ----------------------------------------------------------
redisClient.HSet("EnBg", "tree", "дърво");
redisClient.HSet("EnBg", "apple", "ябълка");
redisClient.HSet("EnBg", "strawberry", "ягода");
redisClient.HSet("EnBg", "blueberry", "боровинка");
redisClient.HSet("EnBg", "peach", "праскова");
redisClient.HSet("EnBg", "cherry", "череша");
redisClient.HSet("EnBg", "grape", "грозде");
// ---------------------------------------
// List all words and their translations
// ----------------------------------------
string[] allWords = redisClient.HKeys("EnBg");
Console.WriteLine("Word -> Translation");
Console.WriteLine(new string('-', 30));
for (int i = 0; i < allWords.Length; i++)
{
Console.WriteLine(allWords[i] + " -> " + redisClient.HGet("EnBg", allWords[i]));
}
Console.WriteLine();
// ----------------------------------------
// Find the translation of given word
// ----------------------------------------
Console.WriteLine("Find translation of a word");
Console.WriteLine(new string('-', 30));
Console.WriteLine("Translation of 'tree' is {0}", redisClient.HGet("EnBg", "tree"));
Console.WriteLine("Translation of 'apple' is {0}", redisClient.HGet("EnBg", "apple"));
Console.WriteLine("Translation of 'cherry' is {0}", redisClient.HGet("EnBg", "cherry"));
}
}
示例2: TestHSetNX
public void TestHSetNX()
{
using(var mock = new MockConnector("localhost", 9999, ":1\r\n"))
using(var redis = new RedisClient(mock))
{
Assert.True(redis.HSet("test", "field1", "test1", true));
Assert.Equal("*4\r\n$6\r\nHSETNX\r\n$4\r\ntest\r\n$6\r\nfield1\r\n$5\r\ntest1\r\n", mock.GetMessage());
}
this.RealCall(redis =>
{
Assert.True(redis.HSet("test", "field1", "value1", true));
Assert.False(redis.HSet("test", "field1", "value1", true));
var response = redis.HKeys("test");
Assert.Equal(1, response.Length);
Assert.Equal("field1", response[0]);
});
}
示例3: TestHKeys
public void TestHKeys()
{
using(var mock = new MockConnector("localhost", 9999, "*2\r\n$5\r\ntest1\r\n$5\r\ntest2\r\n"))
using(var redis = new RedisClient(mock))
{
var response = redis.HKeys("test");
Assert.Equal(2, response.Length);
Assert.Equal("test1", response[0]);
Assert.Equal("test2", response[1]);
Assert.Equal("*2\r\n$5\r\nHKEYS\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.HKeys("test");
Assert.Equal(2, response.Length);
Assert.Equal("field1", response[0]);
Assert.Equal("field2", response[1]);
});
}
示例4: TestHKeys
public void TestHKeys()
{
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.HKeys("test");
Assert.AreEqual(2, response.Length);
Assert.AreEqual("test1", response[0]);
Assert.AreEqual("test2", response[1]);
Assert.AreEqual("*2\r\n$5\r\nHKEYS\r\n$4\r\ntest\r\n", mock.GetMessage());
}
}