2
我使用python Cassandra驱动程序将多个项插入并更新到Cassandra中的表中。目前我的代码看起来像:使用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'方法与准备d语句 –
哪里'bool'从哪里来?它是一个内置的类名,不要将它用于你的对象 –
@AzatIbrakov执行execute_async()按顺序执行查询?如果是这样,那么我可以使用execute_async()来执行很多查询,并且只需要调用最后一次调用session.execute_async()所返回的ResponseFuture对象上的result(),对吧?如果不是,那么我应该怎么做以确保所有查询都已执行(即所有插入已完成)? –