From f0187cfae7ba636217b77f405b22d8677bac0f12 Mon Sep 17 00:00:00 2001 From: quylt Date: Tue, 7 Feb 2023 21:39:41 +0700 Subject: [PATCH] Finish challenge #6 --- .../university/RU102J/dao/FeedDaoRedisImpl.java | 12 ++++++++++++ .../university/RU102J/dao/FeedDaoRedisImplTest.java | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) 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);