Redis, not really perfect!

640?wx_fmt=gif

640?wx_fmt=jpeg


01

Foreword


Clearly, today's Redis has entered a mature stage, but still there are many incurable diseases.Thousands of developers in the development and use of this database, it has a very good document.

I remember the first time you use Redis, in order to query a condition in saving millions of users of a relational database. After continuous optimization of each operation can be controlled in one second or even less , gives me considerable shock.


02

About Redis properties


Before Redis, many Internet companies use MySQL + Memcached architecture that although suitable for mass data storage, but with the increase in business, there will be a lot of problems.

Redis It is in this background is generated, you will find that problems have been encountered Memcached Redis to solve.

So what are the specific characteristics of Redis have it? Roughly divided into the following eight characteristics.

  • Extremely fast. Official data given is 10 million times to read and write ops, largely thanks to these data in memory. Since Redis is open source, when you open the source code, you will find Redis is written in C language, the C language is closest to the computer language code, and only a mere 50,000 lines, to ensure that the speed of Redis. At the same time a Redis just a single thread, the real reason is because a single thread is the most efficient in memory.

  • Persistence. Redis persistence can ensure that the data in memory is saved to disk from time to time, the restart time will be loaded into memory again. Persistence is the way RDB and AOF.

  • It supports a variety of data structures. Respectively support the hash, collection, BitMaps, as well as bitmaps (used for the number of active user statistics, etc.), HyperLogLog (ultra-small memory count unique values, since only 12K, there is a certain error range), GEO (Geographical Information Locator) .

  • Support for multiple programming languages. Support Java, PHP, Python, Ruby,

  • 功能丰富。如发布订阅、Lua 脚本、事务、Pipeline(管道,即当指令到达一定数量后,客户端才会执行)。

  • 简单。不依赖外部库、单线程、只有 23000 行 Code。

  • 主从复制。主节点的数据做副本,这是做高可用的基石。

  • 高可用和分布式。Redis-Sentinel(v2.8)支持高可用,Redis-Cluster(v3.0)支持分布式。

上面是一些 Redis 介绍性的内容,如果你还没有接触过 Redis,但又对此有兴趣的话,这里有适合工作实战的教程

扫码订阅 Redis

640?wx_fmt=png


如果已经开始用到 Redis,那么你在应用过程中是否也遇到过下面的这些问题?


03

关于 Redis 疑难问题


在各种场景中,无论是什么架构,你都可以将 Redis 融入项目中来,这可以解决很多关系数据库无法解决的问题。

比如,现有数据库处理缓慢的任务,或者在原有的基础上开发新的功能,都可以使用 Redis。但大家在实践中总会遇到难题,下面我们盘点一下:

  1. Redis 持久化问题?

  2. Redis 实际应用场景里怎么使用?

  3. 1000 个线程压测时 Redis Incr 出现错误,就是 Timeout,怎么排查?有什么好的经验分享?

  4. 批量查寻是用 MGET 好还是 Hash 更好,Hash 的性能瓶颈是多少,达到多少个 Key 或者多大容量后性能急剧下降?如果需要大批量的查例如 1000 个 Key,用什么方案更好?MGET 在集群模式下的实现方式是什么,怎么知道某个 Key 在哪个集群分片上?Redis 最大并发大约支持 5~10 万并发,假设现在有 20 万或者 50 万并发该怎么办?

  5. Redis 分布式集群的几种解决方案,哨兵等方案结合生产环境经验的区别、优劣是什么?

  6. jedispool 链接对象无法释放,这个怎么办?代码写了在 finally 里面也执行了,然后看客户端连接数越来越多,最后项目挂了怎么办?

  7. Redis 和数据库同步、缓冲穿透、雪崩问题、hyperloglog slowqery 实现原理?

  8. 无论是 Win 或 Linux 都有此现象,服务器 Redis 3.x,客户端 Hiredis,在客户机与服务器间网络不稳定的情况下,客户机可能收不到服务器推送来的消息,以及客户机发布消息时会塞死。是否能提供相关解决经验?

  9. Redis 的连接数用什么命令监测?

  10. Redis 的配置要主要哪些参数调优?

  11. 登录 Redis 出现提示,要求密码 NOAUTH Authentication required 有什么办法可以免密登录?

  12. 有没有在生产环境下用 Redis 做持久化存储的例子?一般怎么配置 AOF 和 RDB?在高并发并且尽量少数据丢失的情况下有哪些优化手段?

  13. 哨兵模式下 Client 是随机挑选其中一个哨兵发送 Request 吗?那么如果这个哨兵 Process 挂了会怎样?

  14. Redis 集群很多个 Redis 的话,是把多个 IP 全部写到代码里面,那会不会导致压力不均衡?

  15. 要开始使用 Redis 的时候,如何预估生产环境需要多少计算资源(Cluster 机器数量、内存、CPU、硬盘空间、Slave 数量等)?有没有一些通用的经验?

  16. AOF 和 RDB 配合着用,恢复数据哪个为主?

  17. 假如内存 8G 的话,Redis 既然是运行在内存中,那 Redis 最大能存多大数据?

熟练使用和运维 Redis 已经成为开发人员的一个必备技能。

国外使用 Redis 的公司包括 Twitter、Instagram 等互联网巨头,而国内对 Redis 的使用更有后来者居上之势,除 BAT 外,新浪微博已成为 Redis 全球最大的使用者。

Click to read the original , this study subscribe Chat, to resolve all of the above Redis gotcha! !

Guess you like

Origin blog.csdn.net/csdnnews/article/details/94682303