Redis Cluster is a distributed solution of Redis, officially launched in Redis 3.0 version, effectively solve the needs of Redis distributed. Cluster architecture can be used to achieve load balancing when the bottleneck of single memory, concurrency, and traffic is encountered. Distributed clusters primarily solve the problem of mapping the entire data set to multiple nodes according to partitioning rules, that is, the data set is divided into multiple nodes, each node is responsible for a subset of the entire data.

V Function Description

1.0 Automatic Data Sharding

Each node in the cluster is responsible for a certain number of slots, and each key is mapped to a specific slot. In this way, it is possible to find out which node the key is stored on.

1.1 Provides hash Tags

The hash tag function allows multiple keys to be mapped to the same slot to provide multi-key operations. The hash tag is used by including “{}” in the key. } “is used for the hash calculation.

1.2 Automatic and manual failover

1.3 Reduce hardware costs and O&M costs.

VRedis Cluster target

A high performance

High availability

The linear scale

V Redis Cluster is configured

Create a directory cluster and create directories for each of the six instances. These directories are used to store the six instances. The six instances will be used to form a cluster later. Three masters and three slaves

1.0 Creating a Directory

mkdir redis-cluster

The mkdir 900 {6}

1.1 Copy six Instances

Cp/root/redis - 5.0.2 / redis. Conf/usr/local/bin/redis cluster / 9001

1.2 Updating the Instance Configuration File

Specifically, note that each instance should have a different port because it is on the same machine; At the same time, each instance will obviously have its own place to store data; Enable AOF mode; Enable cluster configuration. Enable background mode;

1.3 Redis cluster operations are completed by Ruby scripts, so you need to install Ruby related RPM packages, as well as Redis and Ruby interface packages.

1.3.1 install ruby

yum install ruby

1.3.1 install rubygems

yum install rubygems

1.4 Starting the Redis Cluster instance

/ root/redis - 5.0.2 / SRC/redis server/usr/local/bin/redis - cluster / 9001 / redis. Conf

Through the netstat – tnulp | grep redis and ps – aux | grep redis start see if successful.

1.5 Redis using the CLI to create clusters

/redis-cli --cluster create 10.168.11.116:9001 10.168.11.116:9002 10.168.11.116:9003 10.168.11.116:9004 10.168.11.116 10.168.11.116:9005:9006

Note that Redis5.0 uses redis-cli as the command to create clusters, implemented in C instead of Ruby.

1.6 Checking clusters

. / redis - cli - cluster check 10.168.11.116:9001

1.7 Viewing distribution information about cluster Keys, slots, and Slaves

. / redis - cli - cluster info 10.168.11.116:9001

1.8 Cluster Commands

CLUSTER INFO Displays information about the CLUSTER. CLUSTER NODES Lists all known NODES in the CLUSTER and their information. CLUSTER MEET < IP > <port> Adds the node specified by IP and port to the CLUSTER to make it a part of the CLUSTER. CLUSTER FORGET <node_id> Removes the node specified node_id from the CLUSTER. CLUSTER REPLICATE <node_id> Sets the current node to the secondary node of the node specified by node_id. CLUSTER SAVECONFIG saves the node configuration file to the disk. CLUSTER ADDSLOTS <slot> [slot ...] Assign one or more slots to the current node. CLUSTER DELSLOTS <slot> [slot ...] Removes one or more slots assigned to the current node. The CLUSTER FLUSHSLOTS removes all slots assigned to the current node, making the current node a node with no slots assigned to it. CLUSTER SETSLOT <slot> NODE <node_id> assigns slot slots to the NODE specified by node_id. CLUSTER SETSLOT <slot> MIGRATING <node_id> Migrates the slot of the node to the node specified on node_id. CLUSTER SETSLOT <slot> IMPORTING <node_id> imports slot slots from the node specified by node_id into the node. CLUSTER SETSLOT <slot> STABLE Unimports or migrates slots. CLUSTER KEYSLOT <key> calculates which slot the key should be placed in. CLUSTER COUNTKEYSINSLOT <slot> Returns the number of key-value pairs that the slot currently contains. CLUSTER GETKEYSINSLOT <slot> <count> returns count of the keys in the slot. CLUSTER SLAVES node-id Returns a list of SLAVES for the master nodeCopy the code

VCluster tests the effect

/redis-cli -c -h 10.168.11.116 -p 9001

Other references:

  • Redis cluster tutorial
  • Linux Redis cluster installation and deployment and use details
  • Linux Redis cluster building and cluster client implementation
  • Redis-cli cluster management test in 5.0

About the author: Focus on basic platform project development. If you have any questions or suggestions, please feel free to comment! Copyright notice: The copyright of this article belongs to the author and the blog garden, welcome to reprint, but without the consent of the author must retain this statement, and give the original text link in a prominent place on the page of the article. For the record: all comments and messages will be answered as soon as possible. You are welcome to correct your mistakes and make progress together. Or direct private message I support the blogger: if you think the article is helpful to you, you can click on the lower right corner of the article [recommendation]. Your encouragement is the author to adhere to the original and continuous writing of the biggest power! \