Redis Advanced -Redis recommendations twelve thing

Here Insert Picture Description


Command

[Recommended] O (N) N is the number of commands attention

For example hgetall, lrange, smembers, zrange, sinter and other use is not impossible, but the value of N need to be clear. There needs to traverse can use hscan, sscan, zscan instead.


[Recommended] Disable command

Prohibiting the use of the line keys, flushall, flushdb like ban rename mechanism redis command, or using the scan
mode progressive process.


[Recommended] the rational use of select

redis multi-database is weak, the use of numbers to distinguish between, a lot of client support is poor, while the single-threaded or multi-service real multi-database processing, there will be interference.


[Recommended] use batch operations to improve efficiency

Native Command: eg mget, mset.
Non-native command: You can use the pipeline to improve efficiency

Note that the number of control but a batch operation elements (e.g. less than 500, and also the actual number of bytes of the relevant elements).

pipeline vs Native Command

  1. Native command is atomic, pipeline operations are non-atomic.
  2. pipeline can be packaged in different orders, native can not do
  3. pipeline requires the client and server support both

[Proposed] Redis transaction function is weak, is not recommended to use too much, you can substitute with lua


Clients use

[Recommended] to avoid multiple applications using a Redis instance

Positive examples: irrelevant split the business, doing public service of data.


With the database connection pool, it can effectively control the connection while improving efficiency

other suggestion

Published 825 original articles · won praise 2060 · Views 4.2 million +

Guess you like

Origin blog.csdn.net/yangshangwei/article/details/105020406