【发布时间】:2017-11-05 20:17:51
【问题描述】:
我正在使用 python Cassandra 驱动程序将多个条目插入并更新到 Cassandra 中的表中。目前我的代码如下:
cluster = Cluster()
session = cluster.connect('db')
for a in list:
if bool:
# calculate b
session.execute("UPDATE table SET col2 = %s WHERE col1 = %s", (b, a))
else:
# calculate b
session.execute("INSERT INTO table(col1, col2) VALUES(%s, %s)", (a, b))
这种插入和更新方法非常慢,因为列表中要插入的条目数量(都是唯一的)非常多。有没有更快的方法?
【问题讨论】:
-
使用
Session.execute_async方法和准备好的语句 -
bool来自哪里?它是一个内置的类名,不要将它用于您的对象 -
@AzatIbrakov execute_async() 是否按顺序执行查询?如果是这样,那么我可以使用 execute_async() 执行许多查询,只需在最后一次调用 session.execute_async() 返回的 ResponseFuture 对象上调用 result(),对吗?如果不是,那么我应该怎么做才能确保所有查询都已执行(即所有插入都已完成)?
-
“按顺序”是什么意思?它们应该是异步的,你为什么需要订单?
标签: python cassandra-3.0