Redis 中的 CRUD 和关系:如何

CRUD & Relationships in Redis: How to

所以 Redis(PHP 的 Predis 库)非常有用,因为这个 SO 答案清楚地显示了许多用例:What is Redis and what do I use it for? 这个答案着眼于处理与 Redis 的多对多关系:how to have relations many to many in redis

问题: Redis 中的 CRUD 和分页。我们如何实现这一目标?我们是否需要将整个 table(所有行)预加载到 Redis 中?

环境: LAMP堆栈,OSX

How do we achieve this?

对于分页,如果您的后端数据结构是:

  • 列表使用 lrange
  • 一组使用sscan
  • 哈希使用hscan

请注意,*scan 函数可以产生多次相同的值,因此您必须向客户端确保您在每次迭代中收到的数据是唯一的。

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

这显然取决于您的用例。但是,是的,直接与 redis 对话比与 redis 对话更容易 mysql (但是,如果您以适当的方式分片数据,则可以毫无问题地成功完成)。