예제 #1
0
func apiGetRedisSlotInfo(param martini.Params) (int, string) {
	addr := param["addr"]
	slotId, err := strconv.Atoi(param["id"])
	if err != nil {
		log.ErrorErrorf(err, "parse slotid failed")
		return 500, err.Error()
	}
	slotInfo, err := utils.SlotsInfo(addr, globalEnv.Password(), slotId, slotId)
	if err != nil {
		log.ErrorErrorf(err, "get slot info %d failed", slotId)
		return 500, err.Error()
	}
	out, _ := json.MarshalIndent(map[string]interface{}{
		"keys":    slotInfo[slotId],
		"slot_id": slotId,
	}, " ", "  ")
	return 200, string(out)
}
예제 #2
0
func apiGetRedisSlotInfoFromGroupId(param martini.Params) (int, string) {
	groupId, err := strconv.Atoi(param["group_id"])
	if err != nil {
		log.ErrorErrorf(err, "parse groupid failed")
		return 500, err.Error()
	}
	slotId, err := strconv.Atoi(param["slot_id"])
	if err != nil {
		log.ErrorErrorf(err, "parse slotid failed")
		return 500, err.Error()
	}
	g, err := models.GetGroup(safeZkConn, globalEnv.ProductName(), groupId)
	if err != nil {
		log.ErrorErrorf(err, "get group %d failed", groupId)
		return 500, err.Error()
	}

	s, err := g.Master(safeZkConn)
	if err != nil {
		log.ErrorErrorf(err, "get master of group %d failed", groupId)
		return 500, err.Error()
	}

	if s == nil {
		return 500, "master not found"
	}

	slotInfo, err := utils.SlotsInfo(s.Addr, globalEnv.Password(), slotId, slotId)
	if err != nil {
		log.ErrorErrorf(err, "get slot info %d failed", slotId)
		return 500, err.Error()
	}

	out, _ := json.MarshalIndent(map[string]interface{}{
		"keys":     slotInfo[slotId],
		"slot_id":  slotId,
		"group_id": groupId,
		"addr":     s.Addr,
	}, " ", "  ")
	return 200, string(out)

}