我可以在 Google-AppEngine in Python 的 Memcache 中保存列表吗?
Can I save a list in Memcache in Google-AppEngine in Python?
我想使用 Python 在 AppEngine 的 MemCache 中保存一个列表,但我遇到了下一个错误:
TypeError: new() 正好需要 4 个参数(给定 1 个)。
这是有错误的图像的 link:
http://i.stack.imgur.com/we3VU.png
这是我的代码:
def get_r_post_relation(self, url, update = False) :
sufix = "r"
key = sufix + url
list_version = memcache.get(key)
if not list_version or update :
logging.error("LIST VERSION QUERY")
postobj = get_wiki_post(url)
list_version = WikiPostVersion.query().filter(WikiPostVersion.r_post == postobj.key)
memcache.set(key, list_version)
return list_version
您没有存储列表。您正在存储查询对象。要存储列表,请使用 .fetch()
:
list_version = WikiPostVersion.query().filter(WikiPostVersion.r_post == postobj.key).fetch()
您可以存储一个简单的查询对象,但是当您添加 .order()
或 .filter()
时,您会收到 pickling 错误。切换到列表,一切就绪。
请记住,查询对象中没有任何实体。它只是一组指令,用于在稍后与 .get()
或 .fetch()
一起使用时检索实体。因此,当您打算存储实际实体列表时,您正试图存储一个 python 命令集。
我想使用 Python 在 AppEngine 的 MemCache 中保存一个列表,但我遇到了下一个错误:
TypeError: new() 正好需要 4 个参数(给定 1 个)。
这是有错误的图像的 link: http://i.stack.imgur.com/we3VU.png
这是我的代码:
def get_r_post_relation(self, url, update = False) :
sufix = "r"
key = sufix + url
list_version = memcache.get(key)
if not list_version or update :
logging.error("LIST VERSION QUERY")
postobj = get_wiki_post(url)
list_version = WikiPostVersion.query().filter(WikiPostVersion.r_post == postobj.key)
memcache.set(key, list_version)
return list_version
您没有存储列表。您正在存储查询对象。要存储列表,请使用 .fetch()
:
list_version = WikiPostVersion.query().filter(WikiPostVersion.r_post == postobj.key).fetch()
您可以存储一个简单的查询对象,但是当您添加 .order()
或 .filter()
时,您会收到 pickling 错误。切换到列表,一切就绪。
请记住,查询对象中没有任何实体。它只是一组指令,用于在稍后与 .get()
或 .fetch()
一起使用时检索实体。因此,当您打算存储实际实体列表时,您正试图存储一个 python 命令集。