Search code examples
asp.netredisninjectinversion-of-controlstackexchange.redis

StackExchange.Redis ConnectionMultiplexer life cycle management in web scenario


What is the correct lifecycle management of the ConnectionMultiplexer instance in a web scenario. As I understand it manages individual requests by pipelining them and thus reduces the negative effect caused by latency. Does that mean that in a web application the ConnectionMultiplexer should be used as a singleton as opposed to the more frequently used request scope?


Solution

  • Essentially, yes - you should rarely need more than one multiplexer to the same Redis nodes. This is also described here. Note that the database object from GetDatabase is very cheap, and can be per request or per method-scope if needed (per-rewuest plays very nicely for multi-tenancy scenarios where different tenants are on different database numbers)