Esempio n. 1
0
func Flush() string {
	GetConnectionFromKey("Flush")
	iType := protos.Type(protos.Type_value["Flush"])
	command := &protos.Command{
		Type: &iType,
	}
	commandBytes, _ := proto.Marshal(command)
	conn.Write(commandBytes)
	//Create a data buffer of type byte slice with capacity of 4096
	data := make([]byte, 4096)
	n, _ := conn.Read(data)
	response := new(protos.Response)
	proto.Unmarshal(data[0:n], response)
	//fmt.Println("receive response:  "+response.String())
	return response.String()
}
Esempio n. 2
0
func Add(key string, value string) string {
	GetConnectionFromKey(key)
	iType := protos.Type(protos.Type_value["Add"])
	command := &protos.Command{
		Type:  &iType,
		Key:   &key,
		Value: &value,
	}
	commandBytes, _ := proto.Marshal(command)
	conn.Write(commandBytes)
	//Create a data buffer of type byte slice with capacity of 4096
	data := make([]byte, 4096)
	//Read the data waiting on the connection and put it in the data buffer
	n, _ := conn.Read(data)
	response := new(protos.Response)
	proto.Unmarshal(data[0:n], response)
	//fmt.Println("receive response:  "+response.String())
	return response.String()
}