c#实现redis发布订阅

需要添加引用using StackExchange.Redis;

        public static void pushRedis()
        {
            try
            {
                ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("连接字符串");//如果没有密码就直接写ip地址和端口
                ISubscriber sub = redis.GetSubscriber();
                sub.Publish(消息通道, 值);
                //sub.Subscribe(消息通道, (channel, message) =>
                //{
                //    Console.WriteLine(订阅收到消息:" + message);
                //});
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }

 

你可能感兴趣的:(.net,c#,redis)