3

嗨,我是 gemfire 的新手,我想在我设置的空闲时间后从 gemfire 区域中获取特定键的数据。

我通过下面的代码使用redis做到了这一点。

jedis.set(key, value);
config.setMaxIdle(50);
jedis.expire(key, config.getMaxIdle());

但是如何在 gemfire 中做到这一点。

任何帮助。

谢谢。

4

2 回答 2

2

如果您将区域配置为使用自定义过期时间,则可以控制单个密钥的过期时间。您提供 CustomExpiry 接口的实现,该接口可以查看每个条目并决定它应该何时过期。例如:

RegionFactory regionFactory = ...
regionFactory.setCustomEntryIdleTimeout(new CustomExpiry() {
    public ExpirationAttributes getExpiry(Entry entry) {
      if(entry.getKey().equals("XXX")) {
        return new ExpirationAttributes(50, ExpirationAction.INVALIDATE); 
      }
    }
});
于 2016-08-04T23:44:34.843 回答
1

如果要删除特定区域的数据,请尝试以下代码:

Region<String, String> region = cache .<String, String> createClientRegionFactory( ClientRegionShortcut.CACHING_PROXY) .setEntryTimeToLive(new ExpirationAttributes(50)) .create(PropertiesCache.getInstance().getProperty("region"));

它适用于我的情况。

于 2016-12-26T09:50:12.430 回答