简体   繁体   English

如何在 Cassandra Python 驱动程序中存储 PagingState?

[英]How to store PagingState in Cassandra Python driver?

I'm implementing a REST API which behind the scenes queries Cassandra (via Python driver) and returns the result.我正在实现一个 REST API ,它在幕后查询 Cassandra (通过 ZA7F5F35426B927411FC9231 和 B927411FC9231 驱动程序) Now the items to be queried will be huge so I want to have pagination capability.现在要查询的项目会很大,所以我想要有分页能力。

The ResultSet returned by execute() method has a property called paging_state which seems to be byte literal. execute() 方法返回的ResultSet有一个名为paging_state的属性,它似乎是字节文字。 I would like to return this in the response body with something like startKey=<PAGING_STATE_VALUE> .我想用类似startKey=<PAGING_STATE_VALUE>的东西在响应正文中返回它。 Currently, I see the paging state looking something like b'\x0cFY5D70822742\x00\xf0\x7f\xff\xff\xe6\x00' .目前,我看到分页 state 看起来像b'\x0cFY5D70822742\x00\xf0\x7f\xff\xff\xe6\x00'

How should I decode it so that I can append it as a proper string in my API response body.我应该如何解码它,以便我可以 append 它作为我的 API 响应正文中的正确字符串。 I tried decoding with UTF-8 , ASCII but they are failing.我尝试使用UTF-8ASCII进行解码,但它们失败了。

The paging state by definition is binary, and won't be represented as a string.根据定义,分页 state 是二进制的,不会表示为字符串。

Just encode it as base64, quoted printable, uuencode, or hex string - for example by using built-in binascii module.只需将其编码为 base64、带引号的可打印、uuencode 或十六进制字符串 - 例如使用内置的binascii模块。 There are plenty of functions there, like, hexlify to convert from bytes to hex string.那里有很多功能,例如hexlify将字节转换为十六进制字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM