Get amount of pairs in KV before listing

I’m using a worker and kv for a leaderboard. Love it so far but since the daily limit for listing all keys is 1000. I decided to add my own limit which goes from 0 to 1000 in a day. That way it won’t use up all my lists in the beginning. The problem is that, if the time comes where there are more than 1000 pairs then I would need to retrieve the remaining pairs since the max return limit for listing keys is 1000. So I would need to list twice. For my own rate limit system I tell it how many times I’m going to use the function. So I want to add something so it sees how many pairs there are and just calculates how many times I need to list the keys to get the whole leaderboard.

I can’t seem to find a way to get the amount of pairs stored in a kv namespace. I’ve looked at the cloudflare API and saw that you can get the “storedKeys” but firstly that returns two namespace IDs while I only have one kv, the leaderboard, and it also returns the wrong number, or sometimes the actual amount is devided over the two IDs. I just can’t seem to understand how that works.

Still looking for an answer

It’s probably not the answer you are looking for, but why not just upgrade to the Workers Bundled plan? It includes a million lists of $5 and solve your problem, surely just your time is worth more than that.