这就是我让 python 与 cassandra 通信的方式。
首先需要建立连接,添加:
import cql
con= cql.connect(host="127.0.0.1",port=9160,keyspace="testKS")
Run Code Online (Sandbox Code Playgroud)
然后生成一个用于查询的游标:
cur=con.cursor()
result=cur.execute("select * from TestCF")
Run Code Online (Sandbox Code Playgroud)
我可以通过以下方式看到结果:
result.fetchone()
Run Code Online (Sandbox Code Playgroud)
或者
result.fetch()
Run Code Online (Sandbox Code Playgroud)
这很好地查询并且不需要额外的库,例如 pycasaa 或 cqlengine
| 归档时间: |
|
| 查看次数: |
12181 次 |
| 最近记录: |