Пример #1
0
// Specify a factory function to create a connection,
// context and a timeout for connection to be created
func configureRedis() {
	// For each type in redis create corresponding pool
	redisCtx = context.Background()
	redisPoolMap = make(map[string]*pool.ResourcePool)
	milliSecTimeout = 5000
	redisConfigs, err := config.LoadRedisConfig()
	if err != nil {
		os.Exit(1)
	}
	for key, config := range redisConfigs {
		factoryFunc := func(key string, config map[string]string) pool.Factory {
			return func() (pool.Resource, error) {
				return redisFactory(key, config)
			}
		}
		t := time.Duration(time.Duration(milliSecTimeout) * time.Millisecond)
		redisPoolMap[key] = pool.NewResourcePool(factoryFunc(key, config), 10, 100, t)
	}
}
Пример #2
0
// Specify a factory function to create a connection,
// context and a timeout for connection to be created
func configureRedis() {
	// For each type in redis create corresponding pool
	redisCtx = context.Background()
	redisPoolMap = make(map[string]*redis.Pool)
	milliSecTimeout = 1000
	redisConfigs, err := config.LoadRedisConfig()
	if err != nil {
		os.Exit(1)
	}
	for key, config := range redisConfigs {
		/*	factoryFunc := func(key string, config map[string]string) pool.Factory {
				return func() (pool.Resource, error) {
					return redisFactory(key, config)
				}
			}
			t := time.Duration(time.Duration(milliSecTimeout) * time.Millisecond)
			redisPoolMap[key] = pool.NewResourcePool(factoryFunc(key, config), 10, 50, t)
		*/
		factoryFunc := func(key string, config map[string]string) func() (redis.Conn, error) {
			return func() (redis.Conn, error) {
				return redisFactory(key, config)
			}
		}

		redisPoolMap[key] = &redis.Pool{
			MaxIdle:   20,
			MaxActive: 40, // max number of connections
			Dial:      factoryFunc(key, config),
			TestOnBorrow: func(c redis.Conn, t time.Time) error {
				_, err := c.Do("PING")
				return err
			},
		}

	}
}