當前位置: 首頁>>代碼示例>>C#>>正文


C# RedisClient.HSetNX方法代碼示例

本文整理匯總了C#中ServiceStack.Redis.RedisClient.HSetNX方法的典型用法代碼示例。如果您正苦於以下問題:C# RedisClient.HSetNX方法的具體用法?C# RedisClient.HSetNX怎麽用?C# RedisClient.HSetNX使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ServiceStack.Redis.RedisClient的用法示例。


在下文中一共展示了RedisClient.HSetNX方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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");
            }
        }
開發者ID:psotirov,項目名稱:TelerikAcademyProjects,代碼行數:29,代碼來源:RedisDictionary.cs

示例2: 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");
        }
開發者ID:PetarPenev,項目名稱:Telerik,代碼行數:11,代碼來源:Program.cs

示例3: AddSampleWords

        public static void AddSampleWords(RedisClient redisDictionaryClient)
        {
            var firstItem = new DictionaryItem { Word = "1", Translation = "One" };
            var secondItem = new DictionaryItem { Word = "2", Translation = "Two" };
            var thirdItem = new DictionaryItem { Word = "3", Translation = "Three" };
            var fourthItem = new DictionaryItem { Word = "4", Translation = "Four" };
            var fifthItem = new DictionaryItem { Word = "5", Translation = "Five" };

            redisDictionaryClient.HSetNX(ColectionKey, 
                firstItem.Word.ToAsciiCharArray(), firstItem.Translation.ToAsciiCharArray());

            redisDictionaryClient.HSetNX(ColectionKey,
                secondItem.Word.ToAsciiCharArray(), secondItem.Translation.ToAsciiCharArray());

            redisDictionaryClient.HSetNX(ColectionKey,
                thirdItem.Word.ToAsciiCharArray(), thirdItem.Translation.ToAsciiCharArray());

            redisDictionaryClient.HSetNX(ColectionKey,
                fourthItem.Word.ToAsciiCharArray(), fourthItem.Translation.ToAsciiCharArray());

            redisDictionaryClient.HSetNX(ColectionKey,
                fifthItem.Word.ToAsciiCharArray(), fifthItem.Translation.ToAsciiCharArray());
        }
開發者ID:quela,項目名稱:myprojects,代碼行數:23,代碼來源:RedisDBDictionaryClient.cs

示例4: 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));
            }
        }
開發者ID:Gerya,項目名稱:TelerikAcademy,代碼行數:17,代碼來源:Utilities.cs

示例5: 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.");
            }
        }
    }
開發者ID:nikolaynikolov,項目名稱:Telerik,代碼行數:44,代碼來源:RedisDictionaryDemo.cs

示例6: AddItem

        public static void AddItem(RedisClient redisDictionaryClient)
        {
            Console.WriteLine("Enter word: ");
            string word = Console.ReadLine();
            Console.WriteLine("Enter translation: ");
            string translation = Console.ReadLine();

            var newDictionaryItem = new DictionaryItem { Word = word, Translation = translation };
            redisDictionaryClient.HSetNX(ColectionKey, 
                newDictionaryItem.Word.ToAsciiCharArray(), newDictionaryItem.Translation.ToAsciiCharArray());
            Console.WriteLine("Element added!\n");
        }
開發者ID:quela,項目名稱:myprojects,代碼行數:12,代碼來源:RedisDBDictionaryClient.cs

示例7: TryCreateUser

        static bool TryCreateUser(string username, RedisClient redisClient)
        {
            if (redisClient.SAdd("usernames", username.ToAsciiCharArray()) != 0)
            {
                Console.WriteLine("Please enter your age:");
                int age = int.Parse(Console.ReadLine());
                //Think about potential race conditions
                redisClient.HSetNX("user:" + username, "username".ToAsciiCharArray(), username.ToAsciiCharArray());
                redisClient.HSetNX("user:" + username, "age".ToAsciiCharArray(), age.ToString().ToAsciiCharArray());
                return true;
            }

            return false;
        }
開發者ID:quela,項目名稱:myprojects,代碼行數:14,代碼來源:LocalRedisNSAChat.cs


注:本文中的ServiceStack.Redis.RedisClient.HSetNX方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。