Redis 简明教程
Redis - Partitioning
分区是将你的数据拆分成多个 Redis 实例的过程,以便每个实例只包含你的键子集。
Partitioning is the process of splitting your data into multiple Redis instances, so that every instance will only contain a subset of your keys.
Benefits of Partitioning
-
It allows for much larger databases, using the sum of the memory of many computers. Without partitioning you are limited to the amount of memory that a single computer can support.
-
It allows to scale the computational power to multiple cores and multiple computers, and the network bandwidth to multiple computers and network adapters.
Disadvantages of Partitioning
-
Operations involving multiple keys are usually not supported. For instance, you can’t perform the intersection between two sets if they are stored in the keys that are mapped to different Redis instances.
-
Redis transactions involving multiple keys cannot be used.
-
The partitioning granuliary is the key, so it is not possible to shard a dataset with a single huge key like a very big sorted set.
-
When partitioning is used, data handling is more complex. For instance, you have to handle multiple RDB/AOF files, and to get a backup of your data you need to aggregate the persistence files from multiple instances and hosts.
-
Adding and removing the capacity can be complex. For instance, Redis Cluster supports mostly transparent rebalancing of data with the ability to add and remove nodes at runtime. However, other systems like client-side partitioning and proxies don’t support this feature. A technique called Presharding helps in this regard.
Types of Partitioning
Redis 有两种分区类型。假设我们有四个 Redis 实例 R0、R1、R2、R3 和多个密钥,表示用户,比如 user:1、user:2、… 等。
There are two types of partitioning available in Redis. Suppose we have four Redis instances, R0, R1, R2, R3 and many keys representing users like user:1, user:2, … and so forth.
Range Partitioning
范围分区是通过将对象范围映射到特定 Redis 实例来实现的。在我们的示例中,ID 为 0 到 10000 的用户将进入实例 R0,而 ID 为 10001 到 20000 的用户将进入实例 R1,以此类推。
Range partitioning is accomplished by mapping ranges of objects into specific Redis instances. Suppose in our example, the users from ID 0 to ID 10000 will go into instance R0, while the users from ID 10001 to ID 20000 will go into instance R1 and so forth.