示例#1
0
func setupRedisConnection() {
	log.Printf("connecting to redis...")
	redisConn, redisError = redis.NewSynchClientWithSpec(redisSpec)
	if redisError != nil {
		log.Fatal("couldn't connect to redis: ", redisError)
	}
	log.Printf("connected to redis.")
}
示例#2
0
func init() {
	db, _ := beego.AppConfig.Int("ipdb")
	port, _ := beego.AppConfig.Int("ipport")
	spec := redis.DefaultSpec().Host(beego.AppConfig.String("iphost")).Port(port).Db(db).Password(beego.AppConfig.String("ippassword"))
	c, err := redis.NewSynchClientWithSpec(spec)
	//随机取IP
	if err != nil {
		println("数据库连接失败")
	} else {
		client = c
	}
}
func TestAlphazeroRedisConnect(t *testing.T) {
	var err error

	alphazeroRedisClient, err = redis.NewSynchClientWithSpec(redis.DefaultSpec())

	if err != nil {
		t.Fatalf("Connect failed: %v", err)
	}

	err = alphazeroRedisClient.Ping()

	if err != nil {
		t.Fatalf("Command failed: %v", err)
	}

}
示例#4
0
func GetRedisClient() (redis.Client, error) {
	redis_pass, e := GetConfValue("redis.password")
	if e != nil {
		return nil, e
	}
	redis_db, e := GetConfValue("redis.dbnumber")
	if e != nil {
		return nil, e
	}

	redis_ndb, _ := strconv.ParseInt(redis_db, 10, 32)
	spec := redis.DefaultSpec().Db(int(redis_ndb)).Password(redis_pass)
	client, e := redis.NewSynchClientWithSpec(spec)
	if e != nil {
		return nil, errors.New("Failed to create redis client, wrong password ?")
	}
	return client, nil
}
示例#5
0
文件: main.go 项目: em3301/domainpark
func redisConnect() (rd redis.Client, err error) {
	spec := redis.DefaultSpec().Db(AppConfig.redisDb)
	if AppConfig.redisHost != "" {
		spec.Host(AppConfig.redisHost)
	}
	if AppConfig.redisAuth != "" {
		spec.Password(AppConfig.redisAuth)
	}
	port := AppConfig.redisPort
	if port > 0 && port < 65535 {
		spec.Port(port)
	}

	rd, err = redis.NewSynchClientWithSpec(spec)
	if err != nil {
		fmt.Printf("Connect Redis: %s", err)
		return rd, err
	}

	return rd, nil
}
func NewPipelineRedis(host string, port int, db int, passwd string) *PipelineRedis {
	spec := redis.DefaultSpec().Host(host).Port(port).Db(db).Password(passwd)
	client, _ := redis.NewSynchClientWithSpec(spec)
	return &PipelineRedis{client: client}
}