예제 #1
0
func main() {
	rand.Seed(time.Now().UnixNano())

	//host := ":6379"
	host := ":17600"

	chanCount := 50
	countPerThread := 2000000 * 10
	clients := make([]redis.Conn, chanCount)
	ch := make(chan int, chanCount)
	for i := 0; i < chanCount; i++ {
		var err error
		clients[i], err = redis.Dial("tcp", host)
		if err != nil {
			panic(err)
		}
	}
	fmt.Println("start...")
	t1 := time.Now()
	for i := 0; i < chanCount; i++ {
		go thread(clients[i], countPerThread, ch)
	}
	for i := 0; i < chanCount; i++ {
		<-ch
	}
	elapsed := time.Now().Sub(t1)
	qps := float64(chanCount*countPerThread) / elapsed.Seconds()
	fmt.Println("count:", chanCount*countPerThread, "elapsed:", elapsed, "qps:", qps)
}
예제 #2
0
파일: allkeys.go 프로젝트: ming-hai/GoRedis
func allkeys() {
	conn, err := redis.Dial("tcp", "goredis-profile-c001:17600")
	if err != nil {
		panic(err)
	}
	lastkey := ""
	lasttype := ""
	idx := 1
	for {
		reply, _ := conn.Do("key_next", lastkey, 24)
		if reply == nil {
			break
		}
		lst := reply.([]interface{})
		count := len(lst)
		for i := 0; i < count; i += 2 {
			lastkey = string(lst[i].([]byte))
			lasttype = string(lst[i+1].([]byte))
			fmt.Println(idx, lastkey, lasttype)
			idx++
		}
		if count == 0 {
			break
		}
	}
}
예제 #3
0
func (s *StatClient) initRedisPool() {
	s.pool = &redis.Pool{
		MaxIdle:     10,
		IdleTimeout: 240 * time.Second,
		Dial: func() (redis.Conn, error) {
			c, err := redis.Dial("tcp", s.host)
			return c, err
		},
	}
}
예제 #4
0
파일: util.go 프로젝트: WaylandGod/GoRedis
func RedisPool(host string) (pool *redis.Pool) {
	pool = &redis.Pool{
		MaxIdle:     100,
		IdleTimeout: 240 * time.Second,
		Dial: func() (redis.Conn, error) {
			c, err := redis.Dial("tcp", host)
			return c, err
		},
	}
	return
}
예제 #5
0
func (s *Shard) init() (err error) {
	s.pools = make([]*redis.Pool, s.Count)
	for i := 0; i < s.Count; i++ {
		func(idx int) {
			s.pools[idx] = &redis.Pool{
				MaxIdle:     100,
				IdleTimeout: 240 * time.Second,
				Dial: func() (redis.Conn, error) {
					host := strings.Replace(s.Host, "{0}", strconv.Itoa(idx), -1)
					addr := fmt.Sprintf("%s:%d", host, s.Port+idx)
					return redis.Dial("tcp", addr)
				},
			}
		}(i)
	}
	return
}
예제 #6
0
func GetRedisPool(host string) (pool *redis.Pool) {
	mu.Lock()
	defer mu.Unlock()
	var exist bool
	pool, exist = pools[host]
	if !exist {
		pool = &redis.Pool{
			MaxIdle:     100,
			IdleTimeout: 240 * time.Second,
			Dial: func() (redis.Conn, error) {
				c, err := redis.Dial("tcp", host)
				return c, err
			},
		}
		pools[host] = pool
	}
	return
}
예제 #7
0
파일: util.go 프로젝트: WaylandGod/GoRedis
func NewRedisConn(host string) (redis.Conn, error) {
	return redis.Dial("tcp", host)
}