Get the App
SLTechnology News&Howtos  ›  Development  › 

Why should Redis avoid executing commands with high time complexity

Shulou Source: shulou.com Published: 2022-06-01 06:58:36 09月21日 Update

This article mainly shows you "why Redis should avoid executing commands with high time complexity", which is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "Why Redis should avoid executing commands with high time complexity".

Avoid executing commands with high time complexity

We know that Redis executes commands "in a single thread". Executing commands with high time complexity is likely to block other requests.

Complex commands are related to the number of elements. There are usually two scenarios.

Too many elements, consuming IO resources. For example, HGETALL, LRANGE, the time complexity is O (N).

The calculation is too complex and consumes CPU resources. For example, ZUNIONSTORE, the time complexity is O (N) + O (M log (M))

The Redis official manual, which marks the time complexity of command execution. It is recommended that you check the manual and pay attention to the time complexity before using unfamiliar commands.

In real business, you should try to avoid commands with high time complexity. If you have to, there are two suggestions.

Ensure that the number of elements for the operation is as small as possible.

Separation of reading and writing. Complex commands are usually read requests and can be executed on the "slave" node.

The above is all the content of the article "Why should Redis avoid executing commands with high time complexity". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Complexity commands complexity time elements content articles suggestions manuals quantity resources learning help business scenarios official practical as much as possible easy to understand more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Xiaomi MySQL Huawei Shulou Tech Info