static RedisSlaveRole ParseSlave(int num, string role, RedisReader reader) { reader.ExpectSize(5, num); string master_ip = reader.ReadBulkString(); int port = (int)reader.ReadInt(); string state = reader.ReadBulkString(); long data = reader.ReadInt(); return(new RedisSlaveRole(role, master_ip, port, state, data)); }
public override RedisMasterState Parse(RedisReader reader) { reader.ExpectType(RedisMessage.MultiBulk); reader.ExpectSize(3); long down_state = reader.ReadInt(); string leader = reader.ReadBulkString(); long vote_epoch = reader.ReadInt(); return(new RedisMasterState(down_state, leader, vote_epoch)); }
public override T[] Parse(RedisReader reader) { reader.ExpectType(RedisMessage.MultiBulk); long count = reader.ReadInt(false); return(Read(count, reader)); }
public override RedisSlowLogEntry Parse(RedisReader reader) { reader.ExpectType(RedisMessage.MultiBulk); reader.ExpectSize(4); long id = reader.ReadInt(); long timestamp = reader.ReadInt(); long microseconds = reader.ReadInt(); reader.ExpectType(RedisMessage.MultiBulk); string[] arguments = new string[reader.ReadInt(false)]; for (int i = 0; i < arguments.Length; i++) { arguments[i] = reader.ReadBulkString(); } return(new RedisSlowLogEntry(id, RedisDate.FromTimestamp(timestamp), RedisDate.Micro.FromMicroseconds(microseconds), arguments)); }
static RedisMasterRole ParseMaster(int num, string role, RedisReader reader) { reader.ExpectSize(3, num); long offset = reader.ReadInt(); reader.ExpectType(RedisMessage.MultiBulk); var slaves = new Tuple <string, int, int> [reader.ReadInt(false)]; for (int i = 0; i < slaves.Length; i++) { reader.ExpectType(RedisMessage.MultiBulk); reader.ExpectSize(3); string ip = reader.ReadBulkString(); int port = Int32.Parse(reader.ReadBulkString()); int slave_offset = Int32.Parse(reader.ReadBulkString()); slaves[i] = new Tuple <string, int, int>(ip, port, slave_offset); } return(new RedisMasterRole(role, offset, slaves)); }
public override long?Parse(RedisReader reader) { RedisMessage type = reader.ReadType(); if (type == RedisMessage.Int) { return(reader.ReadInt(false)); } reader.ReadBulkString(false); return(null); }
static RedisSentinelRole ParseSentinel(int num, string role, RedisReader reader) { reader.ExpectSize(2, num); reader.ExpectType(RedisMessage.MultiBulk); string[] masters = new string[reader.ReadInt(false)]; for (int i = 0; i < masters.Length; i++) { masters[i] = reader.ReadBulkString(); } return(new RedisSentinelRole(role, masters)); }
public override Tuple <string, string> Parse(RedisReader reader) { reader.ExpectType(RedisMessage.MultiBulk); long count = reader.ReadInt(false); if (count != 2) { throw new RedisProtocolException("Expected 2 items"); } return(Tuple.Create(reader.ReadBulkString(), reader.ReadBulkString())); }
public override T Parse(RedisReader reader) { reader.ExpectType(RedisMessage.MultiBulk); long count = reader.ReadInt(false); T[] array = new T[count]; for (int i = 0; i < array.Length; i++) { array[i] = _command.Parse(reader); } return(array[_index]); }
public override Tuple <string, string> Parse(RedisReader reader) { reader.ExpectType(RedisMessage.MultiBulk); long count = reader.ReadInt(false); if (count != 2) { return(null); //使用 BLPop 命令在 RedisArray.cs 中报错的解决办法。 #22 } //reader.ExpectSize(2); return(Tuple.Create(reader.ReadBulkString(), reader.ReadBulkString())); }
private static long?ParseStream(Stream stream) { RedisMessage type = RedisReader.ReadType(stream); if (type == RedisMessage.Int) { return(RedisReader.ReadInt(stream, false)); } RedisReader.ReadBulkUTF8(stream, false); return(null); }
public override RedisScan <T> Parse(RedisReader reader) { reader.ExpectType(RedisMessage.MultiBulk); if (reader.ReadInt(false) != 2) { throw new RedisProtocolException("Expected 2 items"); } long cursor = Int64.Parse(reader.ReadBulkString()); T[] items = _command.Parse(reader); return(new RedisScan <T>(cursor, items)); }
public override T Parse(RedisReader reader) { reader.ExpectType(RedisMessage.MultiBulk); long count = reader.ReadInt(false); if (count == -1) { return(default(T)); //使用 BLPop 命令在 RedisArray.cs 中报错的解决办法。 #22 } T[] array = new T[count]; for (int i = 0; i < array.Length; i++) { array[i] = _command.Parse(reader); } return(array[_index]); }
static RedisScan ParseStream(Stream stream) { RedisReader.ExpectType(stream, RedisMessage.MultiBulk); long count = RedisReader.ReadInt(stream, false); RedisScan scan = new RedisScan(); scan.Cursor = Int64.Parse(RedisReader.Read(stream).ToString()); RedisReader.ExpectType(stream, RedisMessage.MultiBulk); scan.Items = new string[RedisReader.ReadInt(stream, false)]; for (int i = 0; i < scan.Items.Length; i++) { scan.Items[i] = RedisReader.Read(stream).ToString(); } return(scan); }
public override Dictionary <string, string> Parse(RedisReader reader) { reader.ExpectType(RedisMessage.MultiBulk); long count = reader.ReadInt(false); var dict = new Dictionary <string, string>(); string key = string.Empty; for (int i = 0; i < count; i++) { if (i % 2 == 0) { key = reader.ReadBulkString(); } else { dict[key] = reader.ReadBulkString(); } } return(dict); }
static Dictionary <string, byte[]> ToDict(RedisReader reader) { reader.ExpectType(RedisMessage.MultiBulk); long count = reader.ReadInt(false); var dict = new Dictionary <string, byte[]>(); string key = String.Empty; for (int i = 0; i < count; i++) { if (i % 2 == 0) { key = reader.ReadBulkString(); } else { dict[key] = reader.ReadBulkBytes(); } } return(dict); }
public override RedisSubscriptionResponse Parse(RedisReader reader) { reader.ExpectType(RedisMessage.MultiBulk); long count = reader.ReadInt(false); string type = reader.ReadBulkString(); switch (type) { case "subscribe": case "unsubscribe": case "psubscribe": case "punsubscribe": return(ParseChannel(type, reader)); case "message": case "pmessage": return(ParseMessage(type, reader)); } throw new RedisProtocolException("Unexpected type " + type); }
public override object[] Parse(RedisReader reader) { if (_parsers.Count == 0) { return(reader.ReadMultiBulk(bulkAsString: true)); } reader.ExpectType(RedisMessage.MultiBulk); long count = reader.ReadInt(false); if (count != _parsers.Count) { throw new RedisProtocolException(String.Format("Expecting {0} array items; got {1}", _parsers.Count, count)); } object[] results = new object[_parsers.Count]; for (int i = 0; i < results.Length; i++) { results[i] = _parsers.Dequeue()(reader); } return(results); }
public override RedisRole Parse(RedisReader reader) { reader.ExpectType(RedisMessage.MultiBulk); int count = (int)reader.ReadInt(false); string role = reader.ReadBulkString(); switch (role) { case "master": return(ParseMaster(count, role, reader)); case "slave": return(ParseSlave(count, role, reader)); case "sentinel": return(ParseSentinel(count, role, reader)); default: throw new RedisProtocolException("Unexpected role: " + role); } }
object[] ReadTransaction(Stream input) { if (!_captureResults) { RedisObjects command = RedisCommand.Exec(); command.Parser(input); return(null); } RedisReader.ExpectType(input, RedisMessage.MultiBulk); long count = RedisReader.ReadInt(input, false); if (count == -1) { return(null); } object[] output = new object[_parsers.Count]; for (int i = 0; i < output.Length; i++) { output[i] = _connection.Read(_parsers.Dequeue()); } return(output); }
private static bool ParseStream(Stream stream) { return(RedisReader.ReadInt(stream) == 1); }
public override long Parse(RedisReader reader) { return(reader.ReadInt()); }
private static DateTime ParseStream(Stream stream) { long timestamp = RedisReader.ReadInt(stream); return(RedisArgs.Epoch + TimeSpan.FromSeconds(timestamp)); }
static RedisSubscriptionChannel ParseChannel(string type, RedisReader reader) { switch (type) { case "subscribe": case "unsubscribe": return(new RedisSubscriptionChannel(type, reader.ReadBulkString(), null, reader.ReadInt())); case "psubscribe": case "punsubscribe": return(new RedisSubscriptionChannel(type, null, reader.ReadBulkString(), reader.ReadInt())); } throw new RedisProtocolException("Unexpected type " + type); }
public override DateTimeOffset Parse(RedisReader reader) { return(FromTimestamp(reader.ReadInt())); }
public override bool Parse(RedisReader reader) { return(reader.ReadInt() == 1); }