You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by blasteralfred <bl...@gmail.com> on 2017/05/17 09:49:09 UTC

How to get number of cache entries in a particular cache, in a single ignite instance?

Hi everyone,

I am learning Ignite, and would like to know if this is possible. Whenever a
new entry is pushed to cache, I want to confirm it by looking the count,
just like `numrows` of an sql table. Is this possible? I am trying to build
a stub, which takes cache name as input and return the number of entries in
it. Kindly help me if somebody know something regarding this.

Thank you.



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/How-to-get-number-of-cache-entries-in-a-particular-cache-in-a-single-ignite-instance-tp12966.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: How to get number of cache entries in a particular cache, in a single ignite instance?

Posted by Andrey Gura <ag...@apache.org>.
Hi,

you can use "select count(*) from TableName" query. In order to limit
query by particular local node you should set local flag to true and
execute query on this node. In other words you should do something
like this on your node:


IgniteCache cache = ignite.getOrCreateCache(CacheName); // get cache proxy

Query qry = new SqlFieldsQuery("select count(*) from TableName"); //
create query
qry.setLocal(true); // make query local

QueryCursor cursor = cache.query(qry); // exceute query


If table and cache are the same things in your case then you can just
query local cache size without any SQL:

IgniteCache cache = ignite.getOrCreateCache(CacheName); // get cache proxy

int size = cache.localSize(CachePeekMode.ALL);


On Wed, May 17, 2017 at 12:49 PM, blasteralfred <bl...@gmail.com> wrote:
> Hi everyone,
>
> I am learning Ignite, and would like to know if this is possible. Whenever a
> new entry is pushed to cache, I want to confirm it by looking the count,
> just like `numrows` of an sql table. Is this possible? I am trying to build
> a stub, which takes cache name as input and return the number of entries in
> it. Kindly help me if somebody know something regarding this.
>
> Thank you.
>
>
>
> --
> View this message in context: http://apache-ignite-users.70518.x6.nabble.com/How-to-get-number-of-cache-entries-in-a-particular-cache-in-a-single-ignite-instance-tp12966.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.