示例#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
}