我试过喜欢下面
var Settings = new RedisSettings("localhost");
public async void SetData< T >(IEnumerable< T > collection, string Key)
{
RedisDictionary< object, T > mydictionary = new RedisDictionary< object, T >(Settings, typeof(T).Name);
//how to add collection data into dictionary
// i tried like following but failed
await mydictionary.Set(new[] { new KeyValuePair< object, IEnumerable< T > >(Key, collection) });
但它无法将值插入到 redis 字典中:( 我用过
最佳答案
您的代码似乎与 StackExchange.Redis
无关。可能和ServiceStack.Redis
有关。
无论如何,如果您希望使用非商业客户端(例如 StackExchange.Redis
)将 Redis 哈希作为 .NET 字典来处理,我建议您使用 CachingFramework.Redis依赖于 StackExchange.Redis 的库。
Here是 RedisDictionary
实现的代码。 (参见 documentation)
关于c# - 如何使用 redis 字典添加 IEnumerable< T > 集合数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32124400/