Exemplo n.º 1
0
// Specify a factory function to create a connection,
// context and a timeout for connection to be created
func configureMemcache() {
	// For each type in memcache create corresponding pool
	memCtx = context.Background()
	memPoolMap = make(map[string]*pool.ResourcePool)
	memMilliSecTimeout = 5000
	memcacheConfigs, err := config.LoadMemcacheConfig()
	if err != nil {
		os.Exit(1)
	}
	for key, config := range memcacheConfigs {
		factoryFunc := func(key string, config []string) pool.Factory {
			return func() (pool.Resource, error) {
				return memcacheFactory(key, config)
			}
		}
		t := time.Duration(5000 * time.Millisecond)
		memPoolMap[key] = pool.NewResourcePool(factoryFunc(key, config), 10, 100, t)
	}
}
Exemplo n.º 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]*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)
	}
}