Latest web development tutorials

Redis partition

Partition is divided into a plurality of data processing Redis instances, each instance to save only a subset of the key.

Benefits of partitioning

  • By using more than one computer's memory and values, allow us to construct a larger database.
  • By multicore and multiprocessor computers, allowing us to expand computing capacity; through multiple computers and network adapters, allowing us to expand the network bandwidth.

Inadequate partition

Some features redis in partitioning performance is not very good:

  • Operation involves more than one key is generally not supported. For example, when two set mapped to different instances of redis, you will not be able to perform these two set intersection operation.
  • It involves a number of key redis transaction can not be used.
  • When using partitions, the more complex data processing, for example, you need to handle multiple rdb / aof files and backup files from multiple instances of persistence and host.
  • Add or remove capacity is also more complicated. redis majority support cluster at runtime increases, transparent data delete nodes balance of power, but similar to the client partition, agents and other systems do not support this feature. However, this technique called presharding is helpful.

Partition type

Redis There are two types of partitions. Suppose there are four Redis instance R0, R1, R2, R3, and similar user: 1, user: a plurality of key 2 such a representation on users, given the key to select a variety of different ways in which the key is stored in the instance . In other words, there are different systems to map a key to a Redis service.

Range partitioning

The easiest way is to partition range partitioning is mapped to a range of subject-specific Redis instance.

For example, ID from 0 to 10000 users will save the instance R0, ID from 10001-20000 users will be saved to R1, and so on.

This approach is feasible and practical use, is to have a range of less than the range of the mapping table instance. This table is to be managed, but also need to map various objects, usually Redis is not a good method.

Hash Partitioning

Another approach is to hash partitioning partitions. This applies to any key, and need not be object_name: This form, as simple as described below:

  • Using a hash function key is converted to a number, such as using crc32 hash function. The implementation of key foobar crc32 (foobar) will output an integer of similar 93,024,922.
  • This integer modulo, which was converted to digital between 0-3, it can be mapped to the integer 4 Redis instance be one. 93,024,922% 4 = 2, that is key foobar should be saved to R2 instance. Note: The modulo operation is to take the remainder of the addition, the% operator is usually implemented using a variety of programming languages.