Skip to content

Commit

Permalink
Programming Challenge redislabs-training#6
Browse files Browse the repository at this point in the history
  • Loading branch information
ThiernoAmirouDiallo committed Nov 14, 2022
1 parent 729728e commit 51f4719
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.redislabs.university.RU102J.dao;

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;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.Pipeline;
import redis.clients.jedis.StreamEntry;
import redis.clients.jedis.StreamEntryID;

public class FeedDaoRedisImpl implements FeedDao {

Expand All @@ -20,9 +23,17 @@ public FeedDaoRedisImpl(JedisPool jedisPool) {

// Challenge #6
@Override
public void insert(MeterReading meterReading) {
// START Challenge #6
// END Challenge #6
public void insert( MeterReading meterReading ) {
// START Challenge #6
try ( Jedis jedis = jedisPool.getResource() ) {
Pipeline pipeline = jedis.pipelined();

pipeline.xadd( RedisSchema.getGlobalFeedKey(), StreamEntryID.NEW_ENTRY, meterReading.toMap() );
pipeline.xadd( RedisSchema.getFeedKey( meterReading.getSiteId() ), StreamEntryID.NEW_ENTRY, meterReading.toMap() );

pipeline.sync();
}
// END Challenge #6
}

@Override
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 51f4719

Please sign in to comment.