我刚刚通过 Docker 创建了两个 Cassandra 集群。该docker exec -it name nodetool status
命令告诉集群创建一切正常:
然后我将尝试从 Python 驱动程序将数据插入到表中。
这是我的代码:
from cassandra.cluster import Cluster
from faker import Faker
import time
fake = Faker()
num = 0
cluster = Cluster(['172.17.0.2', '172.17.0.3'], port=9042)
session = cluster.connect()
session.execute('USE keys')
print("Start create data")
start = time.time()
for i in range(10000):
time.sleep(0.001)
num+=1
session.execute(
"""
INSERT INTO tt (id, title) VALUES (%(id)s, %(title)s)
""",
{'id': num, 'title': fake.address()}
)
end = time.time()
print("Total time: ", end - start)
最后,当我尝试执行代码时,我在终端中给出了以下错误: