Exemplo n.º 1
0
func (s *Session) proxyInfo(req *redis.Request) {
	name := fmt.Sprintf("name:%s", s.Proxy.Conf.Name)
	id := fmt.Sprintf("id:%s", s.Proxy.Conf.Id)
	port := fmt.Sprintf("port:%s", s.Proxy.Conf.Port)
	statsd := fmt.Sprintf("statsd:%s", s.Proxy.Conf.Statsd)
	zk := fmt.Sprintf("zk:%s", s.Proxy.Conf.Zk)
	zkpath := fmt.Sprintf("zkpath:%s", s.Proxy.Conf.ZkPath)
	qps := fmt.Sprintf("qps:%d", s.Proxy.LastQPS)
	conns := fmt.Sprintf("conns:%d", len(s.Proxy.SessMgr))
	nodes := "nodes:"
	r := []string{name, id, port, statsd, zk, zkpath, qps, conns, nodes}
	for _, h := range s.Proxy.Conf.Nodes {
		hs := fmt.Sprintf("%s", h)
		r = append(r, hs)
	}
	reply := redis.FormatStringSlice(r)
	s.write2client(reply)
}
Exemplo n.º 2
0
func (s *Session) proxyBlack(req *redis.Request) {
	args := strings.ToLower(req.Args()[1])
	// log.Warning(req.Args())
	switch args {
	// proxy black remove keyname
	case "remove":
		if len(req.Args()) != 3 {
			err := fmt.Sprintf("-%s\r\n", WrongArgumentCount)
			s.write2client([]byte(err))
			return
		}
		// delete(BlackKeyLists, req.Args()[-1])
		key := req.Args()[2]
		if _, exists := BlackKeyLists[key]; exists {
			log.Warning("remove black key ", key)
			delete(BlackKeyLists, key)
			s.write2client(OK_BYTES)
		} else {
			s.write2client([]byte("-remove key not exists\r\n"))
		}

	case "get":
		if len(req.Args()) != 2 {
			err := fmt.Sprintf("-%s\r\n", WrongArgumentCount)
			s.write2client([]byte(err))
			return
		}
		ks := make([]string, 0)
		for k, _ := range BlackKeyLists {
			ks = append(ks, k)
		}
		d := redis.FormatStringSlice(ks)
		s.write2client(d)
	case "set":
		//proxy black set 3600 keyname1
		if len(req.Args()) != 4 {
			err := fmt.Sprintf("-%s\r\n", WrongArgumentCount)
			s.write2client([]byte(err))
			return
		}
		t, err := strconv.Atoi(req.Args()[3])
		if err != nil {
			log.Warningf("black key: %s time unavailable %s", req.Args()[2], req.Args()[3])
			err := fmt.Sprintf("-%s\r\n", BlackTimeUnavaliable)
			s.write2client([]byte(err))
			return
		}
		if t > 86400 || t < 0 {
			log.Warningf("black key: %s time unavailable %s", req.Args()[2], req.Args()[3])
			s.write2client([]byte("-black time must between 0 ~ 86400\r\n"))
			return
		}
		BlackKeyLists[req.Args()[2]] = &BlackKey{
			Name:     req.Args()[2],
			Startup:  time.Now(),
			Deadline: time.Now().Add(time.Duration(t) * time.Second),
		}
		s.write2client(OK_BYTES)
		return
	default:
		err := fmt.Sprintf("-%s\r\n", UnknowProxyOpType)
		s.write2client([]byte(err))
		return
	}
	return
}