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 297207e..cb23b3c 100644 --- a/src/main/java/com/redislabs/university/RU102J/dao/MetricDaoRedisZsetImpl.java +++ b/src/main/java/com/redislabs/university/RU102J/dao/MetricDaoRedisZsetImpl.java @@ -53,7 +53,7 @@ private void insertMetric(Jedis jedis, long siteId, double value, MetricUnit uni Integer minuteOfDay = getMinuteOfDay(dateTime); jedis.zadd(metricKey, minuteOfDay, new MeasurementMinute(value, minuteOfDay).toString()); - + jedis.expire(metricKey, METRIC_EXPIRATION_SECONDS); // END Challenge #2 } diff --git a/src/main/java/com/redislabs/university/RU102J/dao/SiteStatsDaoRedisImpl.java b/src/main/java/com/redislabs/university/RU102J/dao/SiteStatsDaoRedisImpl.java index 139331c..6bfad41 100644 --- a/src/main/java/com/redislabs/university/RU102J/dao/SiteStatsDaoRedisImpl.java +++ b/src/main/java/com/redislabs/university/RU102J/dao/SiteStatsDaoRedisImpl.java @@ -81,20 +81,19 @@ private void updateBasic(Jedis jedis, String key, MeterReading reading) { // Challenge #3 private void updateOptimized(Jedis jedis, String key, MeterReading reading) { // START Challenge #3 - String reportingTime = ZonedDateTime.now(ZoneOffset.UTC).toString(); - - Transaction t = jedis.multi(); - CompareAndUpdateScript script = new CompareAndUpdateScript(jedisPool); + try (Transaction t = jedis.multi()) { + String reportingTime = ZonedDateTime.now(ZoneOffset.UTC).toString(); - t.hset(key, SiteStats.reportingTimeField, reportingTime); - t.hincrBy(key, SiteStats.countField, 1); - t.expire(key, weekSeconds); + t.hset(key, SiteStats.reportingTimeField, reportingTime); + t.hincrBy(key, SiteStats.countField, 1); + t.expire(key, weekSeconds); - script.updateIfGreater(t, key, SiteStats.maxWhField, reading.getWhGenerated()); - script.updateIfLess(t, key, SiteStats.minWhField, reading.getWhGenerated()); - script.updateIfGreater(t, key, SiteStats.maxCapacityField, getCurrentCapacity(reading)); + this.compareAndUpdateScript.updateIfGreater(t, key, SiteStats.maxWhField, reading.getWhGenerated()); + this.compareAndUpdateScript.updateIfLess(t, key, SiteStats.minWhField, reading.getWhGenerated()); + this.compareAndUpdateScript.updateIfGreater(t, key, SiteStats.maxCapacityField, getCurrentCapacity(reading)); - t.exec(); + t.exec(); + } // END Challenge #3 }