是否有可能使来自像 redis 这样的 gemfire 区域的特定键的数据过期

Is it possible to expire data of specific key from gemfire region like redis

嗨,我是 gemfire 的新手,我想在我设置的空闲时间后从 gemfire 区域为特定密钥删除数据。

我通过以下代码使用 redis 完成了此操作。

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

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

任何帮助。

谢谢。

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

RegionFactory regionFactory = ...
regionFactory.setCustomEntryIdleTimeout(new CustomExpiry() {
    public ExpirationAttributes getExpiry(Entry entry) {
      if(entry.getKey().equals("XXX")) {
        return new ExpirationAttributes(50, ExpirationAction.INVALIDATE); 
      }
    }
});

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

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

它适用于我的情况。