add url support
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package redis.clients.jedis.tests;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -167,4 +169,60 @@ public class ShardedJedisPoolTest extends Assert {
|
||||
assertEquals(actual, c1);
|
||||
assertEquals(fails, c2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWithUrlString() {
|
||||
Jedis j = new Jedis("localhost", 6380);
|
||||
j.auth("foobared");
|
||||
j.set("foo", "bar");
|
||||
|
||||
j = new Jedis("localhost", 6379);
|
||||
j.auth("foobared");
|
||||
j.set("foo", "bar");
|
||||
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
shards.add(new JedisShardInfo("redis://:foobared@localhost:6380"));
|
||||
shards.add(new JedisShardInfo("redis://:foobared@localhost:6379"));
|
||||
|
||||
Config redisConfig = new Config();
|
||||
ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards);
|
||||
|
||||
Jedis[] jedises = pool.getResource().getAllShards().toArray(new Jedis[2]);
|
||||
|
||||
Jedis jedis = jedises[0];
|
||||
assertEquals("PONG", jedis.ping());
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
|
||||
jedis = jedises[1];
|
||||
assertEquals("PONG", jedis.ping());
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWithUrl() throws URISyntaxException {
|
||||
Jedis j = new Jedis("localhost", 6380);
|
||||
j.auth("foobared");
|
||||
j.set("foo", "bar");
|
||||
|
||||
j = new Jedis("localhost", 6379);
|
||||
j.auth("foobared");
|
||||
j.set("foo", "bar");
|
||||
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
shards.add(new JedisShardInfo(new URI("redis://:foobared@localhost:6380")));
|
||||
shards.add(new JedisShardInfo(new URI("redis://:foobared@localhost:6379")));
|
||||
|
||||
Config redisConfig = new Config();
|
||||
ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards);
|
||||
|
||||
Jedis[] jedises = pool.getResource().getAllShards().toArray(new Jedis[2]);
|
||||
|
||||
Jedis jedis = jedises[0];
|
||||
assertEquals("PONG", jedis.ping());
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
|
||||
jedis = jedises[1];
|
||||
assertEquals("PONG", jedis.ping());
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user