package main import ( "github.com/aerospike/aerospike-client-go" "log" ) func main() { // Create a new Aerospike client client, err := aerospike.NewClient("localhost", 3000) if err != nil { log.Fatal("Error connecting to Aerospike cluster: ", err) } // Fetch a record from Aerospike DB using primary key "mykey" key, _ := aerospike.NewKey("test", "myset", "mykey") rec, err := client.Get(nil, key) if err != nil { log.Fatal("Error fetching record: ", err) } // Print the record log.Println(rec.Bins) }
package main import ( "fmt" "github.com/aerospike/aerospike-client-go" ) func main() { // database configuration cfg := aerospike.NewClientPolicy() cfg.Timeout = 5 * time.Second cfg.MaxCommandAction = 80 // connect to the database clnt, err := aerospike.NewClientWithPolicy(cfg, "localhost", 3000) if err != nil { fmt.Println(err.Error()) } // lookup a user record by ID key, err := aerospike.NewKey("test", "users", 12345) if err != nil { fmt.Println(err.Error()) } record, err := clnt.Get(nil, key) if err != nil { fmt.Println(err.Error()) } else { // print the user record fmt.Printf("%+v\n", record) } }This code snippet configures a client policy for the Aerospike client, which includes a timeout of 5 seconds and a maximum number of command actions of 80. It then connects to the Aerospike database running on localhost:3000. Finally, it fetches a record with key 12345 from the test namespace and users set. If successful, it prints the record to the console.