```
var Rd *redis.Client
func init() {
rd()
fmt.Println(Rd)
}
func rd() {
var (
err error
pass, host string
)
sec, err := conf.Cfg.GetSection("redis")
if err != nil {
log.Fatal(2, "Fail to get section 'redis':%v", err)
}
host = sec.Key("HOST").MustString("127.0.0.1:6379")
pass = sec.Key("PASSWORD").MustString("")
Rd := redis.NewClient(&redis.Options{
Addr: host,
Password: pass,
})
_, err = Rd.Ping().Result()
fmt.Printf("%s %s\n", redisLogIH, "ping redis")
if err != nil {
log.Printf("%s %s\n", redisLogWH, err)
} else {
log.Printf("%s %s\n", redisLogIH, "redis's connecting is ok")
}
//此处redis成功存储
err = Rd.Set("a333a", "12123", 0).Err()
}
```
### init 位置打印出来是空指针
```
nil
```
### 麻烦大家给我指点下,谢谢
有疑问加站长微信联系(非本文作者)