Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get Keys from IgniteCache

Tags:

java

ignite

I have to get all keys stored in IgniteCache, unfortunately this method is not implemented in Ignite. I'm using java client. I thought it is a common method, what is the reason Ignite team didn't implement it?

Is there any efficient solution for getting keys?

like image 377
Forin Avatar asked Dec 10 '22 10:12

Forin


2 Answers

Thanks to @alexfedotov I created a solution for my problem, I'm positng it here, since someone may find it useful.

List<K> keys = new ArrayList<>();
cache.query(new ScanQuery<>(null)).forEach(entry -> keys.add((K) entry.getKey()));

After running this code you will receive a list with keyset.

like image 119
Forin Avatar answered Dec 23 '22 17:12

Forin


You can get all the keys using ScanQuery with a null predicate. It will return all the entries (key-value pairs).
As well you can use an SqlFieldsQuery like select _key from Entity

like image 21
alexmagnus Avatar answered Dec 23 '22 17:12

alexmagnus