Last active
May 11, 2016 18:57
-
-
Save javjar/3568ee63befb57c832fe6b665d54d172 to your computer and use it in GitHub Desktop.
Golang ScanAll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
as "github.com/aerospike/aerospike-client-go" | |
"github.com/k0kubun/pp" | |
) | |
func main() { | |
fmt.Println("Connecting...") | |
client, err := as.NewClient("1.2.3.4", 3000) | |
if err != nil { | |
log.Fatalf("Error creating aerospike client: %+v\n", err) | |
} | |
if !client.IsConnected() { | |
log.Fatalf("Error, not connected to database: %+v\n", err) | |
} | |
defer client.Close() | |
fmt.Println("Scanning...") | |
policy := as.NewScanPolicy() | |
policy.Timeout = 60000 | |
championSet, err := client.ScanAll(policy, "test", "demo") | |
if err != nil { | |
log.Fatalf("Error scanning records: %+v\n", err) | |
} | |
fmt.Println("Printing...") | |
for res := range championSet.Results() { | |
fmt.Println("for") | |
if res.Err != nil { | |
fmt.Println("if.") | |
log.Fatalf("Error processing results: %+v\n", res.Err.Error()) | |
} else { | |
fmt.Println("else") | |
pp.Printf("%+v\n", res.Record.Key.String()) | |
pp.Printf("%+v\n", res.Record.Bins) | |
} | |
} | |
fmt.Println("done.") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment