private void Subscribe()
        {
            channel         = gateway.GetConnection().GetOpenSubscriberChannel();
            channel.Closed += OnChannelClosed;

            channel.PatternSubscribe(ChannelPattern, OnMessageRecieved);
        }
示例#2
0
        /// <summary>
        /// This is a small application to test event subscriptions in redis - which are required for automatic expiry of cache items
        /// if subscriptions dont work try setting the redis config :
        /// config set notify-keyspace-events Ex
        /// </summary>
        /// <param name="args"></param>
        private static void Main(string[] args)
        {
            Console.WriteLine("Start");

            _conn = new RedisConnection("localhost");
            var c = _conn.Open();

            c.Wait();
            Console.WriteLine("Conn : " + _conn.State);

            _conn.Keys.Remove(_db, "_expireys");


            _subConn = new RedisSubscriberConnection("localhost");
            var s = _subConn.Open();

            s.Wait();
            Console.WriteLine("SubConn : " + _subConn.State);

            channel = _conn.GetOpenSubscriberChannel();
            Thread.Sleep(100);

            Console.WriteLine("Channel : " + channel.State);

            channel.PatternSubscribe("*:expired", OnExecutionCompleted).Wait();

            Console.WriteLine("Subscriptions : " + channel.SubscriptionCount);


            Set(1, 4);
            Thread.Sleep((6 * 1000));
            if (received > 0)
            {
                Console.WriteLine("Subscriptions have worked");
            }
            else
            {
                Console.WriteLine("Subscriptions have not worked");
            }

            Console.ReadKey();
        }