Redis cluster standalone from Hi edition

Source: Internet
Author: User
Tags redis cluster

Redis the cluster

    • How does Redis scale?
    • How is data fragmentation managed?
    • Read/write switching for master-slave replication?

First, what is a cluster

    • ? Redis clusters enable the horizontal expansion of Redis, which is to start n redis nodes and store the entire database in these n nodes, each of which stores the 1/n of the total data.
    • ? Redis clusters provide a degree of availability (availability) through partitioning (partition): Clusters can continue to process command requests even if some of the nodes in the cluster fail or are unable to communicate.

Second, Install ruby Environment

Copy the Redis-3.2.0.gem to the/OPT directory

Third, prepare the cluster

Four, synthesize six nodes into one cluster

before you combine, make sure that all Redis after the instance is started, nodes-xxxx.conf files are generated normally.

Fit:

Cd/opt/redis-3.2.0/src

./redis-trib.rb Create--replicas 1 192.168.10.102:6379 192.168.10.102:6380 192.168.10.102:6381 192.168.10.102:6389 192.168.10.102:6390 192.168.10.102:6391

Do not use 127.0.0.1 here, please use real IP address

by cluster nodes command to view cluster information

    • Redis Cluster How do I allocate these six nodes?
    • A cluster must have at least three master nodes .
    • Option--replicas 1 means that we want to create a slave node for each master node in the cluster.
    • The allocation principle tries to ensure that each primary database runs on a different IP address, each from the library and the main library not on an IP address.

[OK] All nodes agree about slots configuration.

>>> Check for open Slots ...

>>> Check Slots Coverage ...

[OK] All 16384 slots covered.

    • What is slots
    • A Redis cluster contains 16,384 slots (hash slots), and each key in the database belongs to one of these 16,384 slots, and the cluster uses the formula CRC16 (key)% 16384来 to calculate the key to which slot it belongs, where CRC16 (key) The sentence is used to calculate the CRC16 checksum of key keys.
    • Each node in the cluster is responsible for processing a subset of slots. For example, if a cluster can have a master node, where:

Node A is responsible for handling slots No. 0 to No. 5500.

Node B is responsible for handling slot No. 5501 to number 11,000th.

Node C is responsible for handling slots 11,001th to 16,383th.

Hash table default of 16 slots, load factor

Five, cluster operation

    • Enter values in the cluster
    • In REDIS-CLI each input, query key value, Redis will calculate the key should be sent to the slot, if not the client corresponding to the server's slot, Redis will error, and inform should go to the Redis instance address and port. The REDIS-CLI client provides automatic redirection for –c parameters.

    • such as Redis-cli-c–p 6379 login, re-entry, query key value pairs can be automatically redirected.
    • A key value that is not in a slot is a multi-key operation that cannot be used with Mget,mset.
    • The concept of a group can be defined by {}, so that key-value pairs of the same content within the {} In key are placed in a slot.

    • Querying values in a cluster
    • CLUSTER SLOTS View the allocation of slots.
    • CLUSTER keyslot <key> Calculate the key should be placed on which slot.
    • CLUSTER Countkeysinslot <slot> Returns the number of key-value pairs currently contained in the slot slot.
    • CLUSTER Getkeysinslot <slot> <count> returns the key in count slot slots.
    • Add a Node

1 , in any node in the cluster, execute the command:

CLUSTER MEET < new node ip> <port> Add a new node or use it to update the IP address

2 , the old node represents a , send an invitation to new Node B.

3 , new node B after receiving the invitation, it will be connected with a to shake hands so that a will b as a member of the current cluster.

4 , when a and B after the handshake is successful, A will use gossip Protocol the Node B information is communicated to each node in the cluster. In this way, even if there are multiple nodes in the cluster, it is only necessary to select any one of the meet nodes , so that the new node can eventually join the whole cluster.

    • Assigning slots

in/opt/redis-3.2.0/src under

execution./redis-trib.rb Reshard 192.168.31.211:6399

    • Failure recovery
    • If the lower limit of the primary node? Can the node automatically ascend to the primary node?
    • What happens to the master-slave relationship after the primary node is restored?
    • if all the master and slave nodes of a certain slot are dropped, Redis Will the service continue?
    • redis.conf the parameters in Cluster-require-full-coverage

Redis cluster standalone from Hi edition

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.