Forin
Forin

Reputation: 1609

get Keys from IgniteCache

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?

Upvotes: 5

Views: 5396

Answers (3)

yusuf öndersever
yusuf öndersever

Reputation: 83

The easiest way for getting all keys from cache :

ICache<string, object> cache = ignite.GetCache<string, object>(cacheName);
List<string> cacheKeys = cache.Select(e => e.Key).ToList();

Upvotes: 0

Forin
Forin

Reputation: 1609

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.

Upvotes: 8

alexmagnus
alexmagnus

Reputation: 1006

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

Upvotes: 7

Related Questions