Blankman
Blankman

Reputation: 267010

Is it possible to get a subset of the results in a set for paging?

I want to be able to page through the results of a set, especially if it has a few thousand items in it.

The smembers command seems to just return all the items in the set, is paging not supported?

https://redis.io/commands/smembers

Upvotes: 1

Views: 498

Answers (1)

Itamar Haber
Itamar Haber

Reputation: 49942

Paging in a Set isn't supported as Sets are not ordered.

There are two alternatives:

a) continue using Sets and call on SSCAN to iterate the members. Note the SCAN family of commands guarantees, as this is like but not identical to paging.

b) switch to using Sorted Sets and call on ZRANGE for full-blown paging.

Upvotes: 2

Related Questions