jldupont
jldupont

Reputation: 96716

paging through entries in redis hash

I couldn't find a way to "page" through redis hashes (doc).

I've got ~5million hash entries in 1 redis db. I am trying to iterate through all of them without having to resort to building a list of entry keys.

Can this be achieved?

Upvotes: 2

Views: 6899

Answers (3)

Ronak Kalyani
Ronak Kalyani

Reputation: 113

I had exactly the same requirement of Redis Hash Pagination and yes it is possible to page through redis hash using HSCAN command. Detailed documentation of the same is present at SCAN.

Usage: Hscan <your key/hash name> <cursor-id> count <page-size>.
cursor id which should be passed initially is 0 and it returns a cursor-id and data which is of page-size. The cursor id returned needs to be passed in the subsequent call for fetching subsequent data.

Upvotes: 2

Didier Spezia
Didier Spezia

Reputation: 73226

See my answer to this question for an example of key iteration by using extra sets.

There is no way to avoid storing extra sets (or lists) and still iterate on a huge number of keys. The KEYS command is not an option.

Upvotes: 3

plus-
plus-

Reputation: 46543

Since all the redis hash commands require the key element. You need to store your set of keys to page your hash.

Upvotes: 3

Related Questions