登录
首页 >  Golang >  Go问答

示例: 在 Golang 中使用 Aerospike 的多主机配置

来源:stackoverflow

时间:2024-03-18 12:51:30 112浏览 收藏

在 Golang 中配置 Aerospike 多主机连接,您可以使用 `NewClientWithPolicyAndHost` 函数。它接受一个客户端策略和一系列主机地址和端口作为参数。这将创建一个连接到指定主机的 Aerospike 客户端。例如,您可以这样配置四个本地服务器: ```go client, err := aero.NewClientWithPolicyAndHost( aero.NewClientPolicy(), aero.NewHost("192.168.7.241", 3000), aero.NewHost("192.168.7.243", 3000), aero.NewHost("192.168.7.244", 3000), aero.NewHost("192.168.7.245", 3000), ) ```

问题内容

我想使用 golang aerospike 与 4 个本地服务器,我可以使用这样的 php 代码连接它

#CONFIG FOR AEROSPIKE CONNECTION
    $CONF['aerospike_server'] = array(
        'hosts' => array(
            array(
                'addr' => '192.168.7.241',
                'port' => 3000
            ),
            array(
                'addr' => '192.168.7.243',
                'port' => 3000
            ),
            array(
                'addr' => '192.168.7.244',
                'port' => 3000
            ),
            array(
                'addr' => '192.168.7.245',
                'port' => 3000
            )
        )
    );


$aeroDB = new Aerospike($CONF['aerospike_server']);

我如何使用 golang 来做到这一点?我使用这个https://github.com/aerospike/aerospike-client-go 我还在参考文献中读到确实有 newclientwithpolicyandhost 和 newhosts 但找不到示例或如何使用它。

我使用的是go版本go1.17 linux/amd64


正确答案


假设我正确理解了问题,我确实设法获得了一些意见:

client, err := aero.NewClientWithPolicyAndHost(aero.NewClientPolicy(), aero.NewHost(ip1, port1), aero.NewHost(ip2, port2), aero.NewHost(ip3, port3), aero.NewHost(ip4, port4))
if err != nil {
    log.Fatal(err)
}

以上就是《示例: 在 Golang 中使用 Aerospike 的多主机配置》的详细内容,更多关于的资料请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>