在Apache Cassandra中进行分页 [英] Pagination in apache cassandra

查看:571
本文介绍了在Apache Cassandra中进行分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Cassandra中如何实现分页,我知道通过发送最后收到的时间戳,我们将能够实现它.除此之外,还有其他方法可以在Cassandra中实现分页吗?

How is the pagination achieved in Cassandra, I understand by sending the last received timestamp we will be able to achieve it. Apart from that is there any other way to achieve the Pagination in Cassandra?

此外,使用时间戳记有一个局限性,它将帮助我们仅按插入顺序进行分页.

Also, Using timestamp has the limitation that it will help us paginate only in the insert order.

推荐答案

在执行查询时可以传递页面状态的概念,查询将返回以已知状态"开头的结果. NodeJS驱动程序将查询执行后返回的结果的pageState属性公开-您可以将此状态存储在用户会话(或网页本身)中,并通过将其放入选项(例如从文档中窃取)中来重复用于下一个请求):

There is a notion of page state that you can pass when executing query, and query will return results starting with "known state". NodeJS driver exposes as pageState property of the result returned after execution of query - you can store this state in user's session (or web page itself), and reuse for next request, by putting it into options, something like (stolen from documentation):

const options = { pageState : pageState, prepare : true, fetchSize :  200 };
client.eachRow(query, parameters, options, function (n, row) { // Row callback.
 }, function (err, result) {       // End callback.
    // Store the next paging state.
    pageState = result.pageState;
 }
);

NodeJS驱动程序文档提供更多如何使用它的示例.您还可以查阅 Java驱动程序-我相信它具有有关页面状态的更多详细信息.

NodeJS driver documentation provides more examples how to use it. You can also consult documentation for Java driver - I believe that it have more details about page state.

还有一些警告,例如,您不能跳转到任意页面,状态可能在Cassandra版本之间不兼容(如果您进行滚动升级),等等.

There are also some caveats, like, you can't jump to arbitrary page, state may not be "compatible" between Cassandra versions (if you do rolling upgrade), etc.

这篇关于在Apache Cassandra中进行分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆