在應用程式中重用多路複用器
class Program
{
private static Lazy<ConnectionMultiplexer> _multiplexer =
new Lazy<ConnectionMultiplexer>(
() => ConnectionMultiplexer.Connect("localhost"),
LazyThreadSafetyMode.ExecutionAndPublication);
static void Main(string[] args)
{
IDatabase db1 = _multiplexer.Value.GetDatabase(1);
IDatabase db2 = _multiplexer.Value.GetDatabase(2);
}
}