Exemple #1
0
func NewRedisBackend(dns, prefix string, persistent bool) (Storage, error) {
	db, err := kvstore.Open(dns)

	if err != nil {
		return nil, err
	}

	conn := db.Get()
	_, err = conn.Do("Ping")
	conn.Close()

	if err != nil {
		return nil, err
	}

	return &redisBackend{
		prefix:     prefix,
		db:         db,
		lifetime:   DefaultLifetime,
		persistent: persistent,
	}, nil
}
Exemple #2
0
func main() {
	flag.Parse()

	if *help {
		flag.Usage()
		os.Exit(1)
	}

	runtime.GOMAXPROCS(runtime.NumCPU())

	if _, err := toml.DecodeFile(*configFilename, &config); err != nil {
		log.Fatal(err)
	}

	if config.Laddr == "" {
		config.Laddr = *laddr
	}

	for k, v := range config.Regions {
		v.Codename = k
		store, err := kvstore.Open(v.RedisDSN)

		if err != nil {
			log.Fatal(err)
		}

		conn := store.Get()
		_, err = conn.Do("Ping")
		conn.Close()

		if err != nil {
			log.Fatalf("region %s: %v", k, err)
		}

		v.Backend = NewRedisBackend(store, v.Codename)
	}

	runServer()
}