[英]fetch hazelcast value by key
public class Model implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private String id;
private String name;
private String age;
Hazelcast Data-Storage Hazelcast 数据存储
HazelcastInstance hazelCast = Hazelcast.newHazelcastInstance();
IMap<Model, String> hazelInstance = hazelCast.getMap("data");
hazelInstance.put(new Model("001","alia","23"), "john");
how to fetch value(John) by passing the any key..如何通过传递任意键来获取值(约翰)..
Is that possible in hazelcast..?在榛树中这可能吗..?
If you mean fetch values by attributes of the map key, I think you should use IMap.values(Predicate):如果您的意思是通过 map 键的属性获取值,我认为您应该使用 IMap.values(Predicate):
@Test
public void testFetchValue() {
IMap<Model, String> map = hazelcastTestClient.getMap("data");
Model key = new Model("001","alia","23");
map.put(key, "john");
Model key2 = new Model("002","alia2","25");
map.put(key2, "eric");
Model key3 = new Model("003","alia3","23");
map.put(key3, "peter");
String value = map.get(key);
Assert.assertTrue("value should be john", "john".equals(value));
EntryObject eo = new PredicateBuilder().getEntryObject();
Predicate idPredicate = eo.key().get("id").equal("001");
Collection<String> valuesForName = map.values(idPredicate);
Assert.assertTrue("values should contain john", valuesForName.contains("john"));
Assert.assertFalse("values should not contain peter", valuesForName.contains("peter"));
Assert.assertFalse("values should not contain eric", valuesForName.contains("eric"));
eo = new PredicateBuilder().getEntryObject();
Predicate agePredicate = eo.key().get("age").equal("23");
Collection<String> valuesForAge = map.values(agePredicate);
Assert.assertTrue("values should contain john", valuesForAge.contains("john"));
Assert.assertTrue("values should contain peter", valuesForAge.contains("peter"));
Assert.assertFalse("values should not contain eric", valuesForAge.contains("eric"));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.