Skip to content

Commit

Permalink
update JedisPoolBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
Calvin committed Nov 21, 2014
1 parent a4e6d46 commit f1a4295
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public RedisCounterBenchmark() {
@Override
protected void setUp() {

pool = new JedisPoolBuilder().setDirectHostAndPort("localhost", "6379").setPoolSize(threadCount).buildPool();
pool = new JedisPoolBuilder().setUrl("direct://localhost:6379?poolSize=" + threadCount).buildPool();
jedisTemplate = new JedisTemplate(pool);

// 重置Counter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public RedisSessionBenchmark() {

@Override
protected void setUp() {
pool = new JedisPoolBuilder().setDirectHostAndPort("localhost", "6379").setPoolSize(threadCount).buildPool();
pool = new JedisPoolBuilder().setUrl("direct://localhost:6379?poolSize=" + threadCount).buildPool();
jedisTemplate = new JedisTemplate(pool);

// 清空数据库
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class MasterElectorDemo {

public static void main(String[] args) throws Exception {

JedisPool pool = new JedisPoolBuilder().setDirectHostAndPort("localhost", "6379").setPoolSize(1).buildPool();
JedisPool pool = new JedisPoolBuilder().setUrl("direct://localhost:6379").setPoolSize(1).buildPool();
try {
MasterElector masterElector = new MasterElector(pool, 5);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void main(String[] args) throws Exception {
batchSize = Integer.parseInt(System.getProperty("batchsize",
String.valueOf(AdvancedJobConsumer.DEFAULT_BATCH_SIZE)));

pool = new JedisPoolBuilder().setDirectHostAndPort("localhost", "6379").setPoolSize(threadCount).buildPool();
pool = new JedisPoolBuilder().setUrl("direct://localhost:6379?poolSize=" + threadCount).buildPool();

ExecutorService threadPool = Executors.newFixedThreadPool(threadCount);
for (int i = 0; i < threadCount; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void main(String[] args) throws Exception {
threadCount = Integer.parseInt(System.getProperty(ConcurrentBenchmark.THREAD_COUNT_NAME,
String.valueOf(THREAD_COUNT)));

pool = new JedisPoolBuilder().setDirectHostAndPort("localhost", "6379").setPoolSize(threadCount).buildPool();
pool = new JedisPoolBuilder().setUrl("direct://localhost:6379?poolSize=" + threadCount).buildPool();

ExecutorService threadPool = Executors.newFixedThreadPool(threadCount);
for (int i = 0; i < threadCount; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static void main(String[] args) throws Exception {
threadCount = Integer.parseInt(System.getProperty(ConcurrentBenchmark.THREAD_COUNT_NAME,
String.valueOf(THREAD_COUNT)));

pool = new JedisPoolBuilder().setDirectHostAndPort("localhost", "6379").setPoolSize(threadCount).buildPool();
pool = new JedisPoolBuilder().setUrl("direct://localhost:6379?poolSize=" + threadCount).buildPool();

ExecutorService threadPool = Executors.newFixedThreadPool(threadCount);
for (int i = 0; i < threadCount; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ReliableJobDispatcherDemo {

public static void main(String[] args) throws Exception {

JedisPool pool = new JedisPoolBuilder().setDirectHostAndPort("localhost", "6379").setPoolSize(1).buildPool();
JedisPool pool = new JedisPoolBuilder().setUrl("direct://localhost:6379?poolSize=1").buildPool();
try {
JobDispatcher dispatcher = new JobDispatcher("ss", pool);
dispatcher.setReliable(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class SimpleJobDispatcherDemo {

public static void main(String[] args) throws Exception {

JedisPool pool = new JedisPoolBuilder().setDirectHostAndPort("localhost", "6379").setPoolSize(1).buildPool();
JedisPool pool = new JedisPoolBuilder().setUrl("direct://localhost:6379?poolSize=1").buildPool();
try {
JobDispatcher dispatcher = new JobDispatcher("ss", pool);
JobStatistics statistics = new JobStatistics("ss", pool);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public JobProducerDemo() {

@Override
protected void setUp() {
pool = new JedisPoolBuilder().setDirectHostAndPort("localhost", "6379").setPoolSize(threadCount).buildPool();
pool = new JedisPoolBuilder().setUrl("direct://localhost:6379?poolSize=" + threadCount).buildPool();
jobProducer = new JobProducer("ss", pool);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
*/
public class JedisDirectPool extends JedisPool {

public JedisDirectPool(HostAndPort address, JedisPoolConfig config) {
initInternalPool(address, new ConnectionInfo(), config);
public JedisDirectPool(String poolName, HostAndPort address, JedisPoolConfig config) {
this(poolName, address, new ConnectionInfo(), config);
}

public JedisDirectPool(HostAndPort address, ConnectionInfo connectionInfo, JedisPoolConfig config) {
public JedisDirectPool(String poolName, HostAndPort address, ConnectionInfo connectionInfo, JedisPoolConfig config) {
initInternalPool(address, connectionInfo, config);
this.poolName = poolName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
public abstract class JedisPool extends Pool<Jedis> {

protected String poolName;

protected HostAndPort address;

protected ConnectionInfo connectionInfo;
Expand All @@ -41,6 +43,7 @@ public static JedisPoolConfig createPoolConfig(int maxPoolSize) {
* Initialize the internal pool with connection info and pool config.
*/
protected void initInternalPool(HostAndPort address, ConnectionInfo connectionInfo, JedisPoolConfig config) {
this.poolName = poolName;
this.address = address;
this.connectionInfo = connectionInfo;
JedisFactory factory = new JedisFactory(address.getHost(), address.getPort(), connectionInfo.getTimeout(),
Expand Down
Loading

0 comments on commit f1a4295

Please sign in to comment.