在App Engine上,Go语言是否支持Memcache?

huangapple go评论88阅读模式
英文:

Is memcache working in go on appengine?

问题

我有一个应用程序,尝试将小图片(小于50kB)存储在memcache中,但每次调用memcache.Set()都会出现错误memcache: server error
我使用的是共享memcache类,所以我知道没有服务保证,但目前我根本没有服务。
这是创建项目并调用memcache的代码片段。ctx是请求的appengine上下文。memkey是我的键(一个字符串)。img_data是包含数据的字符串。
这段代码在本地开发环境中运行良好。

cache_item = &memcache.Item{
	Key: memkey,
	Value: bytes.NewBufferString(img_data).Bytes(),
}
err = memcache.Set(ctx, cache_item)
if err != nil {
	ctx.Infof("无法将图像存储在memcache中:%s", err)
}
英文:

I have an app that tries to store small images (less than 50kB) in memcache, but each call to memcache.Set() results in an error memcache: server error.
I'm on the shared memcache class, so I understand there is no service guarantee, but currently I have no service at all.
Is it a temporary outage? Am I just unlucky?

Here is the piece of code creating an item and calling memcache. ctx is the appengine context for the request. memkey is my key (a string). img_data is a string with my data.
This code works well in the local dev environment.

cache_item = &memcache.Item{
	Key: memkey,
	Value: bytes.NewBufferString(img_data).Bytes(),
}
err = memcache.Set(ctx, cache_item)
if err != nil {
	ctx.Infof("Could not store image in memcache: %s", err)
}

答案1

得分: 0

如果问题仍然存在,请提交一个错误报告,但我怀疑这只是一个暂时性的问题。

顺便说一下,你的Value初始化器过于复杂了。下面的代码可以达到同样的效果:

cache_item = &memcache.Item{
    Key:   memkey,
    Value: []byte(img_data),
}
英文:

If it's still happening, file a bug, but I suspect it was just a transient problem.

Incidentally, your Value initialiser is unnecessarily complex. This would work the same:

cache_item = &memcache.Item{
    Key:   memkey,
    Value: []byte(img_data),
}

huangapple
  • 本文由 发表于 2013年11月15日 07:24:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/19990531.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定