c# - 如何使用 redis 字典添加 IEnumerable< T > 集合数据?

标签 c# dictionary redis stackexchange.redis cachingframework.redis

我试过喜欢下面

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 的库。

HereRedisDictionary 实现的代码。 (参见 documentation)

关于c# - 如何使用 redis 字典添加 IEnumerable< T > 集合数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32124400/

相关文章:

python - 在 python 字典中排序键值对列表

node.js - 如何在socket.io中重用redis连接?

c# - 尝试使用 Dialogflow V2 API 中的自定义事件更新意图参数,但它没有传递到意图

c# - 在 C# 中比较两个图像的算法

c# - C# 中的 short 和 ushort 有什么区别?

c# - Automapper - 多对象源和一个目标

python - 如何创建一个Python字典(键: value) from select objects in a JSON file with multiple JSON lines

algorithm - map 渲染 : from data to image tile :Good practice/Sample codes/Tutorial

node.js - Nodejs Redis createClient() 函数

redis dump.rdb 文件未加载