本文整理汇总了C#中RedisClient.GetTypedClient方法的典型用法代码示例。如果您正苦于以下问题:C# RedisClient.GetTypedClient方法的具体用法?C# RedisClient.GetTypedClient怎么用?C# RedisClient.GetTypedClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedisClient
的用法示例。
在下文中一共展示了RedisClient.GetTypedClient方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Working_with_int_values
public void Working_with_int_values()
{
const string intKey = "intkey";
const int intValue = 1;
//STORING AN INT USING THE BASIC CLIENT
using (var redisClient = new RedisClient(TestConfig.SingleHost))
{
redisClient.SetEntry(intKey, intValue.ToString());
string strGetIntValue = redisClient.GetValue(intKey);
int toIntValue = int.Parse(strGetIntValue);
Assert.That(toIntValue, Is.EqualTo(intValue));
}
//STORING AN INT USING THE GENERIC CLIENT
using (var redisClient = new RedisClient(TestConfig.SingleHost))
{
//Create a generic client that treats all values as ints:
IRedisTypedClient<int> intRedis = redisClient.GetTypedClient<int>();
intRedis.SetEntry(intKey, intValue);
var toIntValue = intRedis.GetValue(intKey);
Assert.That(toIntValue, Is.EqualTo(intValue));
}
}
示例2: SetUp
public void SetUp()
{
if (client != null)
{
client.Dispose();
client = null;
}
client = new RedisClient(TestConfig.SingleHost);
client.FlushAll();
redis = client.GetTypedClient<CustomType>();
List = redis.Lists[ListId];
List2 = redis.Lists[ListId2];
}
示例3: Working_with_int_list_values
public void Working_with_int_list_values()
{
const string intListKey = "intListKey";
var intValues = new List<int> { 2, 4, 6, 8 };
//STORING INTS INTO A LIST USING THE BASIC CLIENT
using (var redisClient = new RedisClient(TestConfig.SingleHost))
{
IList<string> strList = redisClient.Lists[intListKey];
//storing all int values in the redis list 'intListKey' as strings
intValues.ForEach(x => strList.Add(x.ToString()));
//retrieve all values again as strings
List<string> strListValues = strList.ToList();
//convert back to list of ints
List<int> toIntValues = strListValues.ConvertAll(x => int.Parse(x));
Assert.That(toIntValues, Is.EqualTo(intValues));
//delete all items in the list
strList.Clear();
}
//STORING INTS INTO A LIST USING THE GENERIC CLIENT
using (var redisClient = new RedisClient(TestConfig.SingleHost))
{
//Create a generic client that treats all values as ints:
IRedisTypedClient<int> intRedis = redisClient.GetTypedClient<int>();
IRedisList<int> intList = intRedis.Lists[intListKey];
//storing all int values in the redis list 'intListKey' as ints
intValues.ForEach(x => intList.Add(x));
List<int> toIntListValues = intList.ToList();
Assert.That(toIntListValues, Is.EqualTo(intValues));
}
}
示例4: Working_with_Generic_types
public void Working_with_Generic_types()
{
using (var redisClient = new RedisClient())
{
//Create a typed Redis client that treats all values as IntAndString:
var typedRedis = redisClient.GetTypedClient<IntAndString>();
var pocoValue = new IntAndString { Id = 1, Letter = "A" };
typedRedis.SetEntry("pocoKey", pocoValue);
IntAndString toPocoValue = typedRedis.GetValue("pocoKey");
Assert.That(toPocoValue.Id, Is.EqualTo(pocoValue.Id));
Assert.That(toPocoValue.Letter, Is.EqualTo(pocoValue.Letter));
var pocoListValues = new List<IntAndString> {
new IntAndString {Id = 2, Letter = "B"},
new IntAndString {Id = 3, Letter = "C"},
new IntAndString {Id = 4, Letter = "D"},
new IntAndString {Id = 5, Letter = "E"},
};
IRedisList<IntAndString> pocoList = typedRedis.Lists["pocoListKey"];
//Adding all IntAndString objects into the redis list 'pocoListKey'
pocoListValues.ForEach(x => pocoList.Add(x));
List<IntAndString> toPocoListValues = pocoList.ToList();
for (var i = 0; i < pocoListValues.Count; i++)
{
pocoValue = pocoListValues[i];
toPocoValue = toPocoListValues[i];
Assert.That(toPocoValue.Id, Is.EqualTo(pocoValue.Id));
Assert.That(toPocoValue.Letter, Is.EqualTo(pocoValue.Letter));
}
}
}