我正在使用Amazon Elasticache和pythonspymemcache
模块。在
client = Client(('xxxx', 11211))
test=[1,2,3,4]
client.set('test_key', test)
result = client.get('test_key')
pprint.pprint(result)
pprint.pprint(test)
这将输出以下内容:
^{pr2}$
如您所见,memcache结果已更改为字符串。如何存储阵列?或者将字符串转换回数组?在
Tags:
Memcache本身将值存储为字符串。如果需要,您可以在
pymemcache
中customize your serialization。它看起来像是由default,pymemcache
只是在值上使用__str__
方法,如果没有提供序列化程序:我个人更喜欢^{} 而不是pymemcache。它可以很好地处理非字符串值。在
图书馆似乎想让你先把数据序列化。 https://pymemcache.readthedocs.io/en/latest/getting_started.html#serialization
也许你可以用另一个图书馆? https://github.com/pinterest/pymemcache#comparison-with-other-libraries
我不确定它是否适合您的目的,但是dogpile.cache可能也值得一看。使用它很好,而且它的后端之一是memcached。在
pymemcache作为客户端的服务memcached只支持字符串值。这就是为什么默认情况下pymemcache返回一个字符串。 我建议添加一个小包装器来序列化和反序列化从字符串到对象(如数组)的值。客户机支持添加自己的序列化程序,如下所示
相关问题 更多 >
编程相关推荐