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);
     }
 }
示例#2
0
        public static void FindEntryByBookName(RedisClient redisIO, string bookName)
        {
            Console.WriteLine("Search");
            Console.WriteLine(new string('-', Console.WindowWidth - 5));

            string translation = StringExtensions.StringFromByteArray(redisIO.HGet("Dictonary", bookName.ToAsciiCharArray()));

            Console.WriteLine("Book Name: {0}, Translation: {1}", bookName, translation);
        }
示例#3
0
        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);
        }
示例#4
0
        public static void ListAll(RedisClient client)
        {
            var keys = client.HKeys(wordHashStructure);
            var stringifiedKeys = new List<string>();
            foreach (var key in keys)
            {
                stringifiedKeys.Add(Extensions.StringFromByteArray(key));
            }

            foreach (var key in stringifiedKeys)
            {
                Console.WriteLine(key + " : " + Extensions.StringFromByteArray(client.HGet(wordHashStructure, key.ToAsciiCharArray())));
            }
        }
示例#5
0
 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");
     }
 }
    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.");
     }
 }
        public static void SearchItem(RedisClient redisDictionaryClient)
        {
            Console.WriteLine("Enter word for search: ");
            string searchedWord = Console.ReadLine();

            var searchedItems = redisDictionaryClient.HGet(ColectionKey, searchedWord.ToAsciiCharArray());

            Console.WriteLine("Translation: {0}\n", Extensions.StringFromByteArray(searchedItems));
        }
        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;
        }