1

I am using Node + Redis in a dynamically instanced cluster of these servers. When these servers are instanced(on separate vm's) I want to cut up the database. I have a hash ring function to point keys to the appropriate server.
How do I iterate over all the keys in the store?
Then when pushing that key thru the hash ring, how do I deal with the keys that are pushed back to the current server without causing an endless loop?
Will I need a new redis instance locally? and then kill the old one when the operation is finished? Is there a way for the node redis client to do this operation?

4

1 回答 1

2

Unfortunately there is no proper keyspace iteration in Redis so far. You have two options:

  • Use RANDOMKEY to random sample the dataset.
  • Use KEYS * that is blocking but can do the trick if you can block for a few seconds the server.

To atomically move a key you can use MIGRATE if you use Redis 2.6, however your cluster setup is not clearly specified in your question and to design a proper Redis cluster is full of details.

I suggest you to read the Redis Cluster specification here: http://redis.io/topics/cluster-spec And the following blog post about creating a eventually consistent Redis cluster client-side: http://antirez.com/news/36

于 2012-11-13T19:30:26.883 回答