【发布时间】:2017-05-16 09:22:16
【问题描述】:
首先,图书馆的链接:ServiceStack.Redis
现在,我想存储 T 类型的对象,其中 T 包含字段 Key 和 Value。 (本例)
问题是我似乎只能将字符串存储为键和值。 至于字符串键,那很好,但我需要存储一个对象作为值。
附上我的代码,它支持映射哈希 -> KeyValuePair items
public void PutDictionary(string hashKey, Dictionary<string, T> items, TimeSpan expiration)
{
try
{
using (var trans = _client.CreateTransaction())
{
foreach (KeyValuePair<string, T> item in items)
{
trans.QueueCommand(r => r.SetEntryInHash(hashKey, item.Key, ???));
}
trans.Commit();
}
}
catch (Exception e)
{
// some logic here..
}
}
我知道我可以只对我的对象进行 JSON 字符串化,但这似乎只是消耗了非常需要的性能并失去了快速缓存内存的效果。
我会解释我想要实现的目标。 可以说我有一个团体和人民。 该组有一个 Id,该组内的每个实体也有一个 Id。 我希望能够从特定组中获得特定的人。
在 C# 中,它相当于 Dictionary<string, Dictionary<string, T>>
【问题讨论】:
标签: c# caching redis servicestack servicestack.redis