App Engine memcache async operation get_multi_async
Ho to use memcache get_multi_async.
Doc says it returns "dictionary" of values. http://code.google.com/appengine/docs/python/memcache/clientclass.html#Client_get_multi_async
I was expecting it to return some kind of "async object" on which i can do get_result()开发者_Python百科 later.
Am i missing something ??
I believe you need to pass in an RPC object; the dictionary it speaks of will be obtained via the get_result()
function on the RPC object.
The call to get_multi_async
actually returns an RPC
object which you use to later do the result.
client = memcache.Client()
rpc = client.get_multi_async(['key1', 'key2'])
# Do other work
result = rpc.get_result()
If you want, you can make your own RPC
object which allows you to control the deadline and also provide a callback to be invoked when the fetch is finished:
client = memcache.Client()
rpc = memcache.create_rpc(deadline=30, callback=my_callback)
client.get_multi_async(['key1', 'key2'], rpc=rpc)
Note that the RPC object you make has to be from the memcache
package, not the urlfetch
one.
精彩评论