redis.clients.jedis.providers.PooledConnectionProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jedis_preview Show documentation
Show all versions of jedis_preview Show documentation
Jedis is a blazingly small and sane Redis java client.
The newest version!
package redis.clients.jedis.providers;
import java.util.Collections;
import java.util.Map;
import org.apache.commons.pool2.PooledObjectFactory;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.ClientSideCache;
import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.Connection;
import redis.clients.jedis.ConnectionFactory;
import redis.clients.jedis.ConnectionPool;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisClientConfig;
import redis.clients.jedis.util.Pool;
public class PooledConnectionProvider implements ConnectionProvider {
private final Pool pool;
private Object connectionMapKey = "";
public PooledConnectionProvider(HostAndPort hostAndPort) {
this(new ConnectionFactory(hostAndPort));
this.connectionMapKey = hostAndPort;
}
public PooledConnectionProvider(HostAndPort hostAndPort, JedisClientConfig clientConfig) {
this(new ConnectionPool(hostAndPort, clientConfig));
this.connectionMapKey = hostAndPort;
}
public PooledConnectionProvider(HostAndPort hostAndPort, JedisClientConfig clientConfig, ClientSideCache csCache) {
this(new ConnectionPool(hostAndPort, clientConfig, csCache));
this.connectionMapKey = hostAndPort;
}
public PooledConnectionProvider(HostAndPort hostAndPort, JedisClientConfig clientConfig,
GenericObjectPoolConfig poolConfig) {
this(new ConnectionPool(hostAndPort, clientConfig, poolConfig));
this.connectionMapKey = hostAndPort;
}
public PooledConnectionProvider(HostAndPort hostAndPort, JedisClientConfig clientConfig, ClientSideCache csCache,
GenericObjectPoolConfig poolConfig) {
this(new ConnectionPool(hostAndPort, clientConfig, csCache, poolConfig));
this.connectionMapKey = hostAndPort;
}
public PooledConnectionProvider(PooledObjectFactory factory) {
this(new ConnectionPool(factory));
this.connectionMapKey = factory;
}
public PooledConnectionProvider(PooledObjectFactory factory,
GenericObjectPoolConfig poolConfig) {
this(new ConnectionPool(factory, poolConfig));
this.connectionMapKey = factory;
}
private PooledConnectionProvider(Pool pool) {
this.pool = pool;
}
@Override
public void close() {
pool.close();
}
public final Pool getPool() {
return pool;
}
@Override
public Connection getConnection() {
return pool.getResource();
}
@Override
public Connection getConnection(CommandArguments args) {
return pool.getResource();
}
@Override
public Map, Pool> getConnectionMap() {
return Collections.singletonMap(connectionMapKey, pool);
}
}