示例#1
0
        RedisHost IHostHandler.AddReadHost(string host, int port = 6379)
        {
            RedisHost redisHost = new RedisHost(DB, host, port);

            mReadHosts.Add(redisHost);
            mReadActives = mReadHosts.ToArray();
            return(redisHost);
        }
示例#2
0
 private async void OnSubscrib(object state)
 {
     try
     {
         if (mTimer != null)
         {
             mTimer.Dispose();
             mTimer = null;
         }
         if (redisClient != null)
         {
             redisClient.TcpClient.DisConnect();
         }
         Result    result;
         RedisHost host = mDB.Host.GetWriteHost();
         if (host == null)
         {
             result = new Result()
             {
                 ResultType = ResultType.NetError, Messge = "redis server is not available"
             };
         }
         else
         {
             redisClient      = host.Create();
             mCommand         = new Commands.SUBSCRIBE(mDB.DataFormater, mChannels.Keys.ToArray());
             mCommand.Reader  = OnBlockingRead;
             subscribeRequest = new SubscribeRequest(host, redisClient, mCommand, typeof(string));
             result           = await subscribeRequest.Execute();
         }
         if (result.ResultType == ResultType.NetError || result.ResultType == ResultType.DataError || result.ResultType == ResultType.Error)
         {
             OnReceive(new SubscribeMessage {
                 Type = SubscribeMessageType.Error, Data = result.Messge
             });
             if (redisClient.TcpClient.IsConnected)
             {
                 var pipeStream = redisClient.TcpClient.Stream.ToPipeStream();
                 pipeStream.ReadFree((int)pipeStream.Length);
             }
             else
             {
                 ReOnSubscrib();
             }
         }
         else
         {
             ProcessReceiveData(result);
             OnReadMessave();
         }
     }
     catch (Exception e_)
     {
         OnReceive(new SubscribeMessage {
             Type = SubscribeMessageType.Error, Data = e_.Message
         });
     }
 }
示例#3
0
 public RedisRequest(RedisHost host, RedisClient client, Command cmd, params Type[] types)
 {
     Client = client;
     Client.TcpClient.DataReceive = OnReceive;
     Client.TcpClient.ClientError = OnError;
     Command = cmd;
     Types   = types;
     Host    = host;
 }
示例#4
0
        RedisHost IHostHandler.AddWriteHost(string host, int port, bool ssl)
        {
            if (port == 0)
            {
                port = 6379;
            }
            RedisHost redisHost = new RedisHost(ssl, DB, host, port);

            mWriteHosts.Add(redisHost);
            mWriteActives = mWriteHosts.ToArray();
            return(redisHost);
        }
示例#5
0
 public SubscribeRequest(RedisHost host, RedisClient client, Command cmd, params Type[] types)
     : base(host, client, cmd, types)
 {
 }