代码语言:javascript复制
package main
import (
"fmt"
"github.com/garyburd/redigo/redis"
)
func main() {
c, err := redis.Dial("tcp", "localhost:6379")
if err != nil {
fmt.Println("conn redis failed,", err)
return
}
c.Do("set","gin_demo","test_gin", "ex",10*60)
fmt.Println("redis conn success")
//这里必须使用redis.String()
//c.Do("Get","gin_demo") 获取到的是地址空间
redisGets,val := redis.String(c.Do("Get","gin_demo"))
if val == nil {
fmt.Println(redisGets)
}
defer c.Close()
}