英文:
How to select multiple keys in Hazelcast's IMap?
问题
I'm trying to fetch values by IMap keys.
My test code:
1) Model Class
public class ModelTest implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private String id1;
private String id2;
private String id3;
public ModelTest() {
super();
}
2) Main method
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
IMap<ModelTest, String> map = hazelcastInstance.getMap("map-name");
ModelTest t1 = new ModelTest();
t1.setId1("a1");
t1.setId2("a2");
t1.setId3("a3");
ModelTest t2 = new ModelTest();
t2.setId1("b1");
t2.setId2("b2");
t2.setId3("b3");
//Loading into cache
map.put(t1, "rakesh");
map.put(t2, "ramkumar");
I'm able to fetch values by passing a single key at a time
Example:
SqlPredicate predicate = new SqlPredicate("__key.id1='a1'");
Is it possible to select more than one key at a time?
SqlPredicate predicate = new SqlPredicate("__key.id1='a1' and __key.id2='b2'");
Something like the above code?
I don't want to use Predicate
because it's not dynamic.
Predicate predicate = e.is( "active" ).and( e.get( "age" ).lessThan( 30 ) );
英文:
I'm trying to fetch values by IMap keys.
My test code:
1) Model Class
public class ModelTest implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private String id1;
private String id2;
private String id3;
public ModelTest() {
super();
}
2) Main method
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
IMap<ModelTest, String> map = hazelcastInstance.getMap("map-name");
ModelTest t1 = new ModelTest();
t1.setId1("a1");
t1.setId2("a2");
t1.setId3("a3");
ModelTest t2 = new ModelTest();
t2.setId1("b1");
t2.setId2("b2");
t2.setId3("b3");
//Loading into cache
map.put(t1, "rakesh");
map.put(t2, "ramkumar");
I'm able to fetch values by passing a single key at a time
Example:
SqlPredicate predicate = new SqlPredicate("__key.id1='a1'");
Is it possible to select more than one key at a time?
SqlPredicate predicate = new SqlPredicate("__key.id1='a1' and __key.id2='b2'");
Something like the above code?
I don't want to use Predicate
because it's not dynamic.
Predicate predicate = e.is( "active" ).and( e.get( "age" ).lessThan( 30 ) );
答案1
得分: 1
你可以使用 or
关键词一次查询多个键。
在你的情况下,以下谓词应该返回两个条目。
SqlPredicate predicate = new SqlPredicate("__key.id1='a1' or __key.id2='b2'");
英文:
You can select more than one key with one query, just use or
keyword.
In your case, the following predicate should return both entries.
SqlPredicate predicate = new SqlPredicate("__key.id1='a1' or __key.id2='b2'");
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论