예제 #1
0
파일: main.go 프로젝트: nyxtom/broadcast
func main() {
	flag.Parse()

	if *number <= 0 {
		panic("invalid number")
		return
	}

	if *clients <= 0 || *number < *clients {
		panic("invalid client number")
		return
	}

	loop = *number / *clients
	client, _ = broadcast.NewClient(*port, *ip, 1, *bprotocol)
	benchSet()
	benchPing()
	benchGet()
	benchDel()
	benchIncr()
	benchDecr()
	benchCount()
	benchSetNx()
	benchSAdd()
	benchSRem()
	benchSCard()
	benchSDiff()
	benchSIsMember()
}
예제 #2
0
func main() {
	flag.Parse()

	if *number <= 0 {
		panic("invalid number")
		return
	}

	if *clients <= 0 || *number < *clients {
		panic("invalid client number")
		return
	}

	loop = *number / *clients
	client, _ = broadcast.NewClient(*port, *ip, 1, *bprotocol)
	benchSetDEdge()
	benchIncrDEdge()
	benchDecrDEdge()
	benchSetEdge()
	benchIncrEdge()
	benchDecrEdge()
	benchSetVertex()
	benchIncrVertex()
	benchDecrVertex()
}
예제 #3
0
func (server *WebServer) exec(w http.ResponseWriter, req *http.Request) {
	values := req.URL.Query()
	response := make(map[string]interface{})
	if len(values["cmd"]) > 0 {
		c, err := broadcast.NewClient(server.bport, server.bip, 1, server.bprotocol)
		if err != nil {
			server.LogErr(err)
			return
		}
		reg, _ := regexp.Compile(`'.*?'|".*?"|\S+`)
		cmds := reg.FindAllString(values["cmd"][0], -1)
		if len(cmds) > 0 {
			args := make([]interface{}, len(cmds[1:]))
			for i := range args {
				item := strings.Trim(string(cmds[1+i]), "\"'")
				if a, err := strconv.Atoi(item); err == nil {
					args[i] = a
				} else if a, err := strconv.ParseFloat(item, 64); err == nil {
					args[i] = a
				} else if a, err := strconv.ParseBool(item); err == nil {
					args[i] = a
				} else if len(item) == 1 {
					b := []byte(item)
					args[i] = string(b[0])
				} else {
					args[i] = item
				}
			}
			cmd := strings.ToUpper(cmds[0])
			reply, err := c.Do(cmd, args...)
			if err != nil {
				server.LogErr(err)
			} else {
				response["cmd"] = cmd
				response["args"] = args
				response["reply"] = printReply(cmd, reply, "")
			}
		}
	}

	js, err := json.Marshal(response)
	if err != nil {
		server.LogErr(err)
		return
	}
	w.Header().Set("Content-Type", "application/json")
	w.Write(js)
}
예제 #4
0
파일: main.go 프로젝트: supertigim/webterm
func main() {
	var ip = flag.String("h", "127.0.0.1", "webterm server ip (default 127.0.0.1)")
	var port = flag.Int("p", 7337, "webterm server port (default 7331)")
	var bprotocol = flag.String("bprotocol", "redis", "broadcast server protocol to follow")
	var maxIdle = flag.Int("i", 1, "max idle client connections to pool from")

	flag.Parse()

	addr := *ip + ":" + strconv.Itoa(*port)
	c, err := broadcast.NewClient(*port, *ip, *maxIdle, *bprotocol)
	if err != nil {
		fmt.Printf(err.Error())
		os.Exit(1)
	}

	reply, err := c.Do("cmds")
	if err != nil {
		fmt.Printf("%s", err.Error())
	} else {
		printReply("cmds", reply, "")
	}

	SetCompletionHandler(completionHandler)
	setHistoryCapacity(100)

	reg, _ := regexp.Compile(`'.*?'|".*?"|\S+`)
	prompt := ""

	for {
		prompt = fmt.Sprintf("%s> ", addr)

		cmd, err := line(prompt)
		if err != nil {
			fmt.Printf("%s\n", err.Error())
			return
		}

		cmds := reg.FindAllString(cmd, -1)
		if len(cmds) == 0 {
			continue
		} else {
			addHistory(cmd)

			args := make([]interface{}, len(cmds[1:]))
			for i := range args {
				item := strings.Trim(string(cmds[1+i]), "\"'")
				if a, err := strconv.Atoi(item); err == nil {
					args[i] = a
				} else if a, err := strconv.ParseFloat(item, 64); err == nil {
					args[i] = a
				} else if a, err := strconv.ParseBool(item); err == nil {
					args[i] = a
				} else if len(item) == 1 {
					b := []byte(item)
					args[i] = string(b[0])
				} else {
					args[i] = item
				}
			}

			cmd := strings.ToUpper(cmds[0])
			if strings.ToLower(cmd) == "help" || cmd == "?" {
				printHelp(cmds)
			} else if cmd == "CMDS" {
				printCmds()
			} else {
				async := isCmdAsync(cmd)
				if async {
					c.DoAsync(cmd, args...)
				} else {
					reply, err := c.Do(cmd, args...)
					if err != nil {
						fmt.Printf("%s", err.Error())
					} else {
						printReply(cmd, reply, "")
					}
				}
				fmt.Printf("\n")
			}
		}
	}
}