From 93f6228034f3f48dbbe211cbbd41790eda0d6763 Mon Sep 17 00:00:00 2001 From: Roman Mandeleil Date: Tue, 20 Jan 2015 21:17:44 +0200 Subject: [PATCH] Correct config for redis cloud in heroku env --- .../ethereum/datasource/RedisDataSource.java | 6 +--- .../org/ethereum/datasource/RedisPool.java | 32 ++++++++++++++----- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/ethereumj-core/src/main/java/org/ethereum/datasource/RedisDataSource.java b/ethereumj-core/src/main/java/org/ethereum/datasource/RedisDataSource.java index a375b2d6..de38e4a7 100644 --- a/ethereumj-core/src/main/java/org/ethereum/datasource/RedisDataSource.java +++ b/ethereumj-core/src/main/java/org/ethereum/datasource/RedisDataSource.java @@ -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 rows) { - jedis.select(index); Pipeline pipeline = jedis.pipelined(); Iterator> iterator = rows.entrySet().iterator(); diff --git a/ethereumj-core/src/main/java/org/ethereum/datasource/RedisPool.java b/ethereumj-core/src/main/java/org/ethereum/datasource/RedisPool.java index a762040a..f1e8d120 100644 --- a/ethereumj-core/src/main/java/org/ethereum/datasource/RedisPool.java +++ b/ethereumj-core/src/main/java/org/ethereum/datasource/RedisPool.java @@ -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; } }