This article is a mirror article of machine translation, please click here to jump to the original article.

View: 1417|Reply: 0

[Source] .NET/C# is optimized with StackExchange.Redis performance

[Copy link]
Posted on 2024-12-23 21:37:10 | | | |
Requirements: Generally, .NET developers use the StackExchange.Redis library to read and write Redis operations, and today I checked the network link and found that the StackExchange.Redis library uses singleton mode and actually establishes 4 TCP long links with the Redis server.

Search online and find netizens to answer"By default, each ConnectionMultiplexer instance in StackExchange.Redis creates at least 2 connections per cache. One for interaction commands and one for publishing/subscribing messages.

If you don't use the pub/sub publishing subscription function, you can actually turn it off to optimize connection usage.

Using the CLIENT LIST command in the Redis server, you can see all client connections,Before optimization, the figure below is shown



The client flags combination means the following:

A: connection to be closed ASAP
b: the client is waiting in a blocking operation
c: connection to be closed after writing entire reply
d: a watched keys has been modified - EXEC will fail
e: the client is excluded from the client eviction mechanism
i: the client is waiting for a VM I/O (deprecated)
M: the client is a master
N: no specific flag set
O: the client is a client in MONITOR mode
P: the client is a Pub/Sub subscriber
r: the client is in readonly mode against a cluster node
S: the client is a replica node connection to this instance
u: the client is unblocked
U: the client is connected via a Unix domain socket
x: the client is in a MULTI/EXEC context
t: the client enabled keys tracking in order to perform client side caching
T: the client will not touch the LRU/LFU of the keys it accesses
R: the client tracking target client is invalid
B: the client enabled broadcast tracking mode
How do I turn off pub/sub publish subscription connections?

Option 1

Modify the .NET code as follows:

Option 2 (recommended)

Modify the connection string directly as follows:

After the modification is completed, rerun the program, and you can see that the publish subscription connection has been closed, as shown in the following figure:



Before: 4 TCP connections were established, and after: 2 TCP connections were established.

Reference:

The hyperlink login is visible.
The hyperlink login is visible.
The hyperlink login is visible.





Previous:Angular code obfuscation encryption made easy
Next:.NET/C# test code for multiple Main method solutions
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com