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..3933ea5 100644 --- a/src/main/java/com/redislabs/university/RU102J/dao/FeedDaoRedisImpl.java +++ b/src/main/java/com/redislabs/university/RU102J/dao/FeedDaoRedisImpl.java @@ -22,6 +22,16 @@ public FeedDaoRedisImpl(JedisPool jedisPool) { @Override public void insert(MeterReading meterReading) { // START Challenge #6 + try (Jedis jedis = jedisPool.getResource()) { + String globalFeedKey = RedisSchema.getGlobalFeedKey(); + String siteFeedKey = RedisSchema.getFeedKey(meterReading.getSiteId()); + Pipeline p = jedis.pipelined(); + p.xadd(globalFeedKey, StreamEntryID.NEW_ENTRY, meterReading.toMap(), + globalMaxFeedLength, true); + p.xadd(siteFeedKey, StreamEntryID.NEW_ENTRY, meterReading.toMap(), + siteMaxFeedLength, true); + p.sync(); + } // END Challenge #6 }