diff --git a/src/main/java/com/redislabs/university/RU102J/dao/MetricDaoRedisZsetImpl.java b/src/main/java/com/redislabs/university/RU102J/dao/MetricDaoRedisZsetImpl.java index 49da2ec..d95aff6 100644 --- a/src/main/java/com/redislabs/university/RU102J/dao/MetricDaoRedisZsetImpl.java +++ b/src/main/java/com/redislabs/university/RU102J/dao/MetricDaoRedisZsetImpl.java @@ -5,7 +5,6 @@ import com.redislabs.university.RU102J.api.MetricUnit; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; -import redis.clients.jedis.Pipeline; import redis.clients.jedis.Tuple; import java.text.DecimalFormat; @@ -22,10 +21,10 @@ * */ public class MetricDaoRedisZsetImpl implements MetricDao { - static private final Integer MAX_METRIC_RETENTION_DAYS = 30; - static private final Integer MAX_DAYS_TO_RETURN = 7; - static private final Integer METRICS_PER_DAY = 60 * 24; - static private final Integer METRIC_EXPIRATION_SECONDS = + private static final Integer MAX_METRIC_RETENTION_DAYS = 30; + private static final Integer MAX_DAYS_TO_RETURN = 7; + private static final Integer METRICS_PER_DAY = 60 * 24; + private static final Integer METRIC_EXPIRATION_SECONDS = 60 * 60 * 24 * MAX_METRIC_RETENTION_DAYS + 1; private final JedisPool jedisPool; @@ -51,6 +50,7 @@ private void insertMetric(Jedis jedis, long siteId, double value, MetricUnit uni // START Challenge #2 String metricKey = RedisSchema.getDayMetricKey(siteId, unit, dateTime); Integer minuteOfDay = getMinuteOfDay(dateTime); + jedis.zadd(metricKey, minuteOfDay, value + ":" + minuteOfDay); // END Challenge #2 } diff --git a/src/test/java/com/redislabs/university/RU102J/dao/MetricDaoRedisZsetImplTest.java b/src/test/java/com/redislabs/university/RU102J/dao/MetricDaoRedisZsetImplTest.java index 30e1072..d42e24f 100644 --- a/src/test/java/com/redislabs/university/RU102J/dao/MetricDaoRedisZsetImplTest.java +++ b/src/test/java/com/redislabs/university/RU102J/dao/MetricDaoRedisZsetImplTest.java @@ -6,7 +6,6 @@ import com.redislabs.university.RU102J.api.MetricUnit; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import java.time.ZoneOffset; @@ -20,8 +19,8 @@ public class MetricDaoRedisZsetImplTest extends JedisDaoTestBase { private List readings; - private Long siteId = 1L; - private ZonedDateTime startingDate = ZonedDateTime.now(ZoneOffset.UTC); + private final Long siteId = 1L; + private final ZonedDateTime startingDate = ZonedDateTime.now(ZoneOffset.UTC); @After public void flush() { @@ -48,14 +47,12 @@ public void generateData() { } // Challenge #2 - @Ignore @Test public void testSmall() { testInsertAndRetrieve(1); } // Challenge #2 - @Ignore @Test public void testOneDay() { testInsertAndRetrieve(60 * 24); @@ -63,7 +60,6 @@ public void testOneDay() { // Challenge #2 - @Ignore @Test public void testMultipleDays() { testInsertAndRetrieve(60 * 70);