Cassandra Demo--Python操作cassandra,,==========
Cassandra Demo--Python操作cassandra,,==========
================================================================
创建keyspace和table
CREATE KEYSPACE exps WITH REPLICATION = { ‘class‘ : ‘NetworkTopologyStrategy‘, ‘DC1‘ : 2 };create table exps_user(user_id int primary key,user_name varchar,user_info text);create index idx_user_name on exps_user(user_name);
================================================================
需要安装python依赖包cassandra-driver:
from cassandra.cluster import Clusterfrom cassandra.policies import DCAwareRoundRobinPolicyfrom cassandra import ConsistencyLevelcluster_instances = [‘192.168.199.171‘, ‘192.168.199.172‘, ‘192.168.199.173‘]cluster = Cluster( cluster_instances, load_balancing_policy=DCAwareRoundRobinPolicy(local_dc=‘DC1‘), port=9042)session = cluster.connect("exps")for user_id in range(1, 50000): try: sql_script = ("insert into exps_user(user_id,user_name,user_info)" "VALUES({0},‘U{0}‘,‘THIS IS TEST‘);").format(user_id) user_lookup_stmt = session.prepare(sql_script) user_lookup_stmt.consistency_level = ConsistencyLevel.LOCAL_ONE user1 = session.execute(user_lookup_stmt, []) except Exception as ex: print(str(ex))
Cassandra Demo--Python操作cassandra
相关内容
- Linux配置python,,文章出处https:
- python修改文件的属性,,1、执行attrib
- Python第三方库之openpyxl(4),,Python第三方库
- Python访问MongoDB,并且转换成Dataframe,,#!/usr/bin
- python识别图片,,import req
- python学习——反射练习,,1.类变量和实例变量
- python winpdb远程调试,, 1.使用rpdb2
- python-flask-scoped_session创建session的两种方式,,scoped_ses
- Python os.walk() 遍历出当前目录下的文件夹和文件,,os.
- Python里Pure paths、PurePosixPath、PureWindowsPath的区别,,Pyt
评论关闭