1

我如何在基于 cassandra 的 Web 应用程序中进行分页。我在服务器端使用spring MVC,在客户端使用jquery。我试过这个,但不满意。

我的行键是 UUIDType 并且每次我从客户端浏览器将开始键作为字符串发送时,所以不知道如何将其转换回 UUID。将应用一个简单的例子。

4

3 回答 3

1

如果您将 PlayOrm 用于 cassandra,它会在您查询时返回一个光标,并且当您的第一页读取前 20 个结果并显示它时,下一页可以在您的会话中使用相同的光标,它会在它离开的地方继续再次重新扫描前 20 行。

院长

于 2013-04-16T13:45:56.540 回答
1

Spring-data 预装了这个功能:

http://static.springsource.org/spring-data/data-jpa/docs/current/reference/html/repositories.html#web-pagination

于 2013-04-15T11:07:18.610 回答
0

我会建议适用于任何语言的通用解决方案。我使用 python pycassa 来解决这个问题:

第一种方法:

-Say if column_count = 10 (How many results to display on front end) 
-collect first 11 rows, sort first 10, send it to user (front end) as JSON object and also parameter last=11th_column
-User then calls for page 2, with prev = 1st_column_id, column_start=11th_column and column_count = 10. Based on this, I query cassandra like cf.get('cf', key, column_start=11th_column, column_count=10)
-This way, I can traverse, next page and previous page.
-Only issue with this approach is, I don't have all columns in super column sorted. So this did not work.

第二种方法(我在生产中使用):

-fetch all super columns and columns for a row key. e.g in python pycassa, cf.get('cf',key)
-Sort this in python using sorted and lambda function based on column values.
-Once sorted, prepare buckets and each bucked size is of page size/column count. Also filter out any rogue data if needed before bucketing.
-Store page by page results in Redis with keys such as 'row_key|page_1|super_column' and keep refreshing redis periodically.

我的第二种方法对中小数据量非常有效。

于 2013-12-18T22:10:34.620 回答