本文整理汇总了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");
}
}
示例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");
}
示例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());
}
示例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));
}
}
示例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.");
}
}
}
示例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");
}
示例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;
}