Redis tips

1. Differentiated Services

  1. Scene : the premise is the use of multi-service is the same redis, with Redis, there will be a lot of cache Key among multi-service, simply can not know which key is which part of the business, such as: KEY: user: 1000, user : book, book , user: like: book, book : user; there may even be key conflict.
  2. Solution : is to force the process, giving developers to differentiate business, every business is in front of the development, management laid down, the management is relatively simple. Simple code as a prefix to the business of redis key.

2. elegant expansion

  1. Scene : When we develop web services, will connect with similar jedis Redis server client, will join Redis cluster address in the configuration file. But when the system encounters Redis load is too high, or redis data capacity is needed, we need to add Redis server. Then you need to re-profile Redis cluster changes, and then restart the application.
  2. Solution : the principle is relatively simple, the program is able to know if Redis cluster address had changed, re-set about the connection configuration jedis client. The question now is how to know Redis cluster address has changed?
    We can use the Redis cluster address configuration zookeeper, the application at startup, get the value of the cluster address on the zk, is initialized. If you want to change the cluster address to be set zk above.

3. abnormal

  1. Scene : Because different businesses, different team, different developers in the real business scenario, we can not avoid managers bug exists, the line can not predict what kind of problems will happen? Such as: discovery Redis cluster unstable situation, cpu load is very high, then how do we know which business caused it?
  2. Solution :
    1. The nature of the problem: this unusual problem, in fact, a monitor problem, we need to use Redis circumstances of each client monitor. How to monitor? Need a monitoring tool, the Internet has several monitoring tools, recommended millet-Falcon Open .
    2. redis Use: reuse Aop knockdown Redis operations, a Redis interception operation, the relevant data package. Every minute to report the data to the open-falcon platform. What specific monitoring data by business decisions, the general should set key, business, long operating time, which client IP initiated, all need to be monitored . You can set an alarm in the relevant rules, such as: a key has been called, too high operating frequency over a period of time. This can easily lead to the investigation which key cpu load is too high, you can take a look to set this key code, there is no problem? It is not dead circulation problems?

Guess you like

Origin blog.csdn.net/weixin_38608626/article/details/93713977
Recommended