github.com/binbinly/pkg@v0.0.11-0.20240321014439-f4fbf666eb0f/storage/redis/README.md (about) 1 2 单元测试可以使用 https://github.com/alicebob/miniredis, 可以开启一个本地的模拟redis 3 4 - [在单元测试中模拟Redis](https://medium.com/@elliotchance/mocking-redis-in-unit-tests-in-go-28aff285b98) 5 6 ## 案例 7 8 - [Redis分布式锁没用明白,搞出了大故障…](https://mp.weixin.qq.com/s/BO-gly5iGLVmuG5B_FIpoQ) 9 - [看完这篇Redis缓存三大问题](https://mp.weixin.qq.com/s/HjzwefprYSGraU1aJcJ25g) 10 11 ## Redis 优化方向 12 13 ### 参数优化 14 15 maxIdle设置高点,可以保证突发流量情况下,能够有足够的连接去获取redis,不用在高流量情况下建立连接 16 17 **go-redis参数优化** 18 19 ```yaml 20 min_idle_conn: 30 21 dial_timeout: "1s" 22 read_timeout: "500ms" 23 write_timeout: "500ms" 24 pool_size: 500 25 pool_timeout: "60s" 26 ``` 27 28 **redisgo参数优化** 29 30 ```yaml 31 maxIdle = 30 32 maxActive = 500 33 dialTimeout = "1s" 34 readTimeout = "500ms" 35 writeTimeout = "500ms" 36 idleTimeout = "60s" 37 ``` 38 39 ### 使用优化 40 41 - 增加redis从库 42 - 对批量数据,根据redis从库数量,并发goroutine拉取数据 43 - 对批量数据大量使用pipeline指令 44 - 精简key字段 45 - redis的value存储编解码改为msgpack 46 47 ## Pipeline 48 - https://redis.io/topics/pipelining 49 - [兼容go redis cluster的pipeline批量](http://xiaorui.cc/archives/5557) 50 - https://www.tizi365.com/archives/309.html