duanfu3634 2015-04-24 11:51
浏览 9
已采纳

Google App Engine-Redislabs Go运行时生产错误-无效的内存地址或nil指针取消引用

I'm using the Redis Cloud service (from Redis Labs) on Google App engine Go Runtime , and I get the above mentioned error when I try getting a key that doesn't exist. The code works fine on the local test server, but panics in production.

 c, err := redis.Dial("tcp", "pub-redis-myredis:<myport>")
_, err = c.Do("AUTH", "password") 
value, err := c.Do("GET", "foo4")

if value == nil {
    log.Infof(contextOfAppEngineWhereServerIsRunning, "value not found in redislabs")

} 

The log shows that the panic is in the line _, err = c.Do("AUTH", "password")

  • 写回答

1条回答 默认 最新

  • dongliu8542 2015-04-24 13:10
    关注

    On AppEngine your application (webapp) runs in a sandboxed environment where you can't use the standard net package for sockets (which I assume redislabs use).

    You have to use the appengine/socket package for outbound network sockets.

    It most likely works locally because the restriction only applies in production environment.

    Always check returned error values. Currently in the code you posted you check none. Should you have checked it, you would see the cause from the error.

    You get invalid memory address or nil pointer dereference error because your first call fails:

    c, err := redis.Dial("tcp", "pub-redis-myredis:<myport>")
    

    err will be a non-nil value and c is nil which means you can't call it's Do() method.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器