如何使用不同的端口连接到Cassandra节点?

efzxgjgh  于 2023-06-05  发布在  Cassandra
关注(0)|答案(1)|浏览(211)

我正在尝试连接到具有不同端口(9042和9043)的群集节点,但无法在此处找到方法:

cluster = Cluster(['0.0.0.0','0.0.0.0'],port=9042)

我该怎么做?

0sgqnhkj

0sgqnhkj1#

从DataStax的Python驱动程序v3.27开始,Clustercontact_points参数似乎接受IP和端口的元组。
https://github.com/datastax/python-driver/blob/3.27.0/cassandra/cluster.py#L581-L585

class Cluster(object):
    ...

    contact_points = ['127.0.0.1']
    """
    The list of contact points to try connecting for cluster discovery. A
    contact point can be a string (ip or hostname), a tuple (ip/hostname, port) or a
    :class:`.connection.EndPoint` instance.

你能做到

cluster = Cluster(
    contact_points=[
      ('0.0.0.0', 9042),
      ('0.0.0.0', 9043),
    ]
    ...
)

然后将port=参数保留为空。

相关问题