Redis practice cluster solution

This article is originally from http://blog.csdn.net/voipmaker and reproduced to indicate the source. 

 

 

The purpose of the Redis cluster is to achieve horizontal scaling of data. By saving a piece of data shards to multiple machines, it can scale the database size horizontally, expand bandwidth, and computing power.

 

There are roughly three ways to implement data sharding (clustering):

 

(1) The client implements data fragmentation

That is, on which machine the client's own key to calculate the data should be stored and searched. The advantage of this method is that it reduces the complexity of the server cluster. When the client implements data sharding, the server is independent, and the server has no previous relationship. Most redis client libraries implement this function, also called sharding. The disadvantage of this method is that the client needs to know the contact information of the current cluster node in real time.

At the same time, when adding a new node, the client must support dynamic sharding. Most client implementations do not support this function, and redis needs to be restarted. Another disadvantage is that HA of redis requires additional consideration.

 

(2) The server implements data fragmentation

The theory is that the client communicates with any node in the cluster at will, and the server is responsible for calculating which machine a certain key is on. When the client accesses a certain machine, the server calculates which machine the corresponding key should be stored in, and then stores the result. It is returned to the client, and the client then goes to the corresponding node to operate the key, which is a redirection process. This method is that redis3.0 is being implemented and is currently in beta version. The cluster of Redis 3.0 supports the HA function at the same time, and a master node hangs After that, its slave will automatically take over.

The implementation of the cluster on the server side requires the client language to implement the protocol of the server cluster. At present, most of the java, php, and ruby ​​clients have the redis-cluster client implementation version.

 

(3) Data fragmentation through proxy server

 

This method uses a proxy server to achieve data fragmentation, the client directly contacts the proxy, the proxy calculates the cluster node information, and sends the request to the corresponding cluster node. The complexity of the client is reduced, and the proxy is required to collect cluster node information. Twemproxy is open-sourced by twitter, a proxy that implements this function. This implementation adds a proxy between the client and the server.

But this is the officially recommended way before the stable version of redis 3.0 comes out. Combined with the HA solution of redis-sentinel, it is a good combination.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326392222&siteId=291194637