0

So Redis (Predis Library for PHP) is incredibly useful, as this SO answer clearly shows the many use cases: What is Redis and what do I use it for? And this answer looks at handling many to many relationships with Redis: how to have relations many to many in redis

QUESTION: CRUD & Pagination in Redis. How do we achieve this? Do we need to pre-load the entire table (all rows) into Redis?

Environment: LAMP Stack, OSX

Community
  • 1
  • 1
Donal.Lynch.Msc
  • 3,365
  • 12
  • 48
  • 78

1 Answers1

1

How do we achieve this?

For pagination, if your backend data-structure is:

  • a list use lrange
  • a set use sscan
  • a hash use hscan

Note that *scan function can yield multiple times the same value so you will have to do ensure client-side that the data your received at each iteration is unique.

Do we need to pre-load the entire table (all rows) into Redis?

It clearly depends on your use-case. But yes, it will be easier to talk directly to redis than to talk to redis and mysql at the time (however that can be done sucessfully without issue if you shard your data in a proper way).

FGRibreau
  • 7,021
  • 2
  • 39
  • 48
  • Thanks! In relation to pre-loading: Do you put the result of 'select * from table_x' directly into redis and use this rather than hitting the db (MySQL)? – Donal.Lynch.Msc Mar 01 '15 at 12:47
  • 1
    You can indeed! However you will have to handle cache invalidation by yourself so be sure adding a caching layer is really the next thing to do – FGRibreau Mar 01 '15 at 15:39