Python Cassandra不会创建keysp

2024-10-05 12:26:03 发布

您现在位置:Python中文网/ 问答频道 /正文

怎样使用Python在Cassandra中创建键空间?在

from cassandra.cluster import Cluster
cluster = Cluster(['cassandra.sucks.com'])
session = cluster.connect()

session.execute('CREATE KEYSPACE IF NOT EXISTS kong')



File "cassandra/cluster.py", line 1998, in cassandra.cluster.Session.execute (cassandra/cluster.c:34869)
  File "cassandra/cluster.py", line 3781, in cassandra.cluster.ResponseFuture.result (cassandra/cluster.c:73073)
cassandra.protocol.SyntaxException: <Error from server: code=2000 [Syntax error in CQL query] message="line 0:-1 mismatched input '<EOF>' expecting K_WITH">

Tags: infrompyimportcomexecutesessionline
1条回答
网友
1楼 · 发布于 2024-10-05 12:26:03

如果您有单个数据中心,则应使用以下查询创建键空间:

CREATE KEYSPACE IF NOT EXISTS kong WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 3 };

'replication_factor' Required if class is SimpleStrategy; otherwise, not used. The number of replicas of data on multiple nodes.

或者,如果您有多个数据中心,则使用:

^{pr2}$

dc1 and dc2 are Data Center name. Required if class is NetworkTopologyStrategy and you provide the name of the data center. This value is the number of replicas of data on each node in that data center.

来源:http://docs.datastax.com/en/cql/3.1/cql/cql_reference/create_keyspace_r.html

相关问题 更多 >

    热门问题