Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mate0021 committed Mar 20, 2022
1 parent 667ced2 commit 71204ab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import java.nio.channels.Pipe;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class FeedDaoRedisImpl implements FeedDao {
Expand All @@ -22,6 +24,15 @@ public FeedDaoRedisImpl(JedisPool jedisPool) {
@Override
public void insert(MeterReading meterReading) {
// START Challenge #6
String globalKey = RedisSchema.getGlobalFeedKey();
String localKey = RedisSchema.getFeedKey(meterReading.getSiteId());

try (Jedis jedis = jedisPool.getResource()) {
final Pipeline p = jedis.pipelined();
p.xadd(globalKey, StreamEntryID.NEW_ENTRY, meterReading.toMap(), globalMaxFeedLength, true);
p.xadd(localKey, StreamEntryID.NEW_ENTRY, meterReading.toMap(), siteMaxFeedLength, true);
p.sync();
}
// END Challenge #6
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void flush() {
}

// Challenge #6
@Ignore
// @Ignore
@Test
public void testBasicInsertReturnsRecent() {
FeedDao dao = new FeedDaoRedisImpl(jedisPool);
Expand Down

0 comments on commit 71204ab

Please sign in to comment.