Added sharding using ketama

This commit is contained in:
Jonathan Leibiusky
2010-09-14 01:30:59 -03:00
parent f9e7887e02
commit baab2225f6
5 changed files with 610 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ public class JedisTest extends JedisCommandTestBase {
@Test
public void useWithoutConnecting() {
Jedis jedis = new Jedis("localhost");
jedis.auth("foobared");
jedis.dbSize();
}

View File

@@ -0,0 +1,53 @@
package redis.clients.jedis.tests;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Protocol;
import redis.clients.jedis.ShardedJedis;
import redis.clients.util.ShardInfo;
public class ShardedJedisTest extends Assert {
@Test
public void checkSharding() throws IOException {
List<ShardInfo> shards = new ArrayList<ShardInfo>();
shards.add(new ShardInfo("localhost", Protocol.DEFAULT_PORT));
shards.add(new ShardInfo("localhost", Protocol.DEFAULT_PORT + 1));
ShardedJedis jedis = new ShardedJedis(shards);
ShardInfo s1 = jedis.getShardInfo("a");
ShardInfo s2 = jedis.getShardInfo("b");
assertNotSame(s1, s2);
}
@Test
public void trySharding() throws IOException {
List<ShardInfo> shards = new ArrayList<ShardInfo>();
ShardInfo si = new ShardInfo("localhost", Protocol.DEFAULT_PORT);
si.setPassword("foobared");
shards.add(si);
si = new ShardInfo("localhost", Protocol.DEFAULT_PORT + 1);
si.setPassword("foobared");
shards.add(si);
ShardedJedis jedis = new ShardedJedis(shards);
jedis.set("a", "bar");
ShardInfo s1 = jedis.getShardInfo("a");
jedis.set("b", "bar1");
ShardInfo s2 = jedis.getShardInfo("b");
jedis.disconnect();
Jedis j = new Jedis(s1.getHost(), s1.getPort());
j.auth("foobared");
assertEquals("bar", j.get("a"));
j.disconnect();
j = new Jedis(s2.getHost(), s2.getPort());
j.auth("foobared");
assertEquals("bar1", j.get("b"));
j.disconnect();
}
}