[英]Hazelcast get ttl of key in Imap
I am using set to put values on IMap where i set the ttl.我正在使用 set 将值放在我设置 ttl 的 IMap 上。 The problem i am trying to solve is, when i read the key from the map, i want to be able to get the corresponding ttl.
我试图解决的问题是,当我从地图中读取密钥时,我希望能够获得相应的 ttl。 I am new to hazelcast, would appreciate some help.
我是hazelcast的新手,希望得到一些帮助。
val testMap: IMap[String, String] = hc.getNativeInstance().getMap(testhcMap)
if (!testMap.containsKey(key)) {
val duration = TimeUnit.HOURS
val ttlLen: Long = 1
md5Map.set(key: String, event: acp_event, ttlLen: Long, duration: TimeUnit)
return true
}
The above snippet sets the values.上面的代码片段设置了值。 I want to add one more check before inserting data into the IMap, I want to check if the ttl is less than an hour and do some action based on that.
我想在将数据插入 IMap 之前再添加一个检查,我想检查 ttl 是否小于一个小时并基于此执行一些操作。
This should help you out:这应该可以帮助您:
IMap<String, String> foo;
foo.getEntryView(key).getExpirationTime();
You cannot access the TTL value.您无法访问 TTL 值。 You would have to store it (the deadline => currentTime + timeout = deadline) in either key or value before you actually store it in Hazelcast.
在将其实际存储在 Hazelcast 之前,您必须将其存储在键或值中(截止日期 => 当前时间 + 超时 = 截止日期)。 Easiest way might be to use some envelope-alike class to store the actual value + deadline.
最简单的方法可能是使用一些类似信封的类来存储实际值 + 截止日期。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.