simplification of sharding
This commit is contained in:
@@ -6,6 +6,7 @@ import java.util.Map;
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisShardInfo;
|
||||
import redis.clients.jedis.Protocol;
|
||||
import redis.clients.jedis.tests.commands.JedisCommandTestBase;
|
||||
import redis.clients.util.RedisOutputStream;
|
||||
@@ -35,7 +36,7 @@ public class JedisTest extends JedisCommandTestBase {
|
||||
|
||||
@Test
|
||||
public void connectWithShardInfo() {
|
||||
ShardInfo shardInfo = new ShardInfo("localhost", Protocol.DEFAULT_PORT);
|
||||
JedisShardInfo shardInfo = new JedisShardInfo("localhost", Protocol.DEFAULT_PORT);
|
||||
shardInfo.setPassword("foobared");
|
||||
Jedis jedis = new Jedis(shardInfo);
|
||||
jedis.get("foo");
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisShardInfo;
|
||||
import redis.clients.jedis.ShardedJedis;
|
||||
import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
|
||||
import redis.clients.util.Hashing;
|
||||
@@ -19,9 +20,9 @@ public class ShardedJedisTest extends Assert {
|
||||
|
||||
@Test
|
||||
public void checkSharding() throws IOException {
|
||||
List<ShardInfo> shards = new ArrayList<ShardInfo>();
|
||||
shards.add(new ShardInfo(redis1.host, redis1.port));
|
||||
shards.add(new ShardInfo(redis2.host, redis2.port));
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
shards.add(new JedisShardInfo(redis1.host, redis1.port));
|
||||
shards.add(new JedisShardInfo(redis2.host, redis2.port));
|
||||
ShardedJedis jedis = new ShardedJedis(shards);
|
||||
ShardInfo s1 = jedis.getShardInfo("a");
|
||||
ShardInfo s2 = jedis.getShardInfo("b");
|
||||
@@ -30,18 +31,18 @@ public class ShardedJedisTest extends Assert {
|
||||
|
||||
@Test
|
||||
public void trySharding() throws IOException {
|
||||
List<ShardInfo> shards = new ArrayList<ShardInfo>();
|
||||
ShardInfo si = new ShardInfo(redis1.host, redis1.port);
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
JedisShardInfo si = new JedisShardInfo(redis1.host, redis1.port);
|
||||
si.setPassword("foobared");
|
||||
shards.add(si);
|
||||
si = new ShardInfo(redis2.host, redis2.port);
|
||||
si = new JedisShardInfo(redis2.host, redis2.port);
|
||||
si.setPassword("foobared");
|
||||
shards.add(si);
|
||||
ShardedJedis jedis = new ShardedJedis(shards);
|
||||
jedis.set("a", "bar");
|
||||
ShardInfo s1 = jedis.getShardInfo("a");
|
||||
JedisShardInfo s1 = jedis.getShardInfo("a");
|
||||
jedis.set("b", "bar1");
|
||||
ShardInfo s2 = jedis.getShardInfo("b");
|
||||
JedisShardInfo s2 = jedis.getShardInfo("b");
|
||||
jedis.disconnect();
|
||||
|
||||
Jedis j = new Jedis(s1.getHost(), s1.getPort());
|
||||
@@ -57,18 +58,18 @@ public class ShardedJedisTest extends Assert {
|
||||
|
||||
@Test
|
||||
public void tryShardingWithMurmure() throws IOException {
|
||||
List<ShardInfo> shards = new ArrayList<ShardInfo>();
|
||||
ShardInfo si = new ShardInfo(redis1.host, redis1.port);
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
JedisShardInfo si = new JedisShardInfo(redis1.host, redis1.port);
|
||||
si.setPassword("foobared");
|
||||
shards.add(si);
|
||||
si = new ShardInfo(redis2.host, redis2.port);
|
||||
si = new JedisShardInfo(redis2.host, redis2.port);
|
||||
si.setPassword("foobared");
|
||||
shards.add(si);
|
||||
ShardedJedis jedis = new ShardedJedis(shards, Hashing.MURMUR_HASH);
|
||||
jedis.set("a", "bar");
|
||||
ShardInfo s1 = jedis.getShardInfo("a");
|
||||
JedisShardInfo s1 = jedis.getShardInfo("a");
|
||||
jedis.set("b", "bar1");
|
||||
ShardInfo s2 = jedis.getShardInfo("b");
|
||||
JedisShardInfo s2 = jedis.getShardInfo("b");
|
||||
jedis.disconnect();
|
||||
|
||||
Jedis j = new Jedis(s1.getHost(), s1.getPort());
|
||||
|
||||
Reference in New Issue
Block a user