简体   繁体   中英

Load a dict into memcache with python

Have dict would like to load into memcache (complete newbie to 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. Then how would I get the 'bbb' value? or 'bbb' and 'ccc' values together.

Below works but does not use 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 ? What argument(s) are you passing to set_multi ?

Looking at their source , we see that set_multi takes a mapping as the first (non-self) argument.
Given that a Python dictionary is a mapping we can do:

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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