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"); } }
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."); } }
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); } }
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); }
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"); }
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"); } }
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"); } }
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"); } }
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)); } }
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."); } } }
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."); } }
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; }