码迷,mamicode.com
首页 > 其他好文 > 详细

StackExchange.Redis client best practices

时间:2020-07-25 23:55:39      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:stack   efault   seconds   chm   opera   att   lse   false   his   

StackExchange.Redis client best practices


1. Enabling server GC can optimize the client and provide better performance and throughput.
2. Set AbortOnConnectFail to false, when AbortOnConnectFail is false, the StackExchange.Redis will reconnect automatically.
3. Reuse the ConnectionMultiplexer, do not create a new one for each request. The Lazy<ConnectionMultiplexer> pattern is recommended.
4. Redis works best with smaller values, so consider chopping up bigger data into multiple keys. In this Redis discussion, 100KB is considered large.
5. Configure your ThreadPool settings to avoid timeouts.
6. Use at least the default connectTimeout of 5 seconds.
7. Be aware of the performance costs associated with different operations you are running. For instance, the KEYS command is an O(n) operation and should be avoided.

Performance testing
redis-benchmakr.exe

examples:
private static readonly Lazy<ConnectionMultiplexer> _lazy = new Lazy<ConnectionMultiplexer>(()=>{
string connectionString = ConfigurationManager.AppSettings["RedisConnection"].ToString();
return ConnectionMultiplexer.Connect(connectionString);
});

public static ConnectionMultiplexer Connection => _lazy.Value;

 

StackExchange.Redis client best practices

标签:stack   efault   seconds   chm   opera   att   lse   false   his   

原文地址:https://www.cnblogs.com/yycelsu/p/13376147.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!