Redis Cluster Learning

Source: Internet
Author: User
Tags redis cluster

5 Types of data in Redis string, Hash, list, set, Sorted set.

The Redis source code is more than 10,000 lines in total.

This article has some redis "common sense" http://www.searchdatabase.com.cn/showcontent_70423.htm

The key can be any type, and finally it will be saved as byte[]; The author suggests using: To separate table names, and to use. As a connection between words. (As far as I know, Redis has only libraries without tables)

Operation for Key:

Command sort (sort by a key from small to large, desc is from large to small):

Reference http://www.cnblogs.com/linjiqin/archive/2013/06/14/3135921.html

10.117.146.16:8379> Lpush Price 1.5 8410.117.146.16:8379> sortprice 1) "1.5" 2) "8" 3) "10" 4) "1" 10.117.146.16:8379> sort Price desc) "30" 2) "10" 3) "8" 4) "1.5"

1. You can also sort strings by using the Alpha modifier

2. Restricting return results using the limit modifier

3. Sorting using an external key

4.get has an additional parameter rule, which is to use # to get the value of the sorted key.

5. By passing a non-existent key as a parameter to the by option, you can let sort skip the sort operation and return the result directly.

6. This usage is of little practical use when used alone. However, by combining this usage with the GET option, you can get multiple foreign keys without sorting, which is equivalent to performing a consolidated fetch operation (similar to the JOIN keyword for SQL database).

Save Sort Results

10.117.146.16:8379>410.117.146.16:8379> lrange ordered_price 0-11) "1.5" 2) "8" 3) "ten" 4 " Return value: Does not use the store parameter, returns the sort result in the form of a list. Using the store parameter, returns the number of elements in the sorted result. 

Other commands are: KEYS

The principle of Redis Cluster is clear http://www.cnblogs.com/foxmailed/p/3630875.html

  Redis Cluster is a redis cluster implementation, built-in data auto-shard mechanism, the cluster internally to map all the key to 16,384 slots,
Each Redis instance in the cluster is responsible for reading and writing a portion of the slots.
The cluster client connects to any Redis instance in the cluster to send commands, and when Redis instance receives a request for its own slot that is not responsible,
The Redis instance address that is responsible for requesting key slot will be returned to the client, and the client will automatically resend the original request to this address for external transparency.
Exactly which slot a key belongs to is determined by CRC16 (key)% 16384 . With regard to load balancing, the clustered Redis instance can migrate data between slots, but not automatically, requiring external command triggering. With regard to cluster member management, the cluster node (Redis Instance) and nodes 22 periodically exchange intra-cluster node information and update, from the point of view of the sending node, this information includes:
What nodes are in the cluster, what the IP and port are, what the node name is, what the state of the node is (such as Ok,pfail,fail, which is detailed later), including the node role (master or slave), and so on.
means that the slot read and write service is not available for the primary outage. One master can have multiple from, main down, one from being promoted to the other, which is promoted primarily, and the protocol is similar to raft, see here.
How do I detect a primary outage? The Redis cluster uses the quorum+ heartbeat mechanism. From the node's point of view, the node periodically sends pings to all other nodes,
Cluster-node-timeout (configurable, second level) time did not receive the other party's reply, then unilaterally considered the end node down, the node is marked as Pfail state.
By exchanging information between nodes to quorum nodes that this node is pfail, mark the node as fail,
and sends it to all other nodes, and all other nodes receive it immediately and think the node is down.
From here, it can be seen that, after the main outage, at least cluster-node-timeout time, the master's responsible slot read and write service is not available.

Here are some of the pits and experiences that are encountered using Redis http://www.360doc.com/content/16/0425/23/16915_553797555.shtml

Suspected Cluster brain fissure? (this name is awesome.) Brain fissure in the so-called distributed system is very common, we are not unfamiliar, as the DBA is most afraid of MySQL keepalived brain fissure, causing the main library double write. Is there any brain crack in Redis cluster? 5 o'clock in the morning received a phone call, found that the application sees inconsistent data, occasionally no data, occasional data, much like reading dirty data. Mount Redis, Cluster Nodes, Cluster config, and do find different Redis instances configured with different Cluster Nodes.
Think of yesterday there is a migration to the cluster, dropped a few instances, but there is no push configuration on the PHP configuration side, resulting in PHP may read the old instance data, immediately re-push the configuration, problem resolution.

Redis Cluster Learning

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.