Ejemplo n.º 1
0
func (s *Session) proxyConfigGetByName(name string) []byte {
	var reply []byte
	switch name {
	case "loglevel":
		t := log.GetLogLevel()
		s, _ := log.LogTypeToString(log.LogType(t))
		reply = redis.FormatString(s)
	case "idletime":
		time := s.Proxy.Conf.IdleTime
		reply = redis.FormatInt(int64(time))
	case "maxconn":
		time := s.Proxy.Conf.MaxConn
		reply = redis.FormatInt(int64(time))
	case "slaveok":
		if s.Proxy.Conf.SlaveOk {
			reply = redis.FormatInt(1)
		} else {
			reply = redis.FormatInt(0)
		}
	case "mulparallel":
		parallel := s.Proxy.Conf.MulOpParallel
		reply = redis.FormatInt(int64(parallel))
	case "statsd":
		statsd := s.Proxy.Conf.Statsd
		reply = redis.FormatString(statsd)
	default:
		reply = []byte("-wrong proxy config name\r\n")
	}
	return reply
}
Ejemplo n.º 2
0
func (s *Session) DEL(req *redis.Request) {
	var result int64
	// 串行会很慢,可以考滤开goroutine并行执行
	// 但是这个goroutine量一定要控制,不能有多少key就多少goroutine
	p := make(chan int, s.MulOpParallel)
	for i := 0; i < s.MulOpParallel; i++ {
		p <- 1
	}

	defer func() {
		close(p)
	}()

	keys := req.Args()
	wg := sync.WaitGroup{}
	wg.Add(len(keys))

	for _, key := range keys {
		go func(key string) {
			<-p
			// log.Info("In DEL goroutine ", key)
			cmdslice := []string{"DEL", key}
			r := redis.NewRequest(cmdslice)
			resp := s.Proxy.Backend.OnDEL(r)
			result += resp.Val()
			p <- 1
			wg.Done()
		}(key)
	}

	wg.Wait()
	mergeResp := redis.FormatInt(result)
	// log.Info("DEL merger resp ", mergeResp, result)
	s.write2client(mergeResp)
}