Redis 的订阅发布(PUB/SUB)示例

            ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("127.0.0.1");
            ISubscriber sub = redis.GetSubscriber();
            Console.WriteLine("我要订阅messages");
            sub.Subscribe("messages", (channel, message) =>
            {
                Console.WriteLine((string)message);
            });
            Console.WriteLine("过2s后我就发布");
            Thread.Sleep(2000);
            sub.Publish("messages", "哈哈,你能抓到我吗?");
            Console.Read();

  

posted @ 2017-05-17 17:56  上古时期的码农  阅读(182)  评论(0编辑  收藏  举报