Beispiel #1
0
            public override void MapUnrecognizedLine(string key, string value)
            {
                if (_replicaRegex.IsMatch(key) && value.HasValue())
                {
                    var parts = value.Split(StringSplits.Comma);
                    if (parts.Length == 3)
                    {
                        ReplicaConnections.Add(new RedisReplicaInfo
                        {
                            Index  = int.Parse(key.Replace("slave", "")),
                            IP     = parts[0],
                            Port   = int.Parse(parts[1]),
                            Status = parts[2]
                        });
                    }
                    // redis 2.8+
                    if (parts.Length > 3)
                    {
                        try
                        {
                            var si = new RedisReplicaInfo {
                                Index = int.Parse(key.Replace("slave", ""))
                            };
                            foreach (var p in parts)
                            {
                                var pair = p.Split(StringSplits.Equal);
                                if (pair.Length != 2)
                                {
                                    continue;
                                }
                                var val = pair[1];

                                switch (pair[0])
                                {
                                case "ip":
                                    si.IP = val;
                                    break;

                                case "port":
                                    si.Port = int.Parse(val);
                                    break;

                                case "state":
                                    si.Status = val;
                                    break;

                                case "offset":
                                    si.Offset = long.Parse(val);
                                    break;
                                }
                            }
                            ReplicaConnections.Add(si);
                        }
                        catch (Exception e)
                        {
                            new Exception("Redis error: couldn't parse replica string: " + value, e).Log();
                        }
                    }
                }
            }
Beispiel #2
0
 public RedisInstance GetInstance(RedisReplicaInfo info) => GetInstance(info.Port, info.IPAddress);