One minute you understand the advantages and disadvantages with Redis cluster, from technology selection no longer pit!

Outline

Redis Redis the Cluster is native to achieve data piece, the data can be automatically distributed across multiple nodes, it does not depend on any external tools.

All the Cluster Redis key 16384 is assigned to the slot (the hash tank), the slot will be assigned to the plurality of nodes Redis.

 

A key is mapped to a slot, the algorithm:

HASH_SLOT = CRC16(key) mod 16384

The slot mechanism will give us a bit of trouble, it will be mentioned later.

 

Advantage

  1. high performance
  • Redis Cluster performance and single-node deployment is the same level.

  1. High Availability
  • Redis Cluster supports standard master-replica configuration to guarantee high availability and high reliability.

  • Redis Cluster also achieved a consensus manner similar Raft, and to safeguard the availability of the entire cluster.

  1. Easy to expand
  • Adding a new node, or the node is removed in Redis Cluster, is transparent, no downtime.

  • Horizontal and vertical directions are very easily extended.

  1. Primeval
  • Redis Cluster deployment does not require agents or other tools, and single Redis Redis Cluster and almost completely compatible.

 

limit

  1. Supports the client's needs
  • The client needs to be modified to support Redis Cluster.

  • Although Redis Cluster has been published for several years, but still some clients are not supported, so you need to go online to check what Redis official.

  1. Supports only one database
  • Unlike stand-alone Redis, Redis Cluster supports only one database (database 0), select command can not be used, but few people actually use multiple databases, so this restriction did not affect anything.

  1. Multi-Key operations are limited

Multi-Key (Multi-key) What does it mean? Some cases are multi-key operation, for example:

  • SUNION, such an order will operate multiple key

  • Affairs, will multiple key operations in a transaction

  • LUA script, will operate multiple key

Such cases require special attention because: Redis Cluster requirements, only these are in the same key slot to perform. For example, there are two key, key1 and key2.

  • key1 5500 is mapped to the slot, it is stored in Node A.

  • key2 5501 is mapped to the slot, it is stored in the Node B.

Then you can not make business operations key1 and key2.

 

Multi-Key processing limitations

For multi-key scene, we need to make the design data space, Redis Cluster provides a mechanism for a hash tag, allowing us to map a key set to the same slot.

For example: user1000.following the key to save the user the user user1000 concerned; user1000.followers save user user1000 of fans.

Both have a common key part user1000, you can specify doing slot mapping calculation of the common parts, so they can in the same slot.

Use:

{user1000}.following 和 {user1000}.followers

Is the common portions} {wrap, when the slot value is calculated, if the braces are found, only a part of which will be calculated.

 

summary

Multi-Key This is Redis Cluster for the largest daily limit our use, must pay attention to, if not in the same multi-key in a slot will be given, such as:

(error) CROSSSLOT Keys in request don't hash to the same slot

Need to use the space key hash tag of good design.

Guess you like

Origin www.cnblogs.com/evenchen/p/11940019.html