upgrade to commons-pool 2
This commit is contained in:
3
Makefile
3
Makefile
@@ -57,7 +57,6 @@ sentinel monitor mymaster 127.0.0.1 6379 1
|
||||
sentinel auth-pass mymaster foobared
|
||||
sentinel down-after-milliseconds mymaster 3000
|
||||
sentinel failover-timeout mymaster 900000
|
||||
sentinel can-failover mymaster yes
|
||||
sentinel parallel-syncs mymaster 1
|
||||
pidfile /tmp/sentinel1.pid
|
||||
logfile /tmp/sentinel1.log
|
||||
@@ -69,7 +68,6 @@ daemonize yes
|
||||
sentinel monitor mymaster 127.0.0.1 6381 2
|
||||
sentinel auth-pass mymaster foobared
|
||||
sentinel down-after-milliseconds mymaster 3000
|
||||
sentinel can-failover mymaster yes
|
||||
sentinel parallel-syncs mymaster 1
|
||||
sentinel failover-timeout mymaster 900000
|
||||
pidfile /tmp/sentinel2.pid
|
||||
@@ -82,7 +80,6 @@ daemonize yes
|
||||
sentinel monitor mymaster 127.0.0.1 6381 2
|
||||
sentinel auth-pass mymaster foobared
|
||||
sentinel down-after-milliseconds mymaster 3000
|
||||
sentinel can-failover mymaster yes
|
||||
sentinel parallel-syncs mymaster 1
|
||||
sentinel failover-timeout mymaster 900000
|
||||
pidfile /tmp/sentinel3.pid
|
||||
|
||||
10
pom.xml
10
pom.xml
@@ -59,9 +59,9 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-pool</groupId>
|
||||
<artifactId>commons-pool</artifactId>
|
||||
<version>1.6</version>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
<version>2.0</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
@@ -115,11 +115,11 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>2.4.1</version>
|
||||
<version>2.4.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>2.7</version>
|
||||
<version>2.8.1</version>
|
||||
<configuration>
|
||||
<altDeploymentRepository>internal.repo::default::file://${project.build.directory}/mvn-repo</altDeploymentRepository>
|
||||
</configuration>
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Pipelined responses for all of the low level, non key related commands
|
||||
*/
|
||||
|
||||
@@ -5,8 +5,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
|
||||
/**
|
||||
* Common interface for sharded and non-sharded BinaryJedis
|
||||
*/
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
import redis.clients.util.Hashing;
|
||||
import redis.clients.util.Sharded;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
import redis.clients.util.Hashing;
|
||||
import redis.clients.util.Sharded;
|
||||
|
||||
public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
|
||||
implements BinaryJedisCommands {
|
||||
public BinaryShardedJedis(List<JedisShardInfo> shards) {
|
||||
@@ -409,7 +408,8 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
|
||||
return j.zrangeByScoreWithScores(key, min, max, offset, count);
|
||||
}
|
||||
|
||||
public Set<byte[]> zrangeByScore(byte[] key, byte[] min, byte[] max, int offset, int count) {
|
||||
public Set<byte[]> zrangeByScore(byte[] key, byte[] min, byte[] max,
|
||||
int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByScore(key, min, max, offset, count);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import org.apache.commons.pool.BasePoolableObjectFactory;
|
||||
import org.apache.commons.pool2.PooledObject;
|
||||
import org.apache.commons.pool2.PooledObjectFactory;
|
||||
import org.apache.commons.pool2.impl.DefaultPooledObject;
|
||||
|
||||
/**
|
||||
* PoolableObjectFactory custom impl.
|
||||
*/
|
||||
class JedisFactory extends BasePoolableObjectFactory {
|
||||
class JedisFactory implements PooledObjectFactory<Jedis> {
|
||||
private final String host;
|
||||
private final int port;
|
||||
private final int timeout;
|
||||
@@ -13,12 +15,13 @@ class JedisFactory extends BasePoolableObjectFactory {
|
||||
private final int database;
|
||||
private final String clientName;
|
||||
|
||||
public JedisFactory(final String host, final int port,
|
||||
final int timeout, final String password, final int database) {
|
||||
public JedisFactory(final String host, final int port, final int timeout,
|
||||
final String password, final int database) {
|
||||
this(host, port, timeout, password, database, null);
|
||||
}
|
||||
public JedisFactory(final String host, final int port,
|
||||
final int timeout, final String password, final int database, final String clientName) {
|
||||
|
||||
public JedisFactory(final String host, final int port, final int timeout,
|
||||
final String password, final int database, final String clientName) {
|
||||
super();
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
@@ -28,36 +31,19 @@ class JedisFactory extends BasePoolableObjectFactory {
|
||||
this.clientName = clientName;
|
||||
}
|
||||
|
||||
public Object makeObject() throws Exception {
|
||||
final Jedis jedis = new Jedis(this.host, this.port, this.timeout);
|
||||
|
||||
jedis.connect();
|
||||
if (null != this.password) {
|
||||
jedis.auth(this.password);
|
||||
}
|
||||
if( database != 0 ) {
|
||||
jedis.select(database);
|
||||
}
|
||||
if ( clientName != null ) {
|
||||
jedis.clientSetname(clientName);
|
||||
}
|
||||
|
||||
return jedis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activateObject(Object obj) throws Exception {
|
||||
if (obj instanceof Jedis) {
|
||||
final Jedis jedis = (Jedis)obj;
|
||||
public void activateObject(PooledObject<Jedis> pooledJedis)
|
||||
throws Exception {
|
||||
final BinaryJedis jedis = pooledJedis.getObject();
|
||||
if (jedis.getDB() != database) {
|
||||
jedis.select(database);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void destroyObject(final Object obj) throws Exception {
|
||||
if (obj instanceof Jedis) {
|
||||
final Jedis jedis = (Jedis) obj;
|
||||
@Override
|
||||
public void destroyObject(PooledObject<Jedis> pooledJedis) throws Exception {
|
||||
final BinaryJedis jedis = pooledJedis.getObject();
|
||||
if (jedis.isConnected()) {
|
||||
try {
|
||||
try {
|
||||
@@ -69,19 +55,40 @@ class JedisFactory extends BasePoolableObjectFactory {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean validateObject(final Object obj) {
|
||||
if (obj instanceof Jedis) {
|
||||
final Jedis jedis = (Jedis) obj;
|
||||
@Override
|
||||
public PooledObject<Jedis> makeObject() throws Exception {
|
||||
final Jedis jedis = new Jedis(this.host, this.port, this.timeout);
|
||||
|
||||
jedis.connect();
|
||||
if (null != this.password) {
|
||||
jedis.auth(this.password);
|
||||
}
|
||||
if (database != 0) {
|
||||
jedis.select(database);
|
||||
}
|
||||
if (clientName != null) {
|
||||
jedis.clientSetname(clientName);
|
||||
}
|
||||
|
||||
return new DefaultPooledObject<Jedis>(jedis);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void passivateObject(PooledObject<Jedis> pooledJedis)
|
||||
throws Exception {
|
||||
// TODO maybe should select db 0? Not sure right now.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateObject(PooledObject<Jedis> pooledJedis) {
|
||||
final BinaryJedis jedis = pooledJedis.getObject();
|
||||
try {
|
||||
return jedis.isConnected() && jedis.ping().equals("PONG");
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,19 +2,21 @@ package redis.clients.jedis;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.apache.commons.pool.impl.GenericObjectPool;
|
||||
import org.apache.commons.pool.impl.GenericObjectPool.Config;
|
||||
import org.apache.commons.pool2.impl.GenericObjectPool;
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
|
||||
import redis.clients.util.Pool;
|
||||
|
||||
public class JedisPool extends Pool<Jedis> {
|
||||
|
||||
public JedisPool(final Config poolConfig, final String host) {
|
||||
this(poolConfig, host, Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE, null);
|
||||
public JedisPool(final GenericObjectPoolConfig poolConfig, final String host) {
|
||||
this(poolConfig, host, Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT,
|
||||
null, Protocol.DEFAULT_DATABASE, null);
|
||||
}
|
||||
|
||||
public JedisPool(String host, int port) {
|
||||
this(new Config(), host, port, Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE, null);
|
||||
this(new GenericObjectPoolConfig(), host, port,
|
||||
Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE, null);
|
||||
}
|
||||
|
||||
public JedisPool(final String host) {
|
||||
@@ -24,12 +26,15 @@ public class JedisPool extends Pool<Jedis> {
|
||||
int port = uri.getPort();
|
||||
String password = uri.getUserInfo().split(":", 2)[1];
|
||||
int database = Integer.parseInt(uri.getPath().split("/", 2)[1]);
|
||||
this.internalPool = new GenericObjectPool(new JedisFactory(h, port,
|
||||
Protocol.DEFAULT_TIMEOUT, password, database, null), new Config());
|
||||
this.internalPool = new GenericObjectPool<Jedis>(
|
||||
new JedisFactory(h, port, Protocol.DEFAULT_TIMEOUT,
|
||||
password, database, null),
|
||||
new GenericObjectPoolConfig());
|
||||
} else {
|
||||
this.internalPool = new GenericObjectPool(new JedisFactory(host,
|
||||
Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, null,
|
||||
Protocol.DEFAULT_DATABASE, null), new Config());
|
||||
this.internalPool = new GenericObjectPool<Jedis>(new JedisFactory(
|
||||
host, Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT,
|
||||
null, Protocol.DEFAULT_DATABASE, null),
|
||||
new GenericObjectPoolConfig());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,39 +43,47 @@ public class JedisPool extends Pool<Jedis> {
|
||||
int port = uri.getPort();
|
||||
String password = uri.getUserInfo().split(":", 2)[1];
|
||||
int database = Integer.parseInt(uri.getPath().split("/", 2)[1]);
|
||||
this.internalPool = new GenericObjectPool(new JedisFactory(h, port,
|
||||
Protocol.DEFAULT_TIMEOUT, password, database, null), new Config());
|
||||
this.internalPool = new GenericObjectPool<Jedis>(new JedisFactory(h,
|
||||
port, Protocol.DEFAULT_TIMEOUT, password, database, null),
|
||||
new GenericObjectPoolConfig());
|
||||
}
|
||||
|
||||
public JedisPool(final Config poolConfig, final String host, int port,
|
||||
int timeout, final String password) {
|
||||
this(poolConfig, host, port, timeout, password, Protocol.DEFAULT_DATABASE, null);
|
||||
public JedisPool(final GenericObjectPoolConfig poolConfig,
|
||||
final String host, int port, int timeout, final String password) {
|
||||
this(poolConfig, host, port, timeout, password,
|
||||
Protocol.DEFAULT_DATABASE, null);
|
||||
}
|
||||
|
||||
public JedisPool(final Config poolConfig, final String host, final int port) {
|
||||
this(poolConfig, host, port, Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE, null);
|
||||
public JedisPool(final GenericObjectPoolConfig poolConfig,
|
||||
final String host, final int port) {
|
||||
this(poolConfig, host, port, Protocol.DEFAULT_TIMEOUT, null,
|
||||
Protocol.DEFAULT_DATABASE, null);
|
||||
}
|
||||
|
||||
public JedisPool(final Config poolConfig, final String host, final int port, final int timeout) {
|
||||
this(poolConfig, host, port, timeout, null, Protocol.DEFAULT_DATABASE, null);
|
||||
public JedisPool(final GenericObjectPoolConfig poolConfig,
|
||||
final String host, final int port, final int timeout) {
|
||||
this(poolConfig, host, port, timeout, null, Protocol.DEFAULT_DATABASE,
|
||||
null);
|
||||
}
|
||||
|
||||
public JedisPool(final Config poolConfig, final String host, int port, int timeout, final String password,
|
||||
public JedisPool(final GenericObjectPoolConfig poolConfig,
|
||||
final String host, int port, int timeout, final String password,
|
||||
final int database) {
|
||||
this(poolConfig, host, port, timeout, password, database, null);
|
||||
}
|
||||
|
||||
public JedisPool(final Config poolConfig, final String host, int port, int timeout, final String password,
|
||||
public JedisPool(final GenericObjectPoolConfig poolConfig,
|
||||
final String host, int port, int timeout, final String password,
|
||||
final int database, final String clientName) {
|
||||
super(poolConfig, new JedisFactory(host, port, timeout, password, database, clientName));
|
||||
super(poolConfig, new JedisFactory(host, port, timeout, password,
|
||||
database, clientName));
|
||||
}
|
||||
|
||||
|
||||
public void returnBrokenResource(final BinaryJedis resource) {
|
||||
public void returnBrokenResource(final Jedis resource) {
|
||||
returnBrokenResourceObject(resource);
|
||||
}
|
||||
|
||||
public void returnResource(final BinaryJedis resource) {
|
||||
public void returnResource(final Jedis resource) {
|
||||
returnResourceObject(resource);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,8 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import org.apache.commons.pool.impl.GenericObjectPool.Config;
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
|
||||
/**
|
||||
* Subclass of org.apache.commons.pool.impl.GenericObjectPool.Config that
|
||||
* includes getters/setters so it can be more easily configured by Spring and
|
||||
* other IoC frameworks.
|
||||
*
|
||||
* Spring example:
|
||||
*
|
||||
* <bean id="jedisConfig" class="redis.clients.jedis.JedisPoolConfig"> <property
|
||||
* name="testWhileIdle" value="true"/> </bean>
|
||||
*
|
||||
* <bean id="jedisPool" class="redis.clients.jedis.JedisPool"
|
||||
* destroy-method="destroy"> <constructor-arg ref="jedisConfig" />
|
||||
* <constructor-arg value="localhost" /> <constructor-arg type="int"
|
||||
* value="6379" /> </bean>
|
||||
*
|
||||
* For information on parameters refer to:
|
||||
*
|
||||
* http://commons.apache.org/pool/apidocs/org/apache/commons/pool/impl/
|
||||
* GenericObjectPool.html
|
||||
*/
|
||||
public class JedisPoolConfig extends Config {
|
||||
public class JedisPoolConfig extends GenericObjectPoolConfig {
|
||||
public JedisPoolConfig() {
|
||||
// defaults to make your life with connection pool easier :)
|
||||
setTestWhileIdle(true);
|
||||
@@ -30,103 +10,4 @@ public class JedisPoolConfig extends Config {
|
||||
setTimeBetweenEvictionRunsMillis(30000);
|
||||
setNumTestsPerEvictionRun(-1);
|
||||
}
|
||||
|
||||
public int getMaxIdle() {
|
||||
return maxIdle;
|
||||
}
|
||||
|
||||
public void setMaxIdle(int maxIdle) {
|
||||
this.maxIdle = maxIdle;
|
||||
}
|
||||
|
||||
public int getMinIdle() {
|
||||
return minIdle;
|
||||
}
|
||||
|
||||
public void setMinIdle(int minIdle) {
|
||||
this.minIdle = minIdle;
|
||||
}
|
||||
|
||||
public int getMaxActive() {
|
||||
return maxActive;
|
||||
}
|
||||
|
||||
public void setMaxActive(int maxActive) {
|
||||
this.maxActive = maxActive;
|
||||
}
|
||||
|
||||
public long getMaxWait() {
|
||||
return maxWait;
|
||||
}
|
||||
|
||||
public void setMaxWait(long maxWait) {
|
||||
this.maxWait = maxWait;
|
||||
}
|
||||
|
||||
public byte getWhenExhaustedAction() {
|
||||
return whenExhaustedAction;
|
||||
}
|
||||
|
||||
public void setWhenExhaustedAction(byte whenExhaustedAction) {
|
||||
this.whenExhaustedAction = whenExhaustedAction;
|
||||
}
|
||||
|
||||
public boolean isTestOnBorrow() {
|
||||
return testOnBorrow;
|
||||
}
|
||||
|
||||
public void setTestOnBorrow(boolean testOnBorrow) {
|
||||
this.testOnBorrow = testOnBorrow;
|
||||
}
|
||||
|
||||
public boolean isTestOnReturn() {
|
||||
return testOnReturn;
|
||||
}
|
||||
|
||||
public void setTestOnReturn(boolean testOnReturn) {
|
||||
this.testOnReturn = testOnReturn;
|
||||
}
|
||||
|
||||
public boolean isTestWhileIdle() {
|
||||
return testWhileIdle;
|
||||
}
|
||||
|
||||
public void setTestWhileIdle(boolean testWhileIdle) {
|
||||
this.testWhileIdle = testWhileIdle;
|
||||
}
|
||||
|
||||
public long getTimeBetweenEvictionRunsMillis() {
|
||||
return timeBetweenEvictionRunsMillis;
|
||||
}
|
||||
|
||||
public void setTimeBetweenEvictionRunsMillis(
|
||||
long timeBetweenEvictionRunsMillis) {
|
||||
this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
|
||||
}
|
||||
|
||||
public int getNumTestsPerEvictionRun() {
|
||||
return numTestsPerEvictionRun;
|
||||
}
|
||||
|
||||
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
|
||||
this.numTestsPerEvictionRun = numTestsPerEvictionRun;
|
||||
}
|
||||
|
||||
public long getMinEvictableIdleTimeMillis() {
|
||||
return minEvictableIdleTimeMillis;
|
||||
}
|
||||
|
||||
public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {
|
||||
this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
|
||||
}
|
||||
|
||||
public long getSoftMinEvictableIdleTimeMillis() {
|
||||
return softMinEvictableIdleTimeMillis;
|
||||
}
|
||||
|
||||
public void setSoftMinEvictableIdleTimeMillis(
|
||||
long softMinEvictableIdleTimeMillis) {
|
||||
this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,14 +7,14 @@ import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.apache.commons.pool.impl.GenericObjectPool.Config;
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
|
||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
import redis.clients.util.Pool;
|
||||
|
||||
public class JedisSentinelPool extends Pool<Jedis> {
|
||||
|
||||
protected Config poolConfig;
|
||||
protected GenericObjectPoolConfig poolConfig;
|
||||
|
||||
protected int timeout = Protocol.DEFAULT_TIMEOUT;
|
||||
|
||||
@@ -27,43 +27,44 @@ public class JedisSentinelPool extends Pool<Jedis> {
|
||||
protected Logger log = Logger.getLogger(getClass().getName());
|
||||
|
||||
public JedisSentinelPool(String masterName, Set<String> sentinels,
|
||||
final Config poolConfig) {
|
||||
final GenericObjectPoolConfig poolConfig) {
|
||||
this(masterName, sentinels, poolConfig, Protocol.DEFAULT_TIMEOUT, null,
|
||||
Protocol.DEFAULT_DATABASE);
|
||||
}
|
||||
|
||||
public JedisSentinelPool(String masterName, Set<String> sentinels) {
|
||||
this(masterName, sentinels, new Config(), Protocol.DEFAULT_TIMEOUT,
|
||||
null, Protocol.DEFAULT_DATABASE);
|
||||
this(masterName, sentinels, new GenericObjectPoolConfig(),
|
||||
Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE);
|
||||
}
|
||||
|
||||
public JedisSentinelPool(String masterName, Set<String> sentinels,
|
||||
String password) {
|
||||
this(masterName, sentinels, new Config(), Protocol.DEFAULT_TIMEOUT,
|
||||
password);
|
||||
this(masterName, sentinels, new GenericObjectPoolConfig(),
|
||||
Protocol.DEFAULT_TIMEOUT, password);
|
||||
}
|
||||
|
||||
public JedisSentinelPool(String masterName, Set<String> sentinels,
|
||||
final Config poolConfig, int timeout, final String password) {
|
||||
final GenericObjectPoolConfig poolConfig, int timeout,
|
||||
final String password) {
|
||||
this(masterName, sentinels, poolConfig, timeout, password,
|
||||
Protocol.DEFAULT_DATABASE);
|
||||
}
|
||||
|
||||
public JedisSentinelPool(String masterName, Set<String> sentinels,
|
||||
final Config poolConfig, final int timeout) {
|
||||
final GenericObjectPoolConfig poolConfig, final int timeout) {
|
||||
this(masterName, sentinels, poolConfig, timeout, null,
|
||||
Protocol.DEFAULT_DATABASE);
|
||||
}
|
||||
|
||||
public JedisSentinelPool(String masterName, Set<String> sentinels,
|
||||
final Config poolConfig, final String password) {
|
||||
final GenericObjectPoolConfig poolConfig, final String password) {
|
||||
this(masterName, sentinels, poolConfig, Protocol.DEFAULT_TIMEOUT,
|
||||
password);
|
||||
}
|
||||
|
||||
public JedisSentinelPool(String masterName, Set<String> sentinels,
|
||||
final Config poolConfig, int timeout, final String password,
|
||||
final int database) {
|
||||
final GenericObjectPoolConfig poolConfig, int timeout,
|
||||
final String password, final int database) {
|
||||
this.poolConfig = poolConfig;
|
||||
this.timeout = timeout;
|
||||
this.password = password;
|
||||
@@ -73,11 +74,11 @@ public class JedisSentinelPool extends Pool<Jedis> {
|
||||
initPool(master);
|
||||
}
|
||||
|
||||
public void returnBrokenResource(final BinaryJedis resource) {
|
||||
public void returnBrokenResource(final Jedis resource) {
|
||||
returnBrokenResourceObject(resource);
|
||||
}
|
||||
|
||||
public void returnResource(final BinaryJedis resource) {
|
||||
public void returnResource(final Jedis resource) {
|
||||
returnResourceObject(resource);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,29 +3,31 @@ package redis.clients.jedis;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.pool.BasePoolableObjectFactory;
|
||||
import org.apache.commons.pool.impl.GenericObjectPool;
|
||||
import org.apache.commons.pool2.PooledObject;
|
||||
import org.apache.commons.pool2.PooledObjectFactory;
|
||||
import org.apache.commons.pool2.impl.DefaultPooledObject;
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
|
||||
import redis.clients.util.Hashing;
|
||||
import redis.clients.util.Pool;
|
||||
|
||||
public class ShardedJedisPool extends Pool<ShardedJedis> {
|
||||
public ShardedJedisPool(final GenericObjectPool.Config poolConfig,
|
||||
public ShardedJedisPool(final GenericObjectPoolConfig poolConfig,
|
||||
List<JedisShardInfo> shards) {
|
||||
this(poolConfig, shards, Hashing.MURMUR_HASH);
|
||||
}
|
||||
|
||||
public ShardedJedisPool(final GenericObjectPool.Config poolConfig,
|
||||
public ShardedJedisPool(final GenericObjectPoolConfig poolConfig,
|
||||
List<JedisShardInfo> shards, Hashing algo) {
|
||||
this(poolConfig, shards, algo, null);
|
||||
}
|
||||
|
||||
public ShardedJedisPool(final GenericObjectPool.Config poolConfig,
|
||||
public ShardedJedisPool(final GenericObjectPoolConfig poolConfig,
|
||||
List<JedisShardInfo> shards, Pattern keyTagPattern) {
|
||||
this(poolConfig, shards, Hashing.MURMUR_HASH, keyTagPattern);
|
||||
}
|
||||
|
||||
public ShardedJedisPool(final GenericObjectPool.Config poolConfig,
|
||||
public ShardedJedisPool(final GenericObjectPoolConfig poolConfig,
|
||||
List<JedisShardInfo> shards, Hashing algo, Pattern keyTagPattern) {
|
||||
super(poolConfig, new ShardedJedisFactory(shards, algo, keyTagPattern));
|
||||
}
|
||||
@@ -33,7 +35,8 @@ public class ShardedJedisPool extends Pool<ShardedJedis> {
|
||||
/**
|
||||
* PoolableObjectFactory custom impl.
|
||||
*/
|
||||
private static class ShardedJedisFactory extends BasePoolableObjectFactory {
|
||||
private static class ShardedJedisFactory implements
|
||||
PooledObjectFactory<ShardedJedis> {
|
||||
private List<JedisShardInfo> shards;
|
||||
private Hashing algo;
|
||||
private Pattern keyTagPattern;
|
||||
@@ -45,14 +48,16 @@ public class ShardedJedisPool extends Pool<ShardedJedis> {
|
||||
this.keyTagPattern = keyTagPattern;
|
||||
}
|
||||
|
||||
public Object makeObject() throws Exception {
|
||||
@Override
|
||||
public PooledObject<ShardedJedis> makeObject() throws Exception {
|
||||
ShardedJedis jedis = new ShardedJedis(shards, algo, keyTagPattern);
|
||||
return jedis;
|
||||
return new DefaultPooledObject<ShardedJedis>(jedis);
|
||||
}
|
||||
|
||||
public void destroyObject(final Object obj) throws Exception {
|
||||
if ((obj != null) && (obj instanceof ShardedJedis)) {
|
||||
ShardedJedis shardedJedis = (ShardedJedis) obj;
|
||||
@Override
|
||||
public void destroyObject(PooledObject<ShardedJedis> pooledShardedJedis)
|
||||
throws Exception {
|
||||
final ShardedJedis shardedJedis = pooledShardedJedis.getObject();
|
||||
for (Jedis jedis : shardedJedis.getAllShards()) {
|
||||
try {
|
||||
try {
|
||||
@@ -66,11 +71,12 @@ public class ShardedJedisPool extends Pool<ShardedJedis> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean validateObject(final Object obj) {
|
||||
@Override
|
||||
public boolean validateObject(
|
||||
PooledObject<ShardedJedis> pooledShardedJedis) {
|
||||
try {
|
||||
ShardedJedis jedis = (ShardedJedis) obj;
|
||||
ShardedJedis jedis = pooledShardedJedis.getObject();
|
||||
for (Jedis shard : jedis.getAllShards()) {
|
||||
if (!shard.ping().equals("PONG")) {
|
||||
return false;
|
||||
@@ -81,5 +87,17 @@ public class ShardedJedisPool extends Pool<ShardedJedis> {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activateObject(PooledObject<ShardedJedis> p)
|
||||
throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void passivateObject(PooledObject<ShardedJedis> p)
|
||||
throws Exception {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,29 @@
|
||||
package redis.clients.util;
|
||||
|
||||
import org.apache.commons.pool.PoolableObjectFactory;
|
||||
import org.apache.commons.pool.impl.GenericObjectPool;
|
||||
import org.apache.commons.pool2.PooledObjectFactory;
|
||||
import org.apache.commons.pool2.impl.GenericObjectPool;
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
|
||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
import redis.clients.jedis.exceptions.JedisException;
|
||||
|
||||
public abstract class Pool<T> {
|
||||
protected GenericObjectPool internalPool;
|
||||
protected GenericObjectPool<T> internalPool;
|
||||
|
||||
/**
|
||||
* Using this constructor means you have to set
|
||||
* and initialize the internalPool yourself.
|
||||
* Using this constructor means you have to set and initialize the
|
||||
* internalPool yourself.
|
||||
*/
|
||||
public Pool() {}
|
||||
public Pool() {
|
||||
}
|
||||
|
||||
public Pool(final GenericObjectPool.Config poolConfig,
|
||||
PoolableObjectFactory factory) {
|
||||
public Pool(final GenericObjectPoolConfig poolConfig,
|
||||
PooledObjectFactory<T> factory) {
|
||||
initPool(poolConfig, factory);
|
||||
}
|
||||
|
||||
public void initPool(final GenericObjectPool.Config poolConfig, PoolableObjectFactory factory) {
|
||||
public void initPool(final GenericObjectPoolConfig poolConfig,
|
||||
PooledObjectFactory<T> factory) {
|
||||
|
||||
if (this.internalPool != null) {
|
||||
try {
|
||||
@@ -29,20 +32,19 @@ public abstract class Pool<T> {
|
||||
}
|
||||
}
|
||||
|
||||
this.internalPool = new GenericObjectPool(factory, poolConfig);
|
||||
this.internalPool = new GenericObjectPool<T>(factory, poolConfig);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T getResource() {
|
||||
try {
|
||||
return (T) internalPool.borrowObject();
|
||||
return internalPool.borrowObject();
|
||||
} catch (Exception e) {
|
||||
throw new JedisConnectionException(
|
||||
"Could not get a resource from the pool", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void returnResourceObject(final Object resource) {
|
||||
public void returnResourceObject(final T resource) {
|
||||
try {
|
||||
internalPool.returnObject(resource);
|
||||
} catch (Exception e) {
|
||||
@@ -63,7 +65,7 @@ public abstract class Pool<T> {
|
||||
closeInternalPool();
|
||||
}
|
||||
|
||||
protected void returnBrokenResourceObject(final Object resource) {
|
||||
protected void returnBrokenResourceObject(final T resource) {
|
||||
try {
|
||||
internalPool.invalidateObject(resource);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -3,12 +3,10 @@ package redis.clients.jedis.tests;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.apache.commons.pool.impl.GenericObjectPool;
|
||||
import org.apache.commons.pool.impl.GenericObjectPool.Config;
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.BinaryJedis;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
@@ -76,9 +74,9 @@ public class JedisPoolTest extends Assert {
|
||||
|
||||
@Test(expected = JedisConnectionException.class)
|
||||
public void checkPoolOverflow() {
|
||||
Config config = new Config();
|
||||
config.maxActive = 1;
|
||||
config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
|
||||
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
|
||||
config.setMaxTotal(1);
|
||||
config.setBlockWhenExhausted(false);
|
||||
JedisPool pool = new JedisPool(config, hnp.host, hnp.port);
|
||||
Jedis jedis = pool.getResource();
|
||||
jedis.auth("foobared");
|
||||
@@ -93,7 +91,8 @@ public class JedisPoolTest extends Assert {
|
||||
public void securePool() {
|
||||
JedisPoolConfig config = new JedisPoolConfig();
|
||||
config.setTestOnBorrow(true);
|
||||
JedisPool pool = new JedisPool(config, hnp.host, hnp.port, 2000, "foobared");
|
||||
JedisPool pool = new JedisPool(config, hnp.host, hnp.port, 2000,
|
||||
"foobared");
|
||||
Jedis jedis = pool.getResource();
|
||||
jedis.set("foo", "bar");
|
||||
pool.returnResource(jedis);
|
||||
@@ -106,27 +105,18 @@ public class JedisPoolTest extends Assert {
|
||||
hnp.port, 2000, "foobared");
|
||||
Jedis jedis0 = pool0.getResource();
|
||||
jedis0.set("foo", "bar");
|
||||
assertEquals( "bar", jedis0.get("foo") );
|
||||
assertEquals("bar", jedis0.get("foo"));
|
||||
pool0.returnResource(jedis0);
|
||||
pool0.destroy();
|
||||
|
||||
JedisPool pool1 = new JedisPool(new JedisPoolConfig(), hnp.host,
|
||||
hnp.port, 2000, "foobared", 1);
|
||||
Jedis jedis1 = pool1.getResource();
|
||||
assertNull( jedis1.get("foo") );
|
||||
pool1.returnResource(jedis0);
|
||||
assertNull(jedis1.get("foo"));
|
||||
pool1.returnResource(jedis1);
|
||||
pool1.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnBinary() {
|
||||
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.host,
|
||||
hnp.port, 2000);
|
||||
BinaryJedis jedis = pool.getResource();
|
||||
pool.returnResource(jedis);
|
||||
pool.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWithUrlString() {
|
||||
Jedis j = new Jedis("localhost", 6380);
|
||||
@@ -145,7 +135,8 @@ public class JedisPoolTest extends Assert {
|
||||
j.auth("foobared");
|
||||
j.select(2);
|
||||
j.set("foo", "bar");
|
||||
JedisPool pool = new JedisPool(new URI("redis://:foobared@localhost:6380/2"));
|
||||
JedisPool pool = new JedisPool(new URI(
|
||||
"redis://:foobared@localhost:6380/2"));
|
||||
Jedis jedis = pool.getResource();
|
||||
assertEquals("PONG", jedis.ping());
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
@@ -153,7 +144,8 @@ public class JedisPoolTest extends Assert {
|
||||
|
||||
@Test
|
||||
public void selectDatabaseOnActivation() {
|
||||
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.host, hnp.port, 2000, "foobared");
|
||||
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.host,
|
||||
hnp.port, 2000, "foobared");
|
||||
|
||||
Jedis jedis0 = pool.getResource();
|
||||
assertEquals(0L, jedis0.getDB().longValue());
|
||||
@@ -184,4 +176,3 @@ public class JedisPoolTest extends Assert {
|
||||
pool0.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package redis.clients.jedis.tests;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.pool.impl.GenericObjectPool.Config;
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -63,7 +63,7 @@ public class JedisSentinelPoolTest extends JedisTestBase {
|
||||
@Test
|
||||
public void ensureSafeTwiceFailover() throws InterruptedException {
|
||||
JedisSentinelPool pool = new JedisSentinelPool("mymaster", sentinels,
|
||||
new Config(), 1000, "foobared", 2);
|
||||
new GenericObjectPoolConfig(), 1000, "foobared", 2);
|
||||
|
||||
// perform failover
|
||||
doSegFaultMaster(pool);
|
||||
@@ -75,7 +75,8 @@ public class JedisSentinelPoolTest extends JedisTestBase {
|
||||
// but you need to prepare additional slave per failover
|
||||
}
|
||||
|
||||
private void doSegFaultMaster(JedisSentinelPool pool) throws InterruptedException {
|
||||
private void doSegFaultMaster(JedisSentinelPool pool)
|
||||
throws InterruptedException {
|
||||
// jedis connection should be master
|
||||
Jedis jedis = pool.getResource();
|
||||
assertEquals("PONG", jedis.ping());
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package redis.clients.jedis.tests;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package redis.clients.jedis.tests;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -5,8 +5,7 @@ import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.pool.impl.GenericObjectPool;
|
||||
import org.apache.commons.pool.impl.GenericObjectPool.Config;
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -45,7 +44,8 @@ public class ShardedJedisPoolTest extends Assert {
|
||||
|
||||
@Test
|
||||
public void checkConnections() {
|
||||
ShardedJedisPool pool = new ShardedJedisPool(new Config(), shards);
|
||||
ShardedJedisPool pool = new ShardedJedisPool(
|
||||
new GenericObjectPoolConfig(), shards);
|
||||
ShardedJedis jedis = pool.getResource();
|
||||
jedis.set("foo", "bar");
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
@@ -55,7 +55,8 @@ public class ShardedJedisPoolTest extends Assert {
|
||||
|
||||
@Test
|
||||
public void checkConnectionWithDefaultPort() {
|
||||
ShardedJedisPool pool = new ShardedJedisPool(new Config(), shards);
|
||||
ShardedJedisPool pool = new ShardedJedisPool(
|
||||
new GenericObjectPoolConfig(), shards);
|
||||
ShardedJedis jedis = pool.getResource();
|
||||
jedis.set("foo", "bar");
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
@@ -65,7 +66,8 @@ public class ShardedJedisPoolTest extends Assert {
|
||||
|
||||
@Test
|
||||
public void checkJedisIsReusedWhenReturned() {
|
||||
ShardedJedisPool pool = new ShardedJedisPool(new Config(), shards);
|
||||
ShardedJedisPool pool = new ShardedJedisPool(
|
||||
new GenericObjectPoolConfig(), shards);
|
||||
ShardedJedis jedis = pool.getResource();
|
||||
jedis.set("foo", "0");
|
||||
pool.returnResource(jedis);
|
||||
@@ -78,7 +80,8 @@ public class ShardedJedisPoolTest extends Assert {
|
||||
|
||||
@Test
|
||||
public void checkPoolRepairedWhenJedisIsBroken() {
|
||||
ShardedJedisPool pool = new ShardedJedisPool(new Config(), shards);
|
||||
ShardedJedisPool pool = new ShardedJedisPool(
|
||||
new GenericObjectPoolConfig(), shards);
|
||||
ShardedJedis jedis = pool.getResource();
|
||||
jedis.disconnect();
|
||||
pool.returnBrokenResource(jedis);
|
||||
@@ -91,9 +94,9 @@ public class ShardedJedisPoolTest extends Assert {
|
||||
|
||||
@Test(expected = JedisConnectionException.class)
|
||||
public void checkPoolOverflow() {
|
||||
Config config = new Config();
|
||||
config.maxActive = 1;
|
||||
config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
|
||||
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
|
||||
config.setMaxTotal(1);
|
||||
config.setBlockWhenExhausted(false);
|
||||
|
||||
ShardedJedisPool pool = new ShardedJedisPool(config, shards);
|
||||
|
||||
@@ -106,9 +109,8 @@ public class ShardedJedisPoolTest extends Assert {
|
||||
|
||||
@Test
|
||||
public void shouldNotShareInstances() {
|
||||
Config config = new Config();
|
||||
config.maxActive = 2;
|
||||
config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
|
||||
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
|
||||
config.setMaxTotal(2);
|
||||
|
||||
ShardedJedisPool pool = new ShardedJedisPool(config, shards);
|
||||
|
||||
@@ -120,7 +122,8 @@ public class ShardedJedisPoolTest extends Assert {
|
||||
|
||||
@Test
|
||||
public void checkFailedJedisServer() {
|
||||
ShardedJedisPool pool = new ShardedJedisPool(new Config(), shards);
|
||||
ShardedJedisPool pool = new ShardedJedisPool(
|
||||
new GenericObjectPoolConfig(), shards);
|
||||
ShardedJedis jedis = pool.getResource();
|
||||
jedis.incr("foo");
|
||||
pool.returnResource(jedis);
|
||||
@@ -129,8 +132,8 @@ public class ShardedJedisPoolTest extends Assert {
|
||||
|
||||
@Test
|
||||
public void shouldReturnActiveShardsWhenOneGoesOffline() {
|
||||
Config redisConfig = new Config();
|
||||
redisConfig.testOnBorrow = false;
|
||||
GenericObjectPoolConfig redisConfig = new GenericObjectPoolConfig();
|
||||
redisConfig.setTestOnBorrow(false);
|
||||
ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards);
|
||||
ShardedJedis jedis = pool.getResource();
|
||||
// fill the shards
|
||||
@@ -184,10 +187,11 @@ public class ShardedJedisPoolTest extends Assert {
|
||||
shards.add(new JedisShardInfo("redis://:foobared@localhost:6380"));
|
||||
shards.add(new JedisShardInfo("redis://:foobared@localhost:6379"));
|
||||
|
||||
Config redisConfig = new Config();
|
||||
GenericObjectPoolConfig redisConfig = new GenericObjectPoolConfig();
|
||||
ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards);
|
||||
|
||||
Jedis[] jedises = pool.getResource().getAllShards().toArray(new Jedis[2]);
|
||||
Jedis[] jedises = pool.getResource().getAllShards()
|
||||
.toArray(new Jedis[2]);
|
||||
|
||||
Jedis jedis = jedises[0];
|
||||
assertEquals("PONG", jedis.ping());
|
||||
@@ -209,13 +213,16 @@ public class ShardedJedisPoolTest extends Assert {
|
||||
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")));
|
||||
shards.add(new JedisShardInfo(new URI(
|
||||
"redis://:foobared@localhost:6380")));
|
||||
shards.add(new JedisShardInfo(new URI(
|
||||
"redis://:foobared@localhost:6379")));
|
||||
|
||||
Config redisConfig = new Config();
|
||||
GenericObjectPoolConfig redisConfig = new GenericObjectPoolConfig();
|
||||
ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards);
|
||||
|
||||
Jedis[] jedises = pool.getResource().getAllShards().toArray(new Jedis[2]);
|
||||
Jedis[] jedises = pool.getResource().getAllShards()
|
||||
.toArray(new Jedis[2]);
|
||||
|
||||
Jedis jedis = jedises[0];
|
||||
assertEquals("PONG", jedis.ping());
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.apache.commons.pool.impl.GenericObjectPool.Config;
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
@@ -30,8 +30,8 @@ public class PoolBenchmark {
|
||||
}
|
||||
|
||||
private static void withPool() throws Exception {
|
||||
final JedisPool pool = new JedisPool(new Config(), hnp.host, hnp.port,
|
||||
2000, "foobared");
|
||||
final JedisPool pool = new JedisPool(new GenericObjectPoolConfig(),
|
||||
hnp.host, hnp.port, 2000, "foobared");
|
||||
List<Thread> tds = new ArrayList<Thread>();
|
||||
|
||||
final AtomicInteger ind = new AtomicInteger();
|
||||
|
||||
@@ -299,11 +299,8 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
@Test
|
||||
public void ttl() {
|
||||
// This is supposed to return -2 according to
|
||||
// http://redis.io/commands/ttl
|
||||
// and needs to be fixed in Redis.
|
||||
long ttl = jedis.ttl("foo");
|
||||
assertEquals(-1, ttl);
|
||||
assertEquals(-2, ttl);
|
||||
|
||||
jedis.set("foo", "bar");
|
||||
ttl = jedis.ttl("foo");
|
||||
@@ -313,13 +310,9 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||
ttl = jedis.ttl("foo");
|
||||
assertTrue(ttl >= 0 && ttl <= 20);
|
||||
|
||||
// This is supposed to return -2 according to
|
||||
// http://redis.io/commands/ttl
|
||||
// and needs to be fixed in Redis.
|
||||
|
||||
// Binary
|
||||
long bttl = jedis.ttl(bfoo);
|
||||
assertEquals(-1, bttl);
|
||||
assertEquals(-2, bttl);
|
||||
|
||||
jedis.set(bfoo, bbar);
|
||||
bttl = jedis.ttl(bfoo);
|
||||
@@ -499,7 +492,7 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||
@Test
|
||||
public void pttl() {
|
||||
long pttl = jedis.pttl("foo");
|
||||
assertEquals(-1, pttl);
|
||||
assertEquals(-2, pttl);
|
||||
|
||||
jedis.set("foo", "bar");
|
||||
pttl = jedis.pttl("foo");
|
||||
|
||||
@@ -11,11 +11,10 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
import redis.clients.jedis.Protocol.Keyword;
|
||||
import redis.clients.jedis.Response;
|
||||
import redis.clients.jedis.Transaction;
|
||||
import redis.clients.jedis.TransactionBlock;
|
||||
import redis.clients.jedis.Protocol.Keyword;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
|
||||
public class TransactionCommandsTest extends JedisCommandTestBase {
|
||||
@@ -251,11 +250,11 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
||||
Response<String> r = t.get("foo");
|
||||
List<Object> l = t.exec();
|
||||
assertEquals(JedisDataException.class, l.get(1).getClass());
|
||||
try{
|
||||
try {
|
||||
error.get();
|
||||
fail("We expect exception here!");
|
||||
}catch(JedisDataException e){
|
||||
//that is fine we should be here
|
||||
} catch (JedisDataException e) {
|
||||
// that is fine we should be here
|
||||
}
|
||||
assertEquals(r.get(), "bar");
|
||||
}
|
||||
@@ -269,11 +268,11 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
||||
t.get("foo");
|
||||
|
||||
List<Response<?>> lr = t.execGetResponse();
|
||||
try{
|
||||
try {
|
||||
lr.get(1).get();
|
||||
fail("We expect exception here!");
|
||||
}catch(JedisDataException e){
|
||||
//that is fine we should be here
|
||||
} catch (JedisDataException e) {
|
||||
// that is fine we should be here
|
||||
}
|
||||
assertEquals("bar", lr.get(2).get());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user