nocturnal
nocturnal

Reputation: 395

Hazelcast get ttl of key in Imap

I am using set to put values on IMap where i set the ttl. 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. I am new to hazelcast, would appreciate some help.

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.

Upvotes: 2

Views: 1846

Answers (2)

mrclean
mrclean

Reputation: 41

This should help you out:

IMap<String, String> foo;
foo.getEntryView(key).getExpirationTime();

Upvotes: 4

noctarius
noctarius

Reputation: 6094

You cannot access the TTL value. You would have to store it (the deadline => currentTime + timeout = deadline) in either key or value before you actually store it in Hazelcast. Easiest way might be to use some envelope-alike class to store the actual value + deadline.

Upvotes: 0

Related Questions