Redigo:尝试连接到池时无效的内存地址或零指针取消引用

Redis 连接.....!恐慌:运行时错误:无效的内存地址或

零指针取消引用[信号0xb代码=0x1 addr=0x28 pc=0x40154b]

goroutine 1 [运行]:runtime.panic(0x52c6e0, 0x6b6348)

/usr/lib/go/src/pkg/运行时/panic.c:266 +0xb6

main.func·001(0xc21005102c, 0x0, 0x4bcd4c, 0x1)

/home/vinay10949/redischeck/redischeck.go:21 +0x10b

github.com/garyburd.(*Preigo/ ).get(0xc210051000, 0x0,

0xc2100378f0, 0x42dbdf, 0x7fbe9c177070) /usr/lib/go/src/pkg/github.com/garyburd/redigo/redis/pool.go:250

+0x3a redis.(*Pool).Get(0xc210051000, 0x1, 0x1) > /usr/lib/go/src/pkg/github.com/garyburd/redigo/redis/pool.go:150

+0x27 main.main() /家/


vinay10949/redischeck/redischeck.go:29 +0x13e


package main


import (

    "flag"

    "fmt"

    "github.com/garyburd/redigo/redis"

    //"reflect"

)


var (

    redisAddress   = flag.String("10.12.2.121", "10.12.2.121:6379", "Address to the Redis server")

    maxConnections = flag.Int("max-connections", 10, "Max connections to Redis")

)


func main() {


    //Redis Connection

    redisPool := redis.NewPool(func() (redis.Conn, error) {


        con, err := redis.Dial("tcp", *redisAddress)

        con.Do("SELECT", 1)

        if err != nil {

            return nil, err

        }

        return con, err

    }, *maxConnections)


    fmt.Println("Redis Connecting...!")

    con := redisPool.Get()

    status, errStatus := con.Do("SET", "Name", "BookMyShow")

    if errStatus != nil {

        fmt.Println(errStatus)

    } else {

        fmt.Println("Redis Connected")

    }

    statusInsertion, _ := redis.String(status, errStatus)

    fmt.Println("Status of Insertion :" + statusInsertion)

    value, _ := redis.String(con.Do("GET", "Name"))

    fmt.Println("Value Retrieved : " + value)

}


千巷猫影
浏览 221回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go