[英]Redis cursor-based pagination based on MongoDb ObjectId
I don't have experience with Redis so far, but I'm exploring possibilities to use MongoDB as database and Redis as cache. 到目前为止,我还没有使用Redis的经验,但是我正在探索将MongoDB用作数据库而将Redis用作缓存的可能性。
The question I'm dealing with is whether Redis is capable of handling MongoDb ObjectId's in the scope of cursor-based pagination as described, for example here: https://developer.twitter.com/en/docs/tweets/timelines/guides/working-with-timelines.html . 我要处理的问题是,Redis是否能够在如上所述的基于光标的分页范围内处理MongoDb ObjectId,例如: https : //developer.twitter.com/en/docs/tweets/timelines/guides /working-with-timelines.html 。
In this example we have a maxId that serves as the maximum id that was fetched from the previous request, and will be used as lower bound for fetching the next page. 在此示例中,我们有一个maxId,它用作从上一个请求中获取的最大id,并将用作获取下一页的下限。
In MongoDb I've explored that it is not a problem to user greater than / smaller than operators on ObjectId's, but I don't know if I will be capable to handle this in Redis, as ObjectId's will most probably be stored as a string value. 在MongoDb中,我探索了大于/小于ObjectId上的运算符的用户这不是问题,但是我不知道我是否能够在Redis中处理此问题,因为ObjectId很有可能将存储为字符串值。
This question is important for me as it will help me to decide whether to use MongoDb ObjectId's, or to use auto-increments as PK id. 这个问题对我来说很重要,因为它将帮助我决定是使用MongoDb ObjectId还是使用自动增量作为PK ID。 I would prefer to use ObjectId's though. 我宁愿使用ObjectId。
Note: I'm writing my backend with Java, so fancy npm modules are not what I'm looking for. 注意:我正在用Java编写后端,所以花哨的npm模块不是我想要的。
The solution I came up with: 我想出的解决方案:
This solution isn't ideal since the client will need to perform extra checks on the last processed vs the newly received results to avoid duplicate rendering, but this isn't a real problem as this is not an open api and only used internally. 该解决方案并不理想,因为客户端将需要对上次处理的结果与新收到的结果进行额外的检查,以避免重复渲染,但这并不是一个真正的问题,因为这不是开放的api,仅在内部使用。 After looking for quite some time, there doesn't appear to be an one-fit-all solution to this kind of problem. 在寻找了相当长的时间之后,似乎没有一种万能的解决方案来解决这种问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.