StackExchange.Redis client best practices

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;

 

posted @   从零开始-DotNET技术  阅读(213)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 【杂谈】分布式事务——高大上的无用知识?
点击右上角即可分享
微信分享提示