【发布时间】:2020-04-11 17:43:20
【问题描述】:
我有以下代表作业运行的作业类。我在 Job 类中有一个开始和结束时间的列表,因为可以重新运行相同的 Job。
public class Job {
private final List<Timestamp> jobStartTimes = new SortedList<>();
private final List<Timestamp> jobEndTimes = new SortedList<>();
private String jobName;
private String jobKey;
private String host;
....
....
}
我有这张地图用于查询给定 jobkey 的工作。
public class JobMap {
/**
* Here value of 'String' key is jobKey
*/
private final Map<String, Job> jobCache;
}
我还创建了以下哈希映射层次结构,用于在 Map 中存储 (starttime, jobKey) 和 (endtime, jobkey) 条目,以便我可以更快地检索作业记录。这是必需的,因为我的查询是基于时间戳的,例如:返回在 x 和 y 时间戳之间运行的所有作业。
public class YearCache<T> {
/**
* Here value of 'Integer' key is month number (0, 11)
*/
private final Map<Integer, MonthCache> monthCache;
}
public class MonthCache {
/**
* Here value of 'Integer' key is week number in a month(0, 4)
*/
private final Map<Integer, WeekCache> weekCache;
}
public class WeekCache {
/**
* Here value of 'Integer' key is day number in a week (0, 6)
*/
private final Map<Integer, DayCache> dayCache;
}
private class DayCache
{
/**
* Here value of 'Integer' key is hour value in a day (0, 23)
* T is of type String representing jobKey
*/
private final NavigableMap<Integer, NavigableMap<Timestamp, Set<T>>> hourCache;
}
我想摆脱这个 Java 哈希映射并转移到 Redis 缓存。如何在 Redis 缓存中建模此层次结构?
【问题讨论】: