Java 黑泽尔卡斯特手术

Java 黑泽尔卡斯特手术,java,hazelcast,Java,Hazelcast,通过键获取hazelcast值 IMap<tblHeaders, HazelcastJsonValue> person = hazelcastInstance.getMap("person"); person.put(new tblHeaders("1", "ram", "0001"), new HazelcastJsonValue("{ \"name

通过键获取hazelcast值

        IMap<tblHeaders, HazelcastJsonValue> person = hazelcastInstance.getMap("person");

        person.put(new tblHeaders("1", "ram", "0001"), new HazelcastJsonValue("{ \"name1\":\"John1\" }"));
        person.put(new tblHeaders("1", "vikas", "0002"), new HazelcastJsonValue("{ \"name2\":\"John2\" }"));
        person.put(new tblHeaders("1", "datrs", "0003"), new HazelcastJsonValue("{ \"name3\":\"John3\" }"));
这里如何通过传递单个键来获取值。。。 范例

这里有几件事

  • get()方法只能通过完整的键值进行检索;由于只提供部分键,get()方法将不匹配任何内容
  • IMap.values()方法接受一个谓词参数,在尝试执行基于键的部分内容或条目值的全部或部分内容进行匹配的查询时,它是正确的方法
  • 默认情况下,谓词应用于该值,但您可以通过在谓词的属性字段中使用关键字uu key(两个下划线)来指定它应用于键
  • 由于查询可能(并且确实)匹配多个项,因此正确的返回类型是HazelcastJsonValue的集合
以下代码将执行您正在尝试的操作:

Predicate schoolPredicate = Predicates.equal("__key.school_id", "1");
Collection<HazelcastJsonValue> json = person.values(schoolPredicate);
System.out.println(json); //get the value here
HazelcastJsonValue json = person.get("school_id='0001'");
System.out.println(json.toString()); //get the value here
Predicate schoolPredicate = Predicates.equal("__key.school_id", "1");
Collection<HazelcastJsonValue> json = person.values(schoolPredicate);
System.out.println(json); //get the value here
[{ "name3":"John3" }, { "name1":"John1" }, { "name2":"John2" }]