python 连接cassandra数据库,pythoncassandra
cassandra比mysql快(其实这是一种错误的理解方式)点击打开链接
但cassandra做group,order by操作时比较麻烦,看文章【cassandra的索引查询和排序】点击打开链接
from cassandra.cluster import Cluster
from cassandra.query import tuple_factory
from cassandra.policies import DCAwareRoundRobinPolicy
from cassandra.policies import DowngradingConsistencyRetryPolicy
from cassandra import ConsistencyLevel
from cassandra.query import dict_factory
import sys
clusterList=['cassandra服务器ip','cassandra服务器ip', 'cassandra服务器ip']
'''load_balancing_policy是负载均衡,default_retry_policy是重试策略'''
cluster=Cluster(clusterList,load_balancing_policy=DCAwareRoundRobinPolicy(local_dc='DC2'),default_retry_policy=DowngradingConsistencyRetryPolicy())
session=cluster.connect("数据库名")
'''cassandra数据的一致性'''
session.default_consistency_level = ConsistencyLevel.LOCAL_QUORUM
data=session.execute("select * from 表名 where xxx")
print data
cassandra的数据一致性:http://blog.csdn.net/u010003835/article/details/53432627
我使用的是LOCAL_QUORUM
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。