2014-11-13 87 views
1

我試圖訪問使用ServiceStack.Redis .NET應用程序的密鑰空間通知訪問密鑰空間的通知。我是Redis的新手。如何使用ServiceStack.redis

我啓用高速緩存事件通知的命令:

CONFIG SET notify-keyspace-events KEs 

我訂閱的頻道 「鍵*:*」 在.NET。以下是我的代碼:

const string ChannelName = "__key*__:*"; 
    using (var redisConsumer = new RedisClient("localhost:6379")) 
    using (var subscription = redisConsumer.CreateSubscription()) 
    { 
     subscription.OnSubscribe = channel => 
     { 
      Console.WriteLine(String.Format("Subscribed to '{0}'", channel)); 
     }; 
     subscription.OnUnSubscribe = channel => 
     { 
      Console.WriteLine(String.Format("UnSubscribed from '{0}'", channel)); 
     }; 
     subscription.OnMessage = (channel, msg) => 
     { 
      Console.WriteLine(String.Format("Received '{0}' from channel '{1}'", 
       msg, channel)); 
     };    

     Console.WriteLine(String.Format("Started Listening On '{0}'", ChannelName)); 
     subscription.SubscribeToChannels(ChannelName); //blocking 
    } 

從另一個.Net應用程序中,我將新數據添加到緩存中。我期待着收到一個事件(在的onMessage)。該應用程序沒有捕獲任何情況下,在高速緩存中加入新的項目。

但是,當我在redis-cli.exe上運行命令「psubscribe」key *:*'「時,它會正確捕獲事件。 (當我添加一個新的項目,以高速緩存,它會顯示在控制檯窗口中的事件的詳細信息。)

我無法捕捉到相同的我的應用程序。我在這裏錯過了什麼嗎?

回答

1

使用subscription.SubscribeToChannelsMatching(ChannelName);

相關問題