Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Streams for Feeds
Implement `insert()` in `FeedDaoRedisImpl.java`.
  • Loading branch information
J-A-I-L committed Jul 9, 2022
1 parent d9e1491 commit aaf1fb0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import com.redislabs.university.RU102J.api.MeterReading;
import redis.clients.jedis.*;

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

public class FeedDaoRedisImpl implements FeedDao {

Expand All @@ -22,9 +20,21 @@ public FeedDaoRedisImpl(JedisPool jedisPool) {
@Override
public void insert(MeterReading meterReading) {
// START Challenge #6
try (Jedis jedis = jedisPool.getResource()) {
final Pipeline pipelined = jedis.pipelined();
pipelined.xadd(RedisSchema.getGlobalFeedKey(), StreamEntryID.NEW_ENTRY, meterReading.toMap(),
globalMaxFeedLength, true);
pipelined.xadd(RedisSchema.getFeedKey(meterReading.getSiteId()), StreamEntryID.NEW_ENTRY, meterReading.toMap(),
siteMaxFeedLength, true);
pipelined.sync();
}
// END Challenge #6
}

private void insertForKey(String globalFeedKey, MeterReading meterReading, Long maxGlobalDays) {

}

@Override
public List<MeterReading> getRecentGlobal(int limit) {
return getRecent(RedisSchema.getGlobalFeedKey(), limit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public void flush() {
}

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

0 comments on commit aaf1fb0

Please sign in to comment.