Esempio n. 1
0
 /// <summary>
 /// Create new instance of subscribe-only RedisClient
 /// </summary>
 /// <param name="host">Redis server host or IP</param>
 /// <param name="port">Redis server port</param>
 /// <param name="password">Redis server password</param>
 public RedisSubscriptionClient(string host, int port, string password = null)
 {
     _activity = new ActivityTracer("New Redis subscription client");
     _connection = new RedisConnection(host, port);
     _connection.Connect(0, 1000);
     if (!String.IsNullOrEmpty(password))
     {
         var cmd = RedisCommand.Auth(password);
         _connection.Call(cmd.Parser, cmd.Command, cmd.Arguments);
     }
     _readCancel = new CancellationTokenSource();
     _reader = Task.Factory.StartNew(Read_Task);
     _callbackDispatchers = new Dictionary<string, RedisSubscriptionDispatcher>();
 }
Esempio n. 2
0
        /// <summary>
        /// Release resources used by the current RedisSubscriptionClient
        /// </summary>
        public void Dispose()
        {
            if (_readCancel != null)
                _readCancel.Cancel();

            if (_reader != null)
            {
                _reader.Wait();
                _reader.Dispose();
            }
            if (_connection != null)
                _connection.Dispose();

            if (_callbackDispatchers != null)
                _callbackDispatchers.Clear();

            _count = 0;

            if (_activity != null)
                _activity.Dispose();
            _activity = null;
        }