Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stackexchange.Redis why does ConnectionMultiplexer.Connect establishes two client connections?

I am curious why ConnectionMultiplexer.Connect(options) attempts to connect 2 clients to the RedisDB instead of 1? Each time I connect I see that 2 additional clients connect to my RedisDB.

like image 827
Matt Avatar asked Jan 26 '15 07:01

Matt


People also ask

What is Redis ConnectionMultiplexer?

Redis is the ConnectionMultiplexer class in the StackExchange. Redis namespace; this is the object that hides away the details of multiple servers. Because the ConnectionMultiplexer does a lot, it is designed to be shared and reused between callers. You should not create a ConnectionMultiplexer per operation.

What is lazy ConnectionMultiplexer?

It uses Lazy<T> to handle thread-safe initialization. It sets "abortConnect=false", which means if the initial connect attempt fails, the ConnectionMultiplexer will silently retry in the background rather than throw an exception.

What is ConnectionMultiplexer .NET core?

The ConnectionMultiplexer is the main arbiter of the connection to Redis inside the CLR, your application should maintain a single instance of the ConnectionMultiplexer throughout its runtime. You can initialize the Multiplexer with either a connection string, or with a ConfigurationOptions object.

What is StackExchange Redis?

Overview. StackExchange. Redis is a high performance general purpose redis client for . NET languages (C#, etc.). It is the logical successor to BookSleeve, and is the client developed-by (and used-by) Stack Exchange for busy sites like Stack Overflow.


2 Answers

Because redis requires separate connections for interactive commands versus pub/sub subscriptions. If you aren't using pub/sub, you could tell the options to disable the SUBSCRIBE command, in which case I believe the second connection is not established.

like image 98
Marc Gravell Avatar answered Nov 05 '22 08:11

Marc Gravell


You can turn off second connection if you don't use redis pub/sub

var config = ConfigurationOptions.Parse(redisConnectionString);
config.CommandMap = CommandMap.Create(new HashSet<string> { "SUBSCRIBE" }, false);
connection = ConnectionMultiplexer.Connect(config);
like image 31
Anubis Avatar answered Nov 05 '22 09:11

Anubis