Now Sharded will handle connections instead of Info, so connection won't be shared between instances of ShardedJedis
This commit is contained in:
@@ -103,4 +103,18 @@ public class ShardedJedisPoolTest extends Assert {
|
||||
ShardedJedis newJedis = pool.getResource();
|
||||
newJedis.incr("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotShareInstances() throws Exception {
|
||||
Config config = new Config();
|
||||
config.maxActive = 2;
|
||||
config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
|
||||
|
||||
ShardedJedisPool pool = new ShardedJedisPool(config, shards);
|
||||
|
||||
ShardedJedis j1 = pool.getResource();
|
||||
ShardedJedis j2 = pool.getResource();
|
||||
|
||||
assertNotSame(j1.getShard("foo"), j2.getShard("foo"));
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisShardInfo;
|
||||
import redis.clients.jedis.ShardedJedis;
|
||||
import redis.clients.jedis.tests.HostAndPortUtil;
|
||||
@@ -18,32 +19,32 @@ public class ShardedBenchmark {
|
||||
private static final int TOTAL_OPERATIONS = 100000;
|
||||
|
||||
public static void main(String[] args) throws UnknownHostException,
|
||||
IOException {
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
JedisShardInfo shard = new JedisShardInfo(hnp1.host, hnp1.port);
|
||||
shard.setPassword("foobared");
|
||||
shards.add(shard);
|
||||
shard = new JedisShardInfo(hnp2.host, hnp2.port);
|
||||
shard.setPassword("foobared");
|
||||
shards.add(shard);
|
||||
ShardedJedis jedis = new ShardedJedis(shards);
|
||||
Collection<JedisShardInfo> allShards = jedis.getAllShards();
|
||||
for (JedisShardInfo jedisShardInfo : allShards) {
|
||||
jedisShardInfo.getResource().flushAll();
|
||||
}
|
||||
IOException {
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
JedisShardInfo shard = new JedisShardInfo(hnp1.host, hnp1.port);
|
||||
shard.setPassword("foobared");
|
||||
shards.add(shard);
|
||||
shard = new JedisShardInfo(hnp2.host, hnp2.port);
|
||||
shard.setPassword("foobared");
|
||||
shards.add(shard);
|
||||
ShardedJedis jedis = new ShardedJedis(shards);
|
||||
Collection<Jedis> allShards = jedis.getAllShards();
|
||||
for (Jedis j : allShards) {
|
||||
j.flushAll();
|
||||
}
|
||||
|
||||
long begin = Calendar.getInstance().getTimeInMillis();
|
||||
long begin = Calendar.getInstance().getTimeInMillis();
|
||||
|
||||
for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
|
||||
String key = "foo" + n;
|
||||
jedis.set(key, "bar" + n);
|
||||
jedis.get(key);
|
||||
}
|
||||
for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
|
||||
String key = "foo" + n;
|
||||
jedis.set(key, "bar" + n);
|
||||
jedis.get(key);
|
||||
}
|
||||
|
||||
long elapsed = Calendar.getInstance().getTimeInMillis() - begin;
|
||||
long elapsed = Calendar.getInstance().getTimeInMillis() - begin;
|
||||
|
||||
jedis.disconnect();
|
||||
jedis.disconnect();
|
||||
|
||||
System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops");
|
||||
System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user