func RedisPool(host string) (pool *redis.Pool) { var ok bool if pool, ok = pools[host]; !ok { mu.Lock() defer mu.Unlock() if pool, ok = pools[host]; !ok { pool = &redis.Pool{ MaxIdle: 100, IdleTimeout: 240 * time.Second, Dial: func() (redis.Conn, error) { return redis.Dial("tcp", host) }, } pools[host] = pool } } return }
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 }