redigo http://github.com/garyburd/redigo/redis
go redis client的一个库
如下代码:
package main
import(
"fmt"
"github.com/garyburd/redigo/redis"
)
func main(){
c, err := redis.Dial("tcp", ":6379")
c.Do("SET", "foo", "bar")
v, err := c.Do("GET", "foo")
if err != nil{
fmt.Println(err)
} else {
fmt.Println(v)
}
}
运行下,出错:
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x28 pc=0x2174]
goroutine 1 [running]:
main.main()
/Users/jay/mygo/src/golearn/rd2.go:9 +0x174
goroutine 2 [syscall]:
exit status 2
why? thanks
看错误提示就知道了,这一句:`c, err := redis.Dial("tcp", ":6379")`,你不能忽略 err 不处理。
应该是连redis没连成功。
#1
更多评论