Beispiel #1
0
        /// <summary>
        /// Format the object as a string
        /// </summary>
        public override string ToString()
        {
            string addr = Format.ToString(Address);

            return(string.IsNullOrWhiteSpace(Name) ? addr : (addr + " - " + Name));
        }
Beispiel #2
0
        internal static ClientInfo[] Parse(string input)
        {
            if (input == null)
            {
                return(null);
            }

            var clients = new List <ClientInfo>();

            using (var reader = new StringReader(input))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    var client = new ClientInfo();
                    client.Raw = line;
                    string[] tokens = line.Split(StringSplits.Space);
                    for (int i = 0; i < tokens.Length; i++)
                    {
                        string tok = tokens[i];
                        int    idx = tok.IndexOf('=');
                        if (idx < 0)
                        {
                            continue;
                        }
                        string key = tok.Substring(0, idx), value = tok.Substring(idx + 1);

                        switch (key)
                        {
                        case "addr": client.Address = Format.TryParseEndPoint(value); break;

                        case "age": client.AgeSeconds = Format.ParseInt32(value); break;

                        case "idle": client.IdleSeconds = Format.ParseInt32(value); break;

                        case "db": client.Database = Format.ParseInt32(value); break;

                        case "name": client.Name = value; break;

                        case "sub": client.SubscriptionCount = Format.ParseInt32(value); break;

                        case "psub": client.PatternSubscriptionCount = Format.ParseInt32(value); break;

                        case "multi": client.TransactionCommandLength = Format.ParseInt32(value); break;

                        case "cmd": client.LastCommand = value; break;

                        case "flags":
                            client.FlagsRaw = value;
                            ClientFlags flags = ClientFlags.None;
                            AddFlag(ref flags, value, ClientFlags.SlaveMonitor, 'O');
                            AddFlag(ref flags, value, ClientFlags.Slave, 'S');
                            AddFlag(ref flags, value, ClientFlags.Master, 'M');
                            AddFlag(ref flags, value, ClientFlags.Transaction, 'x');
                            AddFlag(ref flags, value, ClientFlags.Blocked, 'b');
                            AddFlag(ref flags, value, ClientFlags.TransactionDoomed, 'd');
                            AddFlag(ref flags, value, ClientFlags.Closing, 'c');
                            AddFlag(ref flags, value, ClientFlags.Unblocked, 'u');
                            AddFlag(ref flags, value, ClientFlags.CloseASAP, 'A');
                            client.Flags = flags;
                            break;
                        }
                    }
                    clients.Add(client);
                }
            }

            return(clients.ToArray());
        }
Beispiel #3
0
 public override string ToString() => ConnectionType + "/" + Format.ToString(ServerEndPoint.EndPoint);
Beispiel #4
0
        public Task ClientKillAsync(EndPoint endpoint, CommandFlags flags = CommandFlags.None)
        {
            var msg = Message.Create(-1, flags, RedisCommand.CLIENT, RedisLiterals.KILL, (RedisValue)Format.ToString(endpoint));

            return(ExecuteAsync(msg, ResultProcessor.DemandOK));
        }
 /// <summary>
 /// Adds a new endpoint to the list
 /// </summary>
 public void Add(string host, int port)
 {
     Add(Format.ParseEndPoint(host, port));
 }
 public override string ToString()
 {
     return(ConnectionType + "/" + Format.ToString(ServerEndPoint.EndPoint));
 }
 /// <summary>
 /// Attempt to parse a string into an EndPoint
 /// </summary>
 public static EndPoint TryParse(string endpoint)
 {
     return(Format.TryParseEndPoint(endpoint));
 }
 /// <summary>
 /// Format an endpoint
 /// </summary>
 public static string ToString(EndPoint endpoint)
 {
     return(Format.ToString(endpoint));
 }
Beispiel #9
0
        private void DoParse(string configuration, bool ignoreUnknown)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (string.IsNullOrWhiteSpace(configuration))
            {
                throw new ArgumentException("is empty", configuration);
            }

            Clear();

            // break it down by commas
            var arr = configuration.Split(StringSplits.Comma);
            Dictionary <string, string> map = null;

            foreach (var paddedOption in arr)
            {
                var option = paddedOption.Trim();

                if (string.IsNullOrWhiteSpace(option))
                {
                    continue;
                }

                // check for special tokens
                int idx = option.IndexOf('=');
                if (idx > 0)
                {
                    var key   = option.Substring(0, idx).Trim();
                    var value = option.Substring(idx + 1).Trim();

                    switch (OptionKeys.TryNormalize(key))
                    {
                    case OptionKeys.SyncTimeout:
                        SyncTimeout = OptionKeys.ParseInt32(key, value, minValue: 1);
                        break;

                    case OptionKeys.AllowAdmin:
                        AllowAdmin = OptionKeys.ParseBoolean(key, value);
                        break;

                    case OptionKeys.AbortOnConnectFail:
                        AbortOnConnectFail = OptionKeys.ParseBoolean(key, value);
                        break;

                    case OptionKeys.ResolveDns:
                        ResolveDns = OptionKeys.ParseBoolean(key, value);
                        break;

                    case OptionKeys.ServiceName:
                        ServiceName = value;
                        break;

                    case OptionKeys.ClientName:
                        ClientName = value;
                        break;

                    case OptionKeys.ChannelPrefix:
                        ChannelPrefix = value;
                        break;

                    case OptionKeys.ConfigChannel:
                        ConfigurationChannel = value;
                        break;

                    case OptionKeys.KeepAlive:
                        KeepAlive = OptionKeys.ParseInt32(key, value);
                        break;

                    case OptionKeys.ConnectTimeout:
                        ConnectTimeout = OptionKeys.ParseInt32(key, value);
                        break;

                    case OptionKeys.ConnectRetry:
                        ConnectRetry = OptionKeys.ParseInt32(key, value);
                        break;

                    case OptionKeys.ConfigCheckSeconds:
                        ConfigCheckSeconds = OptionKeys.ParseInt32(key, value);
                        break;

                    case OptionKeys.Version:
                        DefaultVersion = OptionKeys.ParseVersion(key, value);
                        break;

                    case OptionKeys.Password:
                        Password = value;
                        break;

                    case OptionKeys.TieBreaker:
                        TieBreaker = value;
                        break;

                    case OptionKeys.Ssl:
                        Ssl = OptionKeys.ParseBoolean(key, value);
                        break;

                    case OptionKeys.SslHost:
                        SslHost = value;
                        break;

                    case OptionKeys.HighPrioritySocketThreads:
                        HighPrioritySocketThreads = OptionKeys.ParseBoolean(key, value);
                        break;

                    case OptionKeys.WriteBuffer:
                        WriteBuffer = OptionKeys.ParseInt32(key, value);
                        break;

                    case OptionKeys.Proxy:
                        Proxy = OptionKeys.ParseProxy(key, value);
                        break;

                    case OptionKeys.ResponseTimeout:
                        ResponseTimeout = OptionKeys.ParseInt32(key, value, minValue: 1);
                        break;

                    case OptionKeys.DefaultDatabase:
                        defaultDatabase = OptionKeys.ParseInt32(key, value);
                        break;

                    default:
                        if (!string.IsNullOrEmpty(key) && key[0] == '$')
                        {
                            RedisCommand cmd;
                            var          cmdName = option.Substring(1, idx - 1);
                            if (Enum.TryParse(cmdName, true, out cmd))
                            {
                                if (map == null)
                                {
                                    map = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                                }
                                map[cmdName] = value;
                            }
                        }
                        else
                        {
                            if (!ignoreUnknown)
                            {
                                OptionKeys.Unknown(key);
                            }
                        }
                        break;
                    }
                }
                else
                {
                    var ep = Format.TryParseEndPoint(option);
                    if (ep != null && !endpoints.Contains(ep))
                    {
                        endpoints.Add(ep);
                    }
                }
            }
            if (map != null && map.Count != 0)
            {
                CommandMap = CommandMap.Create(map);
            }
        }
        internal SocketToken BeginConnect(EndPoint endpoint, ISocketCallback callback, ConnectionMultiplexer multiplexer, TextWriter log)
        {
            var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            SetFastLoopbackOption(socket);
            socket.NoDelay = true;
            try
            {
                CompletionType connectCompletionType = CompletionType.Any;
                this.ShouldForceConnectCompletionType(ref connectCompletionType);

                var formattedEndpoint = Format.ToString(endpoint);
                var tuple             = Tuple.Create(socket, callback);
                if (endpoint is DnsEndPoint)
                {
                    // A work-around for a Mono bug in BeginConnect(EndPoint endpoint, AsyncCallback callback, object state)
                    DnsEndPoint dnsEndpoint = (DnsEndPoint)endpoint;

#if CORE_CLR
                    multiplexer.LogLocked(log, "BeginConnect: {0}", formattedEndpoint);
                    socket.ConnectAsync(dnsEndpoint.Host, dnsEndpoint.Port).ContinueWith(t =>
                    {
                        multiplexer.LogLocked(log, "EndConnect: {0}", formattedEndpoint);
                        EndConnectImpl(t, multiplexer, log, tuple);
                        multiplexer.LogLocked(log, "Connect complete: {0}", formattedEndpoint);
                    });
#else
                    CompletionTypeHelper.RunWithCompletionType(
                        (cb) => {
                        multiplexer.LogLocked(log, "BeginConnect: {0}", formattedEndpoint);
                        return(socket.BeginConnect(dnsEndpoint.Host, dnsEndpoint.Port, cb, tuple));
                    },
                        (ar) => {
                        multiplexer.LogLocked(log, "EndConnect: {0}", formattedEndpoint);
                        EndConnectImpl(ar, multiplexer, log, tuple);
                        multiplexer.LogLocked(log, "Connect complete: {0}", formattedEndpoint);
                    },
                        connectCompletionType);
#endif
                }
                else
                {
#if CORE_CLR
                    multiplexer.LogLocked(log, "BeginConnect: {0}", formattedEndpoint);
                    socket.ConnectAsync(endpoint).ContinueWith(t =>
                    {
                        multiplexer.LogLocked(log, "EndConnect: {0}", formattedEndpoint);
                        EndConnectImpl(t, multiplexer, log, tuple);
                    });
#else
                    CompletionTypeHelper.RunWithCompletionType(
                        (cb) => {
                        multiplexer.LogLocked(log, "BeginConnect: {0}", formattedEndpoint);
                        return(socket.BeginConnect(endpoint, cb, tuple));
                    },
                        (ar) => {
                        multiplexer.LogLocked(log, "EndConnect: {0}", formattedEndpoint);
                        EndConnectImpl(ar, multiplexer, log, tuple);
                        multiplexer.LogLocked(log, "Connect complete: {0}", formattedEndpoint);
                    },
                        connectCompletionType);
#endif
                }
            }
            catch (NotImplementedException ex)
            {
                if (!(endpoint is IPEndPoint))
                {
                    throw new InvalidOperationException("BeginConnect failed with NotImplementedException; consider using IP endpoints, or enable ResolveDns in the configuration", ex);
                }
                throw;
            }
            var token = new SocketToken(socket);
            return(token);
        }
 public override string ToString()
 {
     return(Format.ToString(EndPoint));
 }