Correct config for redis cloud in heroku env
This commit is contained in:
parent
84859727c4
commit
93f6228034
|
@ -30,7 +30,7 @@ public class RedisDataSource implements KeyValueDataSource{
|
|||
|
||||
if (name == null) throw new NullPointerException("no name set to the db");
|
||||
|
||||
this.jedis = RedisPool.getResource();
|
||||
this.jedis = RedisPool.getResource(name);
|
||||
if (jedis == null) this.jedis = new Jedis("localhost");
|
||||
|
||||
if (CONFIG.databaseReset())
|
||||
|
@ -45,19 +45,16 @@ public class RedisDataSource implements KeyValueDataSource{
|
|||
|
||||
@Override
|
||||
public byte[] get(byte[] key) {
|
||||
jedis.select(index);
|
||||
return jedis.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(byte[] key, byte[] value) {
|
||||
jedis.select(index);
|
||||
jedis.set(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(byte[] key) {
|
||||
jedis.select(index);
|
||||
jedis.del(key);
|
||||
}
|
||||
|
||||
|
@ -68,7 +65,6 @@ public class RedisDataSource implements KeyValueDataSource{
|
|||
|
||||
@Override
|
||||
public void updateBatch(Map<byte[], byte[]> rows) {
|
||||
jedis.select(index);
|
||||
Pipeline pipeline = jedis.pipelined();
|
||||
|
||||
Iterator<Map.Entry<byte[], byte[]>> iterator = rows.entrySet().iterator();
|
||||
|
|
|
@ -19,27 +19,43 @@ import java.net.URISyntaxException;
|
|||
public class RedisPool {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("db");
|
||||
private static JedisPool pool;
|
||||
private static JedisPool state;
|
||||
private static JedisPool details;
|
||||
|
||||
static {
|
||||
|
||||
try {
|
||||
if (System.getenv("REDISCLOUD_URL") != null){
|
||||
URI redisUri = new URI(System.getenv("REDISCLOUD_URL"));
|
||||
|
||||
if (System.getenv("REDIS_STATE") != null) {
|
||||
URI redisUri = new URI(System.getenv("REDIS_STATE"));
|
||||
logger.info("Init redis pool: " + redisUri.toString());
|
||||
pool = new JedisPool(new JedisPoolConfig(),
|
||||
state = new JedisPool(new JedisPoolConfig(),
|
||||
redisUri.getHost(),
|
||||
redisUri.getPort(),
|
||||
Protocol.DEFAULT_TIMEOUT,
|
||||
redisUri.getUserInfo().split(":",2)[1]);
|
||||
}
|
||||
|
||||
if (System.getenv("REDIS_DETAILS") != null) {
|
||||
URI redisUri = new URI(System.getenv("REDIS_DETAILS"));
|
||||
logger.info("Init redis pool: " + redisUri.toString());
|
||||
details = new JedisPool(new JedisPoolConfig(),
|
||||
redisUri.getHost(),
|
||||
redisUri.getPort(),
|
||||
Protocol.DEFAULT_TIMEOUT,
|
||||
redisUri.getUserInfo().split(":",2)[1]);
|
||||
}
|
||||
|
||||
} catch (URISyntaxException e) {
|
||||
logger.info("Pool is not available");
|
||||
}
|
||||
}
|
||||
|
||||
public static Jedis getResource(){
|
||||
if (pool == null) return null;
|
||||
return pool.getResource();
|
||||
public static Jedis getResource(String name){
|
||||
if (state == null) return null;
|
||||
|
||||
if (name.equals("state")) return state.getResource();
|
||||
if (name.equals("details")) return details.getResource();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue