Exemple #1
0
func TestClient() {
	time.Sleep(1000 * time.Millisecond)
	conn, err := net.Dial("tcp", "localhost:7777")
	if err != nil {
		fmt.Println(err)
	}
	conn.Write([]byte(command.EncodeRedisProtocol(command.DecodeText("set clive handsome"))))
	response, _ := bufio.NewReader(conn).ReadString('\n')
	fmt.Println("receive response:  " + response)
	conn.Write([]byte(command.EncodeRedisProtocol(command.DecodeText(("get clive")))))
	response, _ = bufio.NewReader(conn).ReadString('\n')
	fmt.Println("receive response:  " + response)

}
Exemple #2
0
func main() {
	Init()
	hostname, _ = os.Hostname()
	servers = make(map[string]string)
	servers["clive"] = ip
	//	servers["clive0"]="7.7.7.7"
	//	servers["clive1"]="7.7.7.8"
	//	servers["clive2"]="7.7.7.9"
	for k, _ := range servers {
		c.Add(k)
	}
	fmt.Println(flag.Args())
	if flag.Args()[1] == "server" {
		if flag.Args()[0] == "start" {
			StartServer()

		} else if flag.Args()[0] == "stop" {
			//quit <- 0
		}
	}
	if flag.Args()[1] == "client" {
		fmt.Print("life is short, i use go -.-\n>")
		conn, _ := net.Dial("tcp", server)
		for {
			line, _, _ := bufio.NewReader(os.Stdin).ReadLine()
			conn.Write([]byte(command.EncodeRedisProtocol(command.DecodeText(string(line)))))
			response, _ := bufio.NewReader(conn).ReadBytes('\n')
			fmt.Println(response)
			fmt.Print(">")
		}
	}
	//client.TestClient()
	//load Graph, why so slow
	if flag.Args()[1] == "loadGraph" {
		time.Sleep(100 * time.Millisecond)
		fmt.Println("loadGraph start: " + time.Now().Format("2006-01-02 15:04:05"))
		client.LoadWebGraph()
		fmt.Println("loadGraph end: " + time.Now().Format("2006-01-02 15:04:05"))
	}
	if flag.Args()[1] == "pageRank" {
		fmt.Println("pagerank start: " + time.Now().Format("2006-01-02 15:04:05"))
		client.PageRank()
		fmt.Println("pagerank end: " + time.Now().Format("2006-01-02 15:04:05"))
		time.Sleep(1000 * time.Second)
	}
}