Aerospike Golang Multi Host example?

Issue

i want to use golang aerospike with 4 server local , i can connect this using PHP code like this

#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']);

how do i do this using golang ? im using this https://github.com/aerospike/aerospike-client-go
also i read in reference does have NewClientWithPolicyAndHost and NewHosts but cannot find the example or how to use it.

i am using go version go1.17 linux/amd64

Solution

I did manage to get some input, assuming I understood the question right:

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)
}

Answered By – Meher

Answer Checked By – Jay B. (GoLangFix Admin)

Leave a Reply

Your email address will not be published.