C# 与sider redis C客户端一起使用发布/订阅

C# 与sider redis C客户端一起使用发布/订阅,c#,redis,system.reactive,observable,redisclient,C#,Redis,System.reactive,Observable,Redisclient,我正在使用Sider C Redis客户端连接到运行在Windows7机器上的Redis服务器。 我可以从我的C应用程序中启动设置/获取/选择 我现在想使用发布/订阅功能,这样我的C应用程序就可以通过代理以事件方式通知redis客户端密钥的任何更改 我无法为此编写代码,因为没有关于如何使用sider客户端页面的示例 我所能写的就是: var client = new RedisClient(address, 6379); string[] keys = new string[1]; keys[

我正在使用Sider C Redis客户端连接到运行在Windows7机器上的Redis服务器。

我可以从我的C应用程序中启动设置/获取/选择

我现在想使用发布/订阅功能,这样我的C应用程序就可以通过代理以事件方式通知redis客户端密钥的任何更改

我无法为此编写代码,因为没有关于如何使用sider客户端页面的示例

我所能写的就是:

var client = new RedisClient(address, 6379);
string[] keys = new string[1];
keys[0] = "key1ToMonitor";
IObservable<Message<string>> obb = client.Subscribe(keys);
我知道这看起来很蹩脚,但我不知道如何以lambda的方式编写它,如果任何客户端更改redis服务器上所需的密钥,就会调用我的函数

PS:我是新手,所以如果我的方法有缺陷,请纠正我

编辑:在添加建议的更改时,我得到以下错误

Error   7   Cannot convert lambda expression to type 'System.IObserver<Sider.Message<string>>' because it is not a delegate type    D:\_Work\TestApp\Program.cs 90  27  TestApp
obb.subscribe签名如下所示

namespace System
{
    // Summary:
    //     Defines a provider for push-based notification.
    //
    // Type parameters:
    //   T:
    //     The object that provides notification information.This type parameter is
    //     covariant. That is, you can use either the type you specified or any type
    //     that is more derived. For more information about covariance and contravariance,
    //     see Covariance and Contravariance in Generics.
    public interface IObservable<out T>
    {
        // Summary:
        //     Notifies the provider that an observer is to receive notifications.
        //
        // Parameters:
        //   observer:
        //     The object that is to receive notifications.
        //
        // Returns:
        //     The observer's interface that enables resources to be disposed.
        IDisposable Subscribe(IObserver<T> observer);
    }
}
代码:


您需要订阅生成的实际可观测数据。大概是这样的:

obb.Subscribe(x => Debug.WriteLine(x.ToString()));

不要忘记添加using System.Reactive.Linq;要获得将lambda转换为观察者所需的扩展。

您需要订阅生成的实际观察值。大概是这样的:

obb.Subscribe(x => Debug.WriteLine(x.ToString()));

不要忘记添加using System.Reactive.Linq;获取将lambda转换为observer所需的扩展。

此库似乎具有奇怪的observer语法,因此您必须再次订阅obb才能查看结果。请尝试obb.Subscribex=>Debug.WriteLinex.ToString,并告诉我您得到了什么结果。您能在代码中准确地显示您是如何尝试建议的更改的吗?@Enigmativity code addedTry System.Diagnostics.Debug.WriteLine.error不是因为这个原因。错误是:错误7无法将lambda表达式转换为类型“System.IObserver”,因为它不是委托类型D:\u Work\TestApp\Program.cs 90 27 TestApp此库似乎具有奇怪的可观察语法,因此您必须再次订阅obb才能查看结果。请尝试obb.Subscribex=>Debug.WriteLinex.ToString,并告诉我您得到了什么结果。您能在代码中准确地显示您是如何尝试建议的更改的吗?@Enigmativity code addedTry System.Diagnostics.Debug.WriteLine.error不是因为这个原因。错误是:错误7无法将lambda表达式转换为类型“System.IObserver”,因为它不是委托类型D:\u Work\TestApp\Program.cs 90 27 TestApp