migueldeicaza/redis-sharp — pull request #9 by rfranke (2014-08-26 20:18:28+00:00)
Title: PubSub2

Here is another pull request for the pub/sub implementation. The new RedisSub extends from Redis and adds (p)(un)subscribe methods. Received messages are treated as C# events.

A new ReadMixedArray method has been added to receive arrays with elements of mixed data types and nested arrays -- subscribe messages contain an integer element. The new Redis Scan method has been added as a second use case for such mixed arrays (and because it is an important alternative to the KEYS command for large databases).

Note that Redis subscribers must not send regular Redis commands, in order to not mess up command replies with messages. This is also why the QUIT command has been commented out in Redis.Dispose(). One might consider to split the existing Redis class into a basic RedisClient that just treats the connection and the communication protocol -- comparable to the redis-cli program -- and a second Redis class that extends from RedisClient and provides all the C# methods for specific commands. RedisSub could then extend from the RedisClient as well and would not inherit commands that should not be used by subscribers. Redis.Dispose() could then call QUIT, while RedisClient.Dispose() would close the socket.