简体   繁体   中英

Getting key value from key of hazelcast IMap

I put my object to hazelcast map using spring annotation:

@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. I found that key is a ArrayList with size equal 2. That is expected result.

 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM