Example #1
0
func main() {
	var client *redis.Client

	client = redis.New()
	client.Connect("localhost", 6379)

	s, _ := client.Ping()
	fmt.Println(s)
	client.Incr("hello")
	s, _ = client.Get("hello")
	fmt.Println(s)
	client.Quit()
}
Example #2
0
File: gsm.go Project: Wuyue/Gsm
//初始化redis连接
//传入配置参数
func Init(config ...*Config) {
	config = checkConfig(config)

	for i := 0; i < len(config); i++ {
		var client *redis.Client
		client = redis.New()
		err1 := client.Connect(config[i].Host, config[i].Port)
		log.Println(config[i].Host+":"+strconv.Itoa(int(config[i].Port)), "Connect ...")
		_, err2 := client.Ping()

		if err1 != nil || err2 != nil {
			log.Println("ERROR: Redis Connect failed!")
			os.Exit(0)
		}
		redisSlice = append(redisSlice, client)
		for j := 0; j < len(config[i].Data); j++ {
			structRedis[config[i].Data[j]] = client
		}
	}
}