diff --git a/src/main/java/com/redislabs/university/RU102J/dao/FeedDaoRedisImpl.java b/src/main/java/com/redislabs/university/RU102J/dao/FeedDaoRedisImpl.java index 4d34dd3..d165ae4 100644 --- a/src/main/java/com/redislabs/university/RU102J/dao/FeedDaoRedisImpl.java +++ b/src/main/java/com/redislabs/university/RU102J/dao/FeedDaoRedisImpl.java @@ -23,6 +23,18 @@ public FeedDaoRedisImpl(JedisPool jedisPool) { public void insert(MeterReading meterReading) { // START Challenge #6 // END Challenge #6 + + String globalFeedKey = RedisSchema.getGlobalFeedKey(); + String feedKey = RedisSchema.getFeedKey(meterReading.getSiteId()); + + try (Jedis jedis = jedisPool.getResource()) { + Pipeline pipelined = jedis.pipelined(); + + pipelined.xadd(globalFeedKey, StreamEntryID.NEW_ENTRY, meterReading.toMap()); + pipelined.xadd(feedKey, StreamEntryID.NEW_ENTRY, meterReading.toMap()); + + pipelined.sync(); + } } @Override diff --git a/src/test/java/com/redislabs/university/RU102J/dao/FeedDaoRedisImplTest.java b/src/test/java/com/redislabs/university/RU102J/dao/FeedDaoRedisImplTest.java index bb95831..c68f2f5 100644 --- a/src/test/java/com/redislabs/university/RU102J/dao/FeedDaoRedisImplTest.java +++ b/src/test/java/com/redislabs/university/RU102J/dao/FeedDaoRedisImplTest.java @@ -53,7 +53,7 @@ public void flush() { } // Challenge #6 - @Ignore +// @Ignore @Test public void testBasicInsertReturnsRecent() { FeedDao dao = new FeedDaoRedisImpl(jedisPool);