A spike to investigate the performance of sorting and paging with Redis.
- Redis 2.8.x
- Maven
$ mvn test
The goal is to being able to sort and paginate 1,000,000 entities in Redis with reasonable performance.
Approach 1 stores IDs in a set and use sort for sorting and paging. This approach uses less memory (328MB) but is quite slow (30.24s). The slowness comes from sorting 1 million records in memory. The test is here.
Approach 2 builds and stores indexes in a sorted set for each entity field. This approach uses more memory (484MB with selected fields) but is super fast (0.03s). The extra memory consumption comes from storing indexes for each entity field. The test is here.
Approach 2 will use almost double the memory as approach 1 in production but it offers excellent latency that end users will expect This is a typical example of space-time tradeoff. In production, Redis can be used as an LRU cache so that memory consumption is under control.