当前位置: 首页>>代码示例>>C#>>正文


C# RedisConnection.GetOpenSubscriberChannel方法代码示例

本文整理汇总了C#中BookSleeve.RedisConnection.GetOpenSubscriberChannel方法的典型用法代码示例。如果您正苦于以下问题:C# RedisConnection.GetOpenSubscriberChannel方法的具体用法?C# RedisConnection.GetOpenSubscriberChannel怎么用?C# RedisConnection.GetOpenSubscriberChannel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BookSleeve.RedisConnection的用法示例。


在下文中一共展示了RedisConnection.GetOpenSubscriberChannel方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RedisMessageBus

        public RedisMessageBus(string server, int port, string password, int db, IEnumerable<string> keys, IDependencyResolver resolver)
            : base(resolver)
        {
            _db = db;
            _keys = keys.ToArray();

            _connection = new RedisConnection(host: server, port: port, password: password);

            _connection.Closed += OnConnectionClosed;
            _connection.Error += OnConnectionError;

            // Start the connection
            _connectTask = _connection.Open().Then(() => {
                // Create a subscription channel in redis
                _channel = _connection.GetOpenSubscriberChannel();

                // Subscribe to the registered connections
                _channel.Subscribe(_keys, OnMessage);

                // Dirty hack but it seems like subscribe returns before the actual
                // subscription is properly setup in some cases
                while (_channel.SubscriptionCount == 0) {
                    Thread.Sleep(500);
                }
            });
        }
开发者ID:tugberkugurlu,项目名称:SignalRWebcast201211,代码行数:26,代码来源:RedisMessageBus.cs

示例2: ConnectionReady

 public bool ConnectionReady()
 {
     if (_redisConnection == null || _redisConnection.State != RedisConnectionBase.ConnectionState.Open)
     {
         lock (_connectionLock)
         {
             if (_redisConnection == null || _redisConnection.State != RedisConnectionBase.ConnectionState.Open)
             {
                 _redisConnection = new RedisConnection(Host, Port, password: Password);
                 try
                 {
                     _redisConnection.Open();
                     _subscriberConnection = _redisConnection.GetOpenSubscriberChannel();
                     _subscriberConnection.MessageReceived += OnRedisMessageReceived;
                     _subscriberConnection.Error += OnRedisError;
                     return true;
                 } 
                 catch (Exception ex)
                 {
                     return false;
                 }
             }
         }
     }
     return true;
 }
开发者ID:Rustemt,项目名称:SignalR.Redis,代码行数:26,代码来源:RedisSignalBus.cs

示例3: RedisSignalBus

 public RedisSignalBus(RedisConnection redisConnection)
 {
     _handlers = new ConcurrentDictionary<string, SafeSet<EventHandler<SignaledEventArgs>>>();
     _redisConnection = redisConnection;
     _subscriberConnection = _redisConnection.GetOpenSubscriberChannel();
     _subscriberConnection.MessageReceived += OnRedisMessageReceived;
 }
开发者ID:JasonPunyon,项目名称:SignalR,代码行数:7,代码来源:RedisSignalBus.cs

示例4: Main

        /// <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();
        }
开发者ID:CrescentFresh,项目名称:TagCache.Redis,代码行数:46,代码来源:Program.cs


注:本文中的BookSleeve.RedisConnection.GetOpenSubscriberChannel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。