简体   繁体   English

使用python将dict加载到memcache中

[英]Load a dict into memcache with python

Have dict would like to load into memcache (complete newbie to memcache) 有dict想加载到memcache(完成新手到memcache)

testd = { 'aaa': (1,23, 300),  'bbb': (37, 23, 300),  'ccc': (39, 62, 300), } 

Would like to use set_multi ...but havent been able to find an example of loading dicts. 想使用set_multi ...但是set_multi能找到加载set_multi的例子。 Then how would I get the 'bbb' value? 那我怎么得到'bbb'值? or 'bbb' and 'ccc' values together. 或'bbb'和'ccc'值合在一起。

Below works but does not use set_multi 下面有效,但不使用set_multi

import memcache

mc = memcache.Client(['127.0.0.1:11211'], debug=0)  
mc.set('keyed',testd)


xdata = mc.get('keyed')
print xdata['bbb']

Saying something does not work is not helpful to you nor to future readers of this question. 说某些东西不起作用对你或这个问题的未来读者没有帮助。
Are you getting an error message? 您收到错误消息了吗? If not, how is the result different from the result you expect? 如果没有,结果与您期望的结果有何不同?

How are you calling set_multi ? 你怎么称呼set_multi What argument(s) are you passing to set_multi ? 您传递给set_multi参数是什么?

Looking at their source , we see that set_multi takes a mapping as the first (non-self) argument. 查看它们的源代码 ,我们看到set_multi将映射作为第一个(非自身)参数。
Given that a Python dictionary is a mapping we can do: 鉴于Python字典是我们可以做的映射:

mc.set_multi(testd)

What happens when you do that? 当你这样做时会发生什么? How does it differ from what you expect? 它与您的期望有何不同?
If you think you're encountering a bug, are you using the latest version of this library? 如果您认为自己遇到了错误,是否使用了此库的最新版本?
If not, please consider a newer version . 如果没有,请考虑更新的版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM