如何在Hazelcast的IMap中选择多个键?

huangapple go评论81阅读模式
英文:

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&lt;ModelTest, String&gt; map = hazelcastInstance.getMap(&quot;map-name&quot;);
        ModelTest t1 = new ModelTest();
		t1.setId1(&quot;a1&quot;);
		t1.setId2(&quot;a2&quot;);
		t1.setId3(&quot;a3&quot;);

		ModelTest t2 = new ModelTest();
		t2.setId1(&quot;b1&quot;);
		t2.setId2(&quot;b2&quot;);
		t2.setId3(&quot;b3&quot;);
       
       //Loading into cache
        map.put(t1, &quot;rakesh&quot;);
		map.put(t2, &quot;ramkumar&quot;);

I'm able to fetch values by passing a single key at a time

Example:

SqlPredicate predicate = new SqlPredicate(&quot;__key.id1=&#39;a1&#39;&quot;);

Is it possible to select more than one key at a time?

SqlPredicate predicate = new SqlPredicate(&quot;__key.id1=&#39;a1&#39; and __key.id2=&#39;b2&#39;&quot;);

Something like the above code?

I don't want to use Predicate because it's not dynamic.

Predicate predicate = e.is( &quot;active&quot; ).and( e.get( &quot;age&quot; ).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(&quot;__key.id1=&#39;a1&#39; or __key.id2=&#39;b2&#39;&quot;);

huangapple
  • 本文由 发表于 2020年8月10日 02:05:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/63329678.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定