예제 #1
0
파일: redismq.go 프로젝트: tsuru/tsuru
func (factory *redisPubSubFactory) getConn() (tsuruRedis.PubSubClient, error) {
	factory.Lock()
	defer factory.Unlock()
	if factory.pool != nil {
		return factory.pool, nil
	}
	factory.config = &tsuruRedis.CommonConfig{
		PoolSize:     1000,
		PoolTimeout:  2 * time.Second,
		IdleTimeout:  2 * time.Minute,
		MaxRetries:   1,
		DialTimeout:  100 * time.Millisecond,
		ReadTimeout:  30 * time.Minute,
		WriteTimeout: 500 * time.Millisecond,
		TryLegacy:    true,
	}
	client, err := tsuruRedis.NewRedisDefaultConfig("pubsub", factory.config)
	if err == tsuruRedis.ErrNoRedisConfig {
		factory.config.TryLocal = true
		client, err = tsuruRedis.NewRedisDefaultConfig("redis-queue", factory.config)
	}
	if err != nil {
		return nil, err
	}
	var ok bool
	factory.pool, ok = client.(tsuruRedis.PubSubClient)
	if !ok {
		return nil, errors.Errorf("redis client is not a capable of pubsub: %#v", client)
	}
	return factory.pool, nil
}
예제 #2
0
파일: router.go 프로젝트: tsuru/tsuru
func (r *hipacheRouter) connect() (tsuruRedis.Client, error) {
	redisClientsMut.RLock()
	client := redisClients[r.prefix]
	if client == nil {
		redisClientsMut.RUnlock()
		redisClientsMut.Lock()
		defer redisClientsMut.Unlock()
		client = redisClients[r.prefix]
		if client == nil {
			var err error
			client, err = tsuruRedis.NewRedisDefaultConfig(r.prefix, &tsuruRedis.CommonConfig{
				PoolSize:     1000,
				PoolTimeout:  2 * time.Second,
				IdleTimeout:  2 * time.Minute,
				MaxRetries:   1,
				DialTimeout:  time.Second,
				ReadTimeout:  2 * time.Second,
				WriteTimeout: 2 * time.Second,
				TryLocal:     true,
			})
			if err != nil {
				return nil, err
			}
			redisClients[r.prefix] = client
		}
	} else {
		redisClientsMut.RUnlock()
	}
	return client, nil
}