本文整理汇总了C#中ServiceStack.Redis.RedisClient.HExists方法的典型用法代码示例。如果您正苦于以下问题:C# RedisClient.HExists方法的具体用法?C# RedisClient.HExists怎么用?C# RedisClient.HExists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceStack.Redis.RedisClient
的用法示例。
在下文中一共展示了RedisClient.HExists方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
var dictionaryData = new string[,]
{
{ ".NET", "platform for applications from Microsoft" },
{ "CLR", "managed execution environment for .NET" },
{ "namespace", "hierarchical organization of classes" },
{ "database", "structured sets of persistent updateable and queriable data" },
{ "blob", "binary large object" },
{ "RDBMS", "relational database management system" },
{ "json", "JavaScript Object Notation" },
{ "xml", "Extensible Markup Language" },
};
using (var redisClient = new RedisClient("127.0.0.1:6379"))
{
for (int i = 0; i < dictionaryData.GetLength(0); i++)
{
if (redisClient.HExists("dictionary", ToByteArray(dictionaryData[i, 0])) == 0)
{
redisClient.HSetNX("dictionary", ToByteArray(dictionaryData[i, 0]), ToByteArray(dictionaryData[i, 1]));
}
}
PrintAllWords(redisClient);
Console.WriteLine("\nSearch for word \"blob\":");
FindWord(redisClient, "blob");
}
}
示例2: ChangeTranslation
private static void ChangeTranslation(RedisClient client)
{
Console.WriteLine("Enter word.");
string word = Console.ReadLine();
byte[] wordInBytes = Extensions.ToAsciiCharArray(word);
Console.WriteLine("Enter translation.");
string translation = Console.ReadLine();
byte[] translationInBytes = Extensions.ToAsciiCharArray(translation);
if (!string.IsNullOrWhiteSpace(word) && !string.IsNullOrWhiteSpace(translation))
{
if (client.HExists(dictionary, wordInBytes) == 1)
{
client.HSet(dictionary, wordInBytes, translationInBytes);
Console.WriteLine("Translation of the word {0} is changed.", word);
}
else
{
Console.WriteLine("There is no word {0}.", word);
}
}
else
{
Console.WriteLine("You enter null or empty string for word or translation. Please try again.");
}
}
示例3: FindWord
private static void FindWord(RedisClient client, string key)
{
if (client.HExists("dictionary", ToByteArray(key)) > 0)
{
var translation = IntoString(client.HGet("dictionary", ToByteArray(key)));
Console.WriteLine(translation);
}
}
示例4: FindTranslation
public static void FindTranslation(RedisClient client, string word)
{
if (client.HExists(wordHashStructure, word.ToAsciiCharArray()) == 0)
{
Console.WriteLine("Word does not exist in the dictionary.");
return;
}
var translation = Extensions.StringFromByteArray(client.HGet(wordHashStructure, word.ToAsciiCharArray()));
Console.WriteLine(word + ":" + translation);
}
示例5: AddWord
public static void AddWord(RedisClient client, string word, string translation)
{
if (client.HExists(wordHashStructure, word.ToAsciiCharArray()) != 0)
{
Console.WriteLine("The word is already added to the dictionary.");
return;
}
client.HSetNX(wordHashStructure, word.ToAsciiCharArray(), translation.ToAsciiCharArray());
Console.WriteLine("Word added");
}
示例6: RemoveWords
public static void RemoveWords(RedisClient words)
{
Console.Write("Enter word for remove: ");
string deleteWord = Console.ReadLine().ToLower();
long countWords = words.HExists("words", Extensions.ToAsciiCharArray(deleteWord));
if (countWords>0)
{
words.HDel("words", Extensions.ToAsciiCharArray(deleteWord));
}
else
{
Console.WriteLine("This word is not exist");
}
}
示例7: SreachWord
public static void SreachWord(RedisClient words)
{
Console.Write("Enter word for translation: ");
string searchedWord = Console.ReadLine().ToLower();
long countWords = words.HExists("words", Extensions.ToAsciiCharArray(searchedWord));
if (countWords > 0)
{
var translation = words.HGet("words", Extensions.ToAsciiCharArray(searchedWord));
Console.WriteLine("Word: {0}\nTranslation: {1}", searchedWord, Extensions.StringFromByteArray(translation));
}
else
{
Console.WriteLine("This word is not exist");
}
}
示例8: EditWord
public static void EditWord(RedisClient words)
{
Console.Write("Enter word for edit: ");
string editWord = Console.ReadLine().ToLower();
Console.Write("Enter new translation: ");
string translation = Console.ReadLine().ToLower();
long countWords = words.HExists("words", Extensions.ToAsciiCharArray(editWord));
if (countWords>0)
{
words.HSet("words", Extensions.ToAsciiCharArray(editWord), Extensions.ToAsciiCharArray(translation));
}
else
{
Console.WriteLine("This word is not exist");
}
}
示例9: AddWord
public static void AddWord(RedisClient words)
{
Console.Write("Enter word: ");
string loweredWord = Console.ReadLine().ToLower();
Console.Write("Enter translation: ");
string loweredTranslation = Console.ReadLine().ToLower();
long countWords = words.HExists("words", Extensions.ToAsciiCharArray(loweredWord));
if (countWords > 0)
{
Console.WriteLine("This word already exist");
}
else
{
words.HSetNX("words", Extensions.ToAsciiCharArray(loweredWord), Extensions.ToAsciiCharArray(loweredTranslation));
}
}
示例10: Main
private static void Main()
{
// The default console's font doesn't support Cyrillic letters.
// We should find a font with Unicode support and change the
// default font.
Console.OutputEncoding = Encoding.UTF8;
ConsoleHelper.SetConsoleFont(6);
string hashId = "dictionary";
string word = "humongous";
string synonym = "enormous";
using (var redisClient = new RedisClient("127.0.0.1:6379"))
{
if (redisClient.Ping())
{
long entriesCount = redisClient.HExists(hashId, StringUtils.ToAsciiCharArray(word));
if (entriesCount > 0)
{
Console.WriteLine("This word is already in the dictionary.");
}
else
{
redisClient.HSetNX(
hashId,
StringUtils.ToAsciiCharArray(word),
StringUtils.ToAsciiCharArray(synonym));
byte[] meaning = redisClient.HGet(hashId, StringUtils.ToAsciiCharArray(word));
Console.WriteLine(
"Word: {0}\nTranslation: {1}",
word,
StringUtils.StringFromByteArray(meaning));
redisClient.HDel(hashId, StringUtils.ToAsciiCharArray(word));
}
}
else
{
Console.WriteLine("The Redis server isn't started.");
}
}
}
示例11: ShowTranslation
private static void ShowTranslation(RedisClient client)
{
Console.WriteLine("Enter word");
string word = Console.ReadLine();
byte[] wordInBytes = Extensions.ToAsciiCharArray(word);
if (!string.IsNullOrWhiteSpace(word))
{
if (client.HExists(dictionary, wordInBytes) == 1)
{
byte[] translation = client.HGet(dictionary, wordInBytes);
Console.WriteLine("Translation of the word {0} is:", word);
Console.WriteLine(Extensions.StringFromByteArray(translation));
}
else
{
Console.WriteLine("There is no word {0}.", word);
}
}
else
{
Console.WriteLine("You enter null or empty string for word. Please try again.");
}
}
示例12: GetTranslation
static string GetTranslation(RedisClient redisClient, string word)
{
if (redisClient.HExists(DictionaryStructure, Extensions.ToAsciiCharArray(word)) != 0)
{
return Extensions.StringFromByteArray(
redisClient.HGet(DictionaryStructure, Extensions.ToAsciiCharArray(word)));
}
return null;
}