Code of the week
This piece of code make me so happy:
private static IDictionary<string, Func<Stream, ICommand>> commandFactories =
new Dictionary<string, Func<Stream, ICommand>>
{
//storage
{"add", s => new AddCommand(s)},
{"append", s => new AppendCommand(s)},
{"cas", s => new CasCommand(s)},
{"delete", s => new DeleteCommand(s)},
{"prepend", s => new PrependCommand(s)},
{"replace", s => new ReplaceCommand(s)},
{"set", s => new SetCommand(s)},
// retrieval
{"get", s => new GetCommand(s)},
{"gets", s => new GetsCommand(s)},
//modifications
{"incr", s => new IncrCommand(s)},
{"decr", s => new DecrCommand(s)},
//misc
{"flush_all", s => new FlushAllCommand(s)},
{"quit", s => new QuitCommand(s)},
{"version", s => new VersionCommand(s)},
};
This is something that I do quite often, and it is good to have a way to do it easily.