I am getting response for the command -sentinel masters against redis server.
public string GetMasterFromSentinel(string sentinelAddress)
{
TcpClient server;
try
{
var splittedAddress = sentinelAddress.Split(':');
server = new TcpClient(splittedAddress[0], int.Parse(splittedAddress[1]));
}
catch (SocketException)
{
return string.Empty;
}
NetworkStream ns = server.GetStream();
var payload = new byte[] { 0x2a, 0x32, 0x0d, 0x0a, 0x24, 0x38, 0x0d, 0x0a, 0x73, 0x65, 0x6e, 0x74, 0x69, 0x6e, 0x65, 0x6c,
0x0d, 0x0a, 0x24, 0x37, 0x0d, 0x0a, 0x6d, 0x61, 0x73, 0x74, 0x65, 0x72, 0x73, 0x0d, 0x0a };
ns.Write(payload, 0, payload.Length);
ns.Flush();
var data = new byte[1024];
ns.Read(data, 0, data.Length);
ns.Close();
server.Close();
string output = string.Empty;
foreach (byte b in data)
output += (Char)b;
output = output.Replace("\r\n", string.Empty).Replace("$","|");
return output;
}
Value of output before removing nulls:"*1\r\n*40\r\n$4\r\nname\r\n$8\r\nmymaster\r\n$2\r\nip\r\n$12\r\n10.93.247.96\r\n$4\r\nport\r\n$4\r\n6379\r\n$5\r\nrunid\r\n$40\r\n03ba9934d84efe28e583f4dca03f5b6c710bd712\r\n$5\r\nflags\r\n$6\r\nmaster\r\n$21\r\nlink-pending-commands\r\n$1\r\n0\r\n$13\r\nlink-refcount\r\n$1\r\n1\r\n$14\r\nlast-ping-sent\r\n$1\r\n0\r\n$18\r\nlast-ok-ping-reply\r\n$3\r\n134\r\n$15\r\nlast-ping-reply\r\n$3\r\n134\r\n$23\r\ndown-after-milliseconds\r\n$5\r\n10000\r\n$12\r\ninfo-refresh\r\n$4\r\n6802\r\n$13\r\nrole-reported\r\n$6\r\nmaster\r\n$18\r\nrole-reported-time\r\n$8\r\n76627249\r\n$12\r\nconfig-epoch\r\n$1\r\n6\r\n$10\r\nnum-slaves\r\n$1\r\n1\r\n$19\r\nnum-other-sentinels\r\n$1\r\n1\r\n$6\r\nquorum\r\n$1\r\n2\r\n$16\r\nfailover-timeout\r\n$6\r\n180000\r\n$14\r\nparallel-syncs\r\n$1\r\n1\r\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
Value of Output after removing nulls:
"*1*40$4name$8mymaster$2ip$1210.73.247.36$4port$46379$5runid$4003ba9934d84efe28e583f4dca03f5b6c710bd712$5flags$6master$21link-pending-commands$10$13link-refcount$11$14last-ping-sent$10$18last-ok-ping-reply$3958$15last-ping-reply$3958$23down-after-milliseconds$510000$12info-refresh$48689$13role-reported$6master$18role-reported-time$876879953$12config-epoch$16$10num-slaves$11$19num-other-sentinels$11$6quorum$12$16failover-timeout$6180000$14parallel-syncs$11\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
I need to convert the respective key and values in a dictionary or object.
What I have tried:
I have tried removing the nulls from output.
Is there proper way to filter/parse the information sent by redis server?
The actual response from Redis will be like:
1) 1) "name"
2) "resque"
3) "ip"
4) "127.0.0.1"
5) "port"
6) "7789"
...