Skip to content

Commit

Permalink
Finis challenge redislabs-training#4
Browse files Browse the repository at this point in the history
  • Loading branch information
quyluongthanh committed Feb 7, 2023
1 parent 2e57263 commit 04e047e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ public CapacityReport getReport(Integer limit) {
@Override
public Long getRank(Long siteId) {
// START Challenge #4
return -2L;
// return -2L;
// END Challenge #4

String capacityRankingKey = RedisSchema.getCapacityRankingKey();

try (Jedis jedis = jedisPool.getResource()) {
return jedis.zrevrank(capacityRankingKey, String.valueOf(siteId));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ private void insertMetric(Jedis jedis, long siteId, double value, MetricUnit uni
// END Challenge #2

MeasurementMinute mm = new MeasurementMinute(value, minuteOfDay);

jedis.zadd(metricKey, minuteOfDay, mm.toString());
jedis.expire(metricKey, METRIC_EXPIRATION_SECONDS);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private void updateBasic(Jedis jedis, String key, MeterReading reading) {
// Challenge #3
private void updateOptimized(Jedis jedis, String key, MeterReading reading) {
// START Challenge #3
// END Challenge #3

String reportingTime = ZonedDateTime.now(ZoneOffset.UTC).toString();

Expand All @@ -98,8 +99,6 @@ private void updateOptimized(Jedis jedis, String key, MeterReading reading) {
script.updateIfGreater(multi, key, SiteStats.maxCapacityField, getCurrentCapacity(reading));

multi.exec();

// END Challenge #3
}

private Double getCurrentCapacity(MeterReading reading) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void getReport() {
}

// Challenge #4
@Ignore
// @Ignore
@Test
public void getRank() {
CapacityDao dao = new CapacityDaoRedisImpl(jedisPool);
Expand Down

0 comments on commit 04e047e

Please sign in to comment.