Home  >  Article  >  Database  >  Introduction to redis operation merging

Introduction to redis operation merging

尚
forward
2020-06-18 17:04:465994browse

Introduction to redis operation merging

Redis operation merging is a macro-thinking of redis pipeline operations, which means merging multiple redis operations together to make requests to redis to improve the performance of redis services. At the same time, because the network round-trip time is reduced, the response time of the interface is also reduced.

When operating multiple keys, the difference between redis single point and cluster

In redis cluster, operations on multiple keys such as union operations of sets (to be precise, multiple keys are not on a hash slot), is not supported. Similarly, when you use redis pipelines and transactions, the commands involved in operating multiple keys are not supported. Example:

Introduction to redis operation merging

But with phpredis expansion, I have implemented several Functions that can operate multiple keys in the cluster (the implementation principle is that the RedisCluster class traverses the hash slots of each key and then operates on each hash slot):

mget: Returns the given The value of one or more string keys

mset: Set values ​​for multiple string keys

del: Delete key

unlink: Non-blocking delete key, redis For versions greater than 4.0.0

, you can also use Keys hash tags to ensure that multiple keys are in the same hash slot, and then perform operations on these keys.

Introduction to redis operation merging

When operating the same key

1. When adding a key, set the expiration time for the key

The set command natively supports adding keys The expiration time can be set at the same time, and for other types of keys, the expiration time can be added through pipelines or transactions. Example:

Introduction to redis operation merging

2. Add multiple data to the key at one time

For example, lpush, rpush, sadd, and zadd can add multiple pieces of data to the key at the same time. Example:

Introduction to redis operation merging

For more related knowledge, please pay attention to redis Getting Started TutorialColumn

The above is the detailed content of Introduction to redis operation merging. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete