Apache Ignite - 从缓存中获取所有内容
Apache Ignite - get all from cache
我正在尝试从 Apache Ignite 缓存中获取所有项目。
目前我可以使用
获得单个项目
ClientCache<Integer, BinaryObject> cache = igniteClient.cache("myCache").withKeepBinary();
BinaryObject temp = cache.get(1);
为了获取所有密钥,我尝试了以下方法:
try(QueryCursor<Entry<Integer,BinaryObject>> cursor = cache.query(new ScanQuery<Integer, BinaryObject>(null))) {
for (Object p : cursor)
System.out.println(p.toString());
}
这个 returns 列表 org.apache.ignite.internal.client.thin.ClientCacheEntry
是内部的,我不能调用 getValue
。
如何获取此缓存的所有项目?
通过使用 Iterator,您可以从缓存中获取所有值和键。下面是从缓存中检索所有值的示例代码。
Iterator<Entry<Integer, BinaryObject>> itr = cache.iterator();
while(itr.hasNext()) {
BinaryObject object = itr.next().getValue();
System.out.println(object);
}
以下可能会帮助您遍历缓存中的所有记录。
import javax.cache.Cache.Entry;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
import org.apache.ignite.binary.BinaryObject;
public class App5BinaryObject {
public static void main(String[] args) {
Ignition.setClientMode(true);
try (Ignite client = Ignition
.start("/Users/amritharajherle/git_new/ignite-learning-by-examples/complete/cfg/ignite-config.xml")) {
IgniteCache<BinaryObject, BinaryObject> cities = client.cache("City").withKeepBinary();
int count = 0;
for (Entry<BinaryObject, BinaryObject> entry : cities) {
count++;
BinaryObject key = entry.getKey();
BinaryObject value = entry.getValue();
System.out.println("CountyCode=" + key.field("COUNTRYCODE") + ", DISTRICT = " + value.field("DISTRICT")
+ ", POPULATION = " + value.field("POPULATION") + ", NAME = " + value.field("NAME"));
}
System.out.println("total cities count = " + count);
}
}
}
使用 Ignite Rest API 我们可以获取一定数量的记录[大小]。千辛万苦终于找到了API.
http://:8080/ignite?cmd=qryscanexe&pageSize=10&cacheName=
根据 Ignite 集群用户添加身份验证 Header。
我正在尝试从 Apache Ignite 缓存中获取所有项目。
目前我可以使用
获得单个项目ClientCache<Integer, BinaryObject> cache = igniteClient.cache("myCache").withKeepBinary();
BinaryObject temp = cache.get(1);
为了获取所有密钥,我尝试了以下方法:
try(QueryCursor<Entry<Integer,BinaryObject>> cursor = cache.query(new ScanQuery<Integer, BinaryObject>(null))) {
for (Object p : cursor)
System.out.println(p.toString());
}
这个 returns 列表 org.apache.ignite.internal.client.thin.ClientCacheEntry
是内部的,我不能调用 getValue
。
如何获取此缓存的所有项目?
通过使用 Iterator,您可以从缓存中获取所有值和键。下面是从缓存中检索所有值的示例代码。
Iterator<Entry<Integer, BinaryObject>> itr = cache.iterator();
while(itr.hasNext()) {
BinaryObject object = itr.next().getValue();
System.out.println(object);
}
以下可能会帮助您遍历缓存中的所有记录。
import javax.cache.Cache.Entry;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
import org.apache.ignite.binary.BinaryObject;
public class App5BinaryObject {
public static void main(String[] args) {
Ignition.setClientMode(true);
try (Ignite client = Ignition
.start("/Users/amritharajherle/git_new/ignite-learning-by-examples/complete/cfg/ignite-config.xml")) {
IgniteCache<BinaryObject, BinaryObject> cities = client.cache("City").withKeepBinary();
int count = 0;
for (Entry<BinaryObject, BinaryObject> entry : cities) {
count++;
BinaryObject key = entry.getKey();
BinaryObject value = entry.getValue();
System.out.println("CountyCode=" + key.field("COUNTRYCODE") + ", DISTRICT = " + value.field("DISTRICT")
+ ", POPULATION = " + value.field("POPULATION") + ", NAME = " + value.field("NAME"));
}
System.out.println("total cities count = " + count);
}
}
}
使用 Ignite Rest API 我们可以获取一定数量的记录[大小]。千辛万苦终于找到了API.
http://
根据 Ignite 集群用户添加身份验证 Header。