【问题标题】:An example how I directly connect to Cassandra by CQL (1)我如何通过 CQL 直接连接到 Cassandra 的示例(1)
【发布时间】:2015-06-11 20:40:39
【问题描述】:

我需要完整的示例来向我展示如何通过 CQL 连接到 Cassandra。我正在开发一个应该用 (python) Django 编写的项目,我想直接做一些事情,而不仅仅是使用 cqlEngine 作为我的项目驱动程序。 感谢您的帮助。

【问题讨论】:

    标签: python django cassandra cql


    【解决方案1】:

    这就是我让 python 与 cassandra 通信的方式。

    首先需要建立连接,添加:

    import cql
    con= cql.connect(host="127.0.0.1",port=9160,keyspace="testKS")
    

    然后生成一个游标用于查询:

    cur=con.cursor()
    result=cur.execute("select * from TestCF")
    

    我可以通过以下方式查看结果:

    result.fetchone()
    

    result.fetch()
    

    这个查询很好,不需要额外的库,比如 pycasaa 或 cqlengine

    【讨论】:

    • 如果有人收到cql.apivalues.ProgrammingError: column name '\x00\x00\x00' can't be deserialized as 'org.apache.cassandra.db.marshal.CompositeType': global name 'self' is not defined。使用 cql_version='3.0.0' 作为 cql.connect 的参数,否则假定为 CQL2。欲了解更多信息,请查看this issue
    猜你喜欢
    • 2018-03-22
    • 2014-12-04
    • 2020-11-22
    • 2019-06-29
    • 2012-07-28
    • 1970-01-01
    • 2019-10-15
    • 2016-06-17
    • 1970-01-01
    相关资源
    最近更新 更多