redis一个比较大的改变,redis3.0.1稳定版本发布,支持集群。redis集群配置reidsCluster(七)

2015-07-21 16:27:13 · 作者: · 浏览: 3
ce to have a unique name in the context of the cluster. Every node remembers every other node using this IDs, and not by IP or port. IP addresses and ports may change, but the unique node identifier will never change for all the life of the node. We call this identifier simplyNode ID.

*Creating the cluster

Now that we have a number of instances running, we need to create our cluster by writing some meaningful configuration to the nodes.

This is very easy to accomplish as we are helped by the Redis Cluster command line utility calledredis-trib, that is a Ruby program executing special commands in the instances in order to create new clusters, check or reshard an existing cluster, and so forth.

The redis-trib utility is in the src directory of the Redis source code distribution. To create your cluster simply type:

./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 \
127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005

The command used here is create, since we want to create a new cluster. The option--replicas 1 means that we want a slave for every master created. The other arguments are the list of addresses of the instances I want to use to create the new cluster.

Obviously the only setup with our requirements is to create a cluster with 3 masters and 3 slaves.

Redis-trib will propose you a configuration. Accept typing yes. The cluster will be configured andjoined, that means, instances will be bootstrapped into talking with each other. Finally if everything went ok you'll see a message like that:

[OK] All 16384 slots covered

This means that there is at least a master instance serving each of the 16384 slots available.

*Creating a Redis Cluster using the create-cluster script

If you don't want to create a Redis Cluster by configuring and executing individual instances manually as explained above, there is a much simpler system (but you'll not learn the same amount of operational details).

Just check utils/create-cluster directory in the Redis distribution. There is a script calledcreate-cluster inside (same name as the directory it is contained into), it's a simple bash script. In order to start a 6 nodes cluster with 3 masters and 3 slaves just type the following commands:

create-cluster start create-cluster create

Reply to yes in step 2 when the redis-trib utility wants you to accept the cluster layout.

You can now interact with the cluster, the first node will start at port 30001 by default. When you are done, stop the cluster with:

create-cluster stop.

Please read the README inside this directory for more information on how to run the script.

*Playing with the cluster

At this stage one of the problems with Redis Cluster is the lack of client libraries implementations.

I'm aware of the following implementations:

redis-rb-cluster is a Ruby implementation written by me (@antirez) as a reference for other languages. It is a simple wrapper around the original redis-rb, implementing the minimal semantics to talk with the cluster efficiently. redis-py-cluster A port of redis-rb-cluster to Python. Supports majority of redis-py functionality. Is in active development.The popular Predis has support for Redis Cluster, the support was recently updated and is in active development.The most used Java client, Jedis recently added support for Redis Cluster, see the Jedis Cluster section in the project README.StackExchange.Redis offers support for C# (and should work fine with most .NET languages; VB, F#, etc)thunk-redis offers support for Node.js and io.