コード例 #1
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	// defer client.Close()
	clientPolicy := as.NewClientPolicy()
	clientPolicy.ConnectionQueueSize = 100
	clientPolicy.Timeout = 50 * time.Millisecond
	client, err = as.NewClient("172.31.53.227", 3000)
	panicOnError(err)

	writePolicy = as.NewWritePolicy(0, 0)
	ch = make(chan Event, 1000)
	key, err := as.NewKey("test", "totals", "total_votes")
	panicOnError(err)
	// define some bins with data
	bins := as.BinMap{
		"total_votes": 0,
	}
	err = client.Put(nil, key, bins)
	panicOnError(err)

	time.AfterFunc(1*time.Second, func() {
		for i := 1; i < 72; i++ {
			fmt.Println("starting worker %d", i)
			go worker(ch)
		}
	})

	http.HandleFunc("/vote", voteHandler)
	http.HandleFunc("/loaderio-35df9c4fffde902e3b0e3e0115816d82.html", validationHandler)
	http.ListenAndServe(":80", nil)
}
コード例 #2
0
ファイル: asinfo.go プロジェクト: Kavec/aerospike-client-go
func main() {
	flag.Parse()
	log.SetOutput(os.Stdout)
	log.SetFlags(0)

	clientPolicy = as.NewClientPolicy()
	if *user != "" {
		clientPolicy.User = *user
		clientPolicy.Password = *password
	}

	// connect to the host
	if client, err := as.NewClientWithPolicy(clientPolicy, *host, *port); err != nil {
		log.Fatalln(err.Error())
	} else {
		node := client.GetNodes()[0]
		if conn, err := node.GetConnection(time.Second); err != nil {
			log.Fatalln(err.Error())
		} else {
			if infoMap, err := as.RequestInfo(conn, strings.Trim(*value, " ")); err != nil {
				node.InvalidateConnection(conn)
				log.Fatalln(err.Error())
			} else {
				node.PutConnection(conn)
				cnt := 1
				for k, v := range infoMap {
					log.Printf("%d :  %s\n     %s\n\n", cnt, k, v)
					cnt++
				}
			}
		}
	}
}
コード例 #3
0
ファイル: asinfo.go プロジェクト: shatil/aerospike-client-go
func main() {
	flag.Parse()
	log.SetOutput(os.Stdout)
	log.SetFlags(0)

	clientPolicy = as.NewClientPolicy()
	if *user != "" {
		clientPolicy.User = *user
		clientPolicy.Password = *password
	}
	*value = strings.Trim(*value, " ")

	// connect to the host
	client, err := as.NewClientWithPolicy(clientPolicy, *host, *port)
	dieIfError(err)

	node := client.GetNodes()[0]
	conn, err := node.GetConnection(time.Second)
	dieIfError(err)

	infoMap, err := as.RequestInfo(conn, *value)
	dieIfError(err, func() {
		node.InvalidateConnection(conn)
	})

	node.PutConnection(conn)

	if len(infoMap) == 0 {
		log.Printf("Query successful, no information for -v \"%s\"\n\n", *value)
		return
	}

	outfmt := "%d :  %s\n     %s\n"
	cnt := 1
	for k, v := range infoMap {
		log.Printf(outfmt, cnt, k, v)
		cnt++
	}
}
コード例 #4
0
func NewAeroSpikeClient(cfg *Config) (*AeroSpikeClient, error) {

	clientPolicy := aerospike.NewClientPolicy()
	clientPolicy.ConnectionQueueSize = ConnectionQueueSize
	clientPolicy.LimitConnectionsToQueueSize = true
	clientPolicy.Timeout = 50 * time.Millisecond

	hosts := []*aerospike.Host{}
	for _, connStr := range cfg.AeroHostsPots {
		hostStr, portStr, err := net.SplitHostPort(connStr)
		if err != nil {
			return nil, err
		}
		port, err := strconv.Atoi(portStr)
		if err != nil {
			return nil, err
		}
		hosts = append(hosts, aerospike.NewHost(hostStr, port))
	}

	client, err := aerospike.NewClientWithPolicyAndHost(clientPolicy, hosts...)
	if err != nil {
		return nil, err
	}

	getPolicy := aerospike.NewPolicy()
	getPolicy.Timeout = time.Millisecond * 50
	getPolicy.MaxRetries = maxRetries

	out := &AeroSpikeClient{
		namespace: cfg.AeroNamespace,
		prefix:    cfg.AeroPrefix,
		getPolicy: getPolicy,
		client:    client,
	}

	return out, nil
}