Exemplo n.º 1
0
func channeled() {
	client, err := kinetic.Connect("localhost:8123")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer client.Close()

	count := 10

	data := make([]byte, 64*1024)

	rxs := make([]<-chan error, count)

	for i := 0; i < count; i++ {
		ch := make(chan []byte)
		go repeat(ch, 16, data)
		rxs[i], err = client.PutFrom([]byte("go-big-"+strconv.Itoa(i)), 1024*1024, ch)
		if err != nil {
			fmt.Println(err)
		}
	}

	// wait for all
	for i := 0; i < count; i++ {
		err := <-rxs[i]
		if err != nil {
			fmt.Println(err)
		}
	}
}
Exemplo n.º 2
0
func unlink(name string) {
	client, _ := kinetic.Connect("localhost:8123")
	defer client.Close()

	chanError, _ := client.Delete([]byte(string(name)))
	err := <-chanError
	if err != nil {
		fmt.Println(err)
	}
}
Exemplo n.º 3
0
func create(name string, value string) {
	fmt.Println("create:::", " ", name, " ", value, " ")
	client, _ := kinetic.Connect("localhost:8123")
	defer client.Close()

	chanError, _ := client.Put([]byte(name), []byte(value))
	err := <-chanError
	if err != nil {
		fmt.Println(name, " ", value, " ", err)
	}
}
Exemplo n.º 4
0
func content(name string) (string, error) {
	client, _ := kinetic.Connect("localhost:8123")
	defer client.Close()

	chanValue, chanError, _ := client.Get([]byte(string(name)))
	select {
	case val := <-chanValue:
		// Success
		return string(val), nil
	case err := <-chanError:
		fmt.Println(err)
		return "", err
	}
}
Exemplo n.º 5
0
func listing() [][]byte {
	client, _ := kinetic.Connect("localhost:8123")
	defer client.Close()

	chanValue, chanError, _ := client.GetKeyRange([]byte(string(0)), []byte(string(math.MaxInt32)))
	select {
	case val := <-chanValue:
		// Success
		// for i := 0; i < len(val); i++ {
		// 	fmt.Println(string(val[i]))
		// }
		return val
	case err := <-chanError:
		fmt.Println(err)
		return nil
	}
}
Exemplo n.º 6
0
func regular() {
	client, _ := kinetic.Connect("localhost:8123")
	defer client.Close()

	count := 10

	rxs := make([]<-chan error, count)

	for i := 0; i < count; i++ {
		rxs[i], _ = client.Put([]byte("from-go-"+strconv.Itoa(i)), []byte("refactored 2.0!"))
	}

	// wait for all
	for i := 0; i < count; i++ {
		err := <-rxs[i]
		if err != nil {
			fmt.Println(err)
		}
	}
}