package main import ( "fmt" "github.com/aerospike/aerospike-client-go" ) func main() { host := "127.0.0.1" port := 3000 client, err := aerospike.NewClient(host, port) if err != nil { fmt.Printf("Failed to connect to Aerospike cluster: %s\n", err.Error()) return } defer client.Close() fmt.Println("Successfully connected to Aerospike cluster") }
package main import ( "fmt" "github.com/aerospike/aerospike-client-go" ) func main() { host := "127.0.0.1" port := 3000 client, err := aerospike.NewClient(host, port) if err != nil { fmt.Printf("Failed to connect to Aerospike cluster: %s\n", err.Error()) return } defer client.Close() key, err := aerospike.NewKey("test", "myset", "mykey") if err != nil { fmt.Printf("Failed to create key: %s\n", err.Error()) return } bin1 := aerospike.NewBin("name", "John") bin2 := aerospike.NewBin("age", 30) err = client.Put(nil, key, bin1, bin2) if err != nil { fmt.Printf("Failed to write record: %s\n", err.Error()) return } fmt.Println("Record written successfully") }In this example, we use the `Put` method to write a record to the database. We create a new key for the record using the `NewKey` method and specify the namespace, set, and record key. We then create two bins to store data for the record and pass them as arguments to the `Put` method. If the operation is successful, we print a message indicating the record was written successfully. Package library: github.com.aerospike.aerospike-client-go