Several changes have been added to this commit:

- Add asking to cluster commands
- Make jedis cluster return connection to original pool
- Add tests for MOVED and ASK cluster responses
- Refactor connection handler to recalculate connections based on slots

This commit makes the first usable version of Jedis along with Redis Cluster
This commit is contained in:
Marcos Nils
2014-01-03 16:42:21 -03:00
parent 1b26815799
commit dd0bbdaf91
10 changed files with 349 additions and 265 deletions

View File

@@ -1,10 +1,7 @@
package redis.clients.jedis;
import java.util.Random;
import java.util.Set;
import redis.clients.util.Pool;
public class JedisRandomConnectionHandler extends JedisClusterConnectionHandler {
@@ -12,11 +9,12 @@ public class JedisRandomConnectionHandler extends JedisClusterConnectionHandler
super(nodes);
}
@SuppressWarnings("unchecked")
public Jedis getConnection(String key) {
Object[] nodeArray = nodes.values().toArray();
return ((Pool<Jedis>) nodeArray[new Random().nextInt(nodeArray.length)]).getResource();
public Jedis getConnection() {
return getRandomConnection().getResource();
}
@Override
Jedis getConnectionFromSlot(int slot) {
return getRandomConnection().getResource();
}
}