/// <summary> /// Read multi-bulk response from Redis server /// </summary> /// <param name="response"></param> /// <returns></returns> public static RedisSubscriptionResponse ReadResponse(object[] response) { RedisSubscriptionResponseType type = ParseType(response[0] as String); RedisSubscriptionResponse obj; switch (type) { case RedisSubscriptionResponseType.Subscribe: case RedisSubscriptionResponseType.Unsubscribe: case RedisSubscriptionResponseType.PSubscribe: case RedisSubscriptionResponseType.PUnsubscribe: obj = new RedisSubscriptionChannel(type, response); break; case RedisSubscriptionResponseType.Message: case RedisSubscriptionResponseType.PMessage: obj = new RedisSubscriptionMessage(type, response); break; default: throw new RedisProtocolException("Unexpected response type: " + type); } obj.Type = type; return(obj); }
/// <summary> /// Instantiate a new instance of the RedisSubscriptionChannel class /// </summary> /// <param name="type">The type of channel response</param> /// <param name="response">Redis multi-bulk response</param> public RedisSubscriptionChannel(RedisSubscriptionResponseType type, object[] response) { switch (type) { case RedisSubscriptionResponseType.Subscribe: case RedisSubscriptionResponseType.Unsubscribe: Channel = response[1] as String; break; case RedisSubscriptionResponseType.PSubscribe: case RedisSubscriptionResponseType.PUnsubscribe: Pattern = response[1] as String; break; } Count = (long)response[2]; ActivityTracer.Info("Subscription response: type={0}; channel={1}; pattern={2}; count={3}", Type, Channel, Pattern, Count); }
/// <summary> /// Instantiate a new instance of the RedisSubscriptionChannel class /// </summary> /// <param name="type">The type of channel response</param> /// <param name="response">Redis multi-bulk response</param> public RedisSubscriptionChannel(RedisSubscriptionResponseType type, object[] response) { switch (type) { case RedisSubscriptionResponseType.Subscribe: case RedisSubscriptionResponseType.Unsubscribe: Channel = response[1] as String; break; case RedisSubscriptionResponseType.PSubscribe: case RedisSubscriptionResponseType.PUnsubscribe: Pattern = response[1] as String; break; } Count = (long)response[2]; ActivityTracer.Info("Subscription response: type={0}; channel={1}; pattern={2}; count={3}", Type, Channel, Pattern, Count); }
/// <summary> /// Instantiate a new instance of the RedisSubscriptionMessage class /// </summary> /// <param name="type">The type of message response</param> /// <param name="response">Redis multi-bulk response</param> public RedisSubscriptionMessage(RedisSubscriptionResponseType type, object[] response) { switch (type) { case RedisSubscriptionResponseType.Message: Channel = response[1] as String; Body = response[2] as String; break; case RedisSubscriptionResponseType.PMessage: Pattern = response[1] as String; Channel = response[2] as String; Body = response[3] as String; break; } ActivityTracer.Info("Subscription message: type={0}; channel={1}; pattern={2}; body={3}", Type, Channel, Pattern, Body); }
/// <summary> /// Instantiate a new instance of the RedisSubscriptionMessage class /// </summary> /// <param name="type">The type of message response</param> /// <param name="response">Redis multi-bulk response</param> public RedisSubscriptionMessage(RedisSubscriptionResponseType type, object[] response) { switch (type) { case RedisSubscriptionResponseType.Message: Channel = response[1] as String; Body = response[2] as String; break; case RedisSubscriptionResponseType.PMessage: Pattern = response[1] as String; Channel = response[2] as String; Body = response[3] as String; break; } ActivityTracer.Info("Subscription message: type={0}; channel={1}; pattern={2}; body={3}", Type, Channel, Pattern, Body); }