[英]Getting key value from key of hazelcast IMap
I put my object to hazelcast map using spring annotation: 我使用spring注释将对象放置到hazelcast地图中:
@Cacheable(value = "cacheName", key = "{ #someId1,#someId2}")
public String generateValue(Long someId1, Long someId2)
I would like to invalidate object from cache based on condition placed on key of the Imap. 我想根据放置在Imap键上的条件使缓存中的对象无效。 I found that key is a ArrayList with size equal 2. That is expected result.
我发现键是大小等于2的ArrayList。这是预期的结果。
Set set = cache.keySet(); // this returns Set<ArrayList<Long>>
I try to set condition on key: 我尝试在键上设置条件:
EntryObject e = new PredicateBuilder().getEntryObject();
Predicate predicateKey = e.key().get("__key#get(0)").equal(someId1).and(e.get("__key#get(1)").equal(someId2));
But invoking this predicate end up in failure: 但是调用此谓词最终会失败:
Set<Long> idKeysToInvalidate = cache.keySet(predicateKey);
com.hazelcast.query.QueryException: java.lang.IllegalArgumentException: There is no suitable accessor for '__key#get(0)' on class 'class java.util.ArrayList'
at com.hazelcast.query.impl.getters.ReflectionHelper.createGetter(ReflectionHelper.java:176)
Did anyone encounter the same issue? 有人遇到过同样的问题吗?
我自己没有做过,至少在按键上没有做过,但是您可以尝试__key#[0]
否则请看这里: http : //docs.hazelcast.org/docs/3.8/manual/html-single/index.html #查询功能于收藏和阵列
I solved issue as below: 我解决了如下问题:
EntryObject e = new PredicateBuilder().getEntryObject();
List<Long> input = Arrays.asList(someId1, someId2);
Predicate predicateKey = e.key().get("hashCode").equal(input.hashCode());
Set<List> idKeysToInvalidate = cache.keySet(predicateKey);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.