0

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")

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117
Karthic Rao
  • 3,624
  • 8
  • 30
  • 44

1 Answers1

1

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.

icza
  • 389,944
  • 63
  • 907
  • 827
  • Yes , you are right .. Its the restriction by app engine to not to allow outgoing socket calls by standard net package – Karthic Rao Apr 24 '15 at 13:18