Can't set up AppEngine's Memcache in Go

245 views Asked by At

I've been trying to use AppEngine's Memcache. Note that I'm referring to the one included in AppEngine; I'm trying to avoid MemoryStore because of its costs: having the free alternative in AppEngine, I prefer to try to use that one instead.

enter image description here

Thing is, although I can add values from the web, there's no way I can manage to get some working code in Go.

I first tried following this code, but got error adding item: not an App Engine context.

I read that as Memcache is from the package of appengine and not the Google Cloud ones ("google.golang.org/appengine/memcache" instead of "cloud.google.com/go/xxx"), one has to add this in main: appengine.Main().

With that, the app fails:

panic: Metadata fetch failed for 'instance/attributes/gae_project': Get "http://metadata/computeMetadata/v1/instance/attributes/gae_project": dial tcp: lookup metadata: Temporary failure in name resolution

goroutine 23 [running]:
google.golang.org/appengine/internal.mustGetMetadata(0xc1bda4, 0x1f, 0x0, 0x0, 0xc000329800)
    /home/xxx/go/pkg/mod/google.golang.org/[email protected]/internal/metadata.go:34 +0x148
google.golang.org/appengine/internal.partitionlessAppID(0xc1410e, 0x15)
    /home/xxx/go/pkg/mod/google.golang.org/[email protected]/internal/identity_vm.go:112 +0xa5
google.golang.org/appengine/internal.DefaultTicket.func1()
    /home/xxx/go/pkg/mod/google.golang.org/[email protected]/internal/api.go:297 +0x9c
sync.(*Once).doSlow(0x11634b8, 0xc3ab10)
    /usr/local/go/src/sync/once.go:66 +0xec
sync.(*Once).Do(...)
    /usr/local/go/src/sync/once.go:57
google.golang.org/appengine/internal.DefaultTicket(0xc000486780, 0xabdc60)
    /home/xxx/go/pkg/mod/google.golang.org/[email protected]/internal/api.go:292 +0x65
google.golang.org/appengine/internal.Call(0xce6320, 0xc000486780, 0xc0d10f, 0xa, 0xc082fb, 0x5, 0xce3460, 0xc000329880, 0xce2660, 0xc00046a880, ...)
    /home/xxx/go/pkg/mod/google.golang.org/[email protected]/internal/api.go:499 +0x96a
google.golang.org/appengine/internal.(*context).flushLog(0xc0000bd740, 0xc3c601, 0x0)
    /home/xxx/go/pkg/mod/google.golang.org/[email protected]/internal/api.go:644 +0x48c
google.golang.org/appengine/internal.handleHTTP.func1(0xc000096540, 0xc0000bd740)
    /home/xxx/go/pkg/mod/google.golang.org/[email protected]/internal/api.go:141 +0x58
created by google.golang.org/appengine/internal.handleHTTP
    /home/xxx/go/pkg/mod/google.golang.org/[email protected]/internal/api.go:137 +0x397
exit status 2

Does anyone know I could get this working? Any help would be appreciated. Thanks in advance!

1

There are 1 answers

0
rsalinas On

As mentioned by @Cerise Limón, Memcache can only be used by Go1.11 as it's now considered a legacy service. For runtime 1.12 you need to use Memorystore, and there is no free workaround for this.

This is mentioned also in GCPs documentation:

We recommend using Memorystore for Redis as your caching service. Note that Memorystore for Redis does not provide a free tier. See Memorystore Pricing for details.