Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Govind Balaji S committed Oct 16, 2022
1 parent 952a48b commit ccd1046
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
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 java.util.Map;

public class FeedDaoRedisImpl implements FeedDao {

private final JedisPool jedisPool;
private static final long globalMaxFeedLength = 10000;
private static final long siteMaxFeedLength = 2440;
private static final long GLOBAL_MAX_FEED_LENGTH = 10000;
private static final long SITE_MAX_FEED_LENGTH = 2440;

public FeedDaoRedisImpl(JedisPool jedisPool) {
this.jedisPool = jedisPool;
Expand All @@ -22,6 +21,15 @@ public FeedDaoRedisImpl(JedisPool jedisPool) {
@Override
public void insert(MeterReading meterReading) {
// START Challenge #6
Map<String, String> meterReadingMap = meterReading.toMap();
Long siteId = meterReading.getSiteId();
try (Jedis jedis = jedisPool.getResource();
Pipeline pipeline = jedis.pipelined()) {
pipeline.xadd(RedisSchema.getGlobalFeedKey(), StreamEntryID.NEW_ENTRY, meterReadingMap, GLOBAL_MAX_FEED_LENGTH,
true);
pipeline.xadd(RedisSchema.getFeedKey(siteId), StreamEntryID.NEW_ENTRY, meterReadingMap, SITE_MAX_FEED_LENGTH,
true);
}
// END Challenge #6
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.redislabs.university.RU102J.dao;

import com.redislabs.university.RU102J.HostPort;
import com.redislabs.university.RU102J.JedisDaoTestBase;
import com.redislabs.university.RU102J.TestKeyManager;
import com.redislabs.university.RU102J.api.MeterReading;
import org.junit.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -53,7 +54,6 @@ public void flush() {
}

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

0 comments on commit ccd1046

Please sign in to comment.