我正在尝试将memcached用于我的Django 1.8.5(在python3下)网站。
目前我已经尝试了pylibmc和python-memcached。
pylibmc给了我这个错误
libmemcached/get.cc:87 Assertion "ptr->query_id == query_id +1" failed for function "memcached_get_by_key" likely for "Programmer error, the query_id was not incremented."
Number of stack frames obtained: 24
/usr/lib/x86_64-linux-gnu/libmemcached.so.10 : memcached_get_by_key()+0x283
/usr/lib/x86_64-linux-gnu/libmemcached.so.10 : memcached_get()+0x1f
/home/francesco/virtualenvs/TeamCompSite/lib/python3.4/site-packages/_pylibmc.cpython-34m.so : ()+0x61fd
/home/francesco/virtualenvs/TeamCompSite/bin/python : PyEval_EvalFrameEx()+0x3f6a
/home/francesco/virtualenvs/TeamCompSite/bin/python : PyEval_EvalCodeEx()+0x15b
/home/francesco/virtualenvs/TeamCompSite/bin/python : PyEval_EvalFrameEx()+0x4490
/home/francesco/virtualenvs/TeamCompSite/bin/python : PyEval_EvalCodeEx()+0x15b
/home/francesco/virtualenvs/TeamCompSite/bin/python : PyEval_EvalFrameEx()+0x4490
/home/francesco/virtualenvs/TeamCompSite/bin/python() [0x56a7ec]
/home/francesco/virtualenvs/TeamCompSite/bin/python : PyObject_Call()+0x3a
/home/francesco/virtualenvs/TeamCompSite/bin/python : PyEval_EvalFrameEx()+0x1e2f
/home/francesco/virtualenvs/TeamCompSite/bin/python() [0x56a7ec]
/home/francesco/virtualenvs/TeamCompSite/bin/python : PyObject_Call()+0x3a
/home/francesco/virtualenvs/TeamCompSite/bin/python : PyEval_EvalFrameEx()+0x1e2f
/home/francesco/virtualenvs/TeamCompSite/bin/python : PyEval_EvalFrameEx()+0x403d
/home/francesco/virtualenvs/TeamCompSite/bin/python : PyEval_EvalFrameEx()+0x403d
/home/francesco/virtualenvs/TeamCompSite/bin/python() [0x56a7ec]
/home/francesco/virtualenvs/TeamCompSite/bin/python() [0x4e21bd]
/home/francesco/virtualenvs/TeamCompSite/bin/python : PyObject_Call()+0x3a
/home/francesco/virtualenvs/TeamCompSite/bin/python : PyEval_CallObjectWithKeywords()+0x36
/home/francesco/virtualenvs/TeamCompSite/bin/python() [0x5be452]
/lib/x86_64-linux-gnu/libpthread.so.0 : ()+0x8182
/lib/x86_64-linux-gnu/libc.so.6 : clone()+0x6d
看起来非常罕见,因为在google上我只找到了pylibmc: 'Assertion "ptr->query_id == query_id +1" failed for function "memcached_get_by_key"'
不幸的是我无法改变django如何处理memcached lib ..
然后我尝试了python-memcached
这次我得到了
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f00537e9f28>
Traceback (most recent call last):
File "/home/francesco/virtualenvs/TeamCompSite/lib/python3.4/site-packages/django/utils/autoreload.py", line 229, in wrapper
fn(*args, **kwargs)
File "/home/francesco/virtualenvs/TeamCompSite/lib/python3.4/site-packages/django/core/management/commands/runserver.py", line 107, in inner_run
autoreload.raise_last_exception()
File "/home/francesco/virtualenvs/TeamCompSite/lib/python3.4/site-packages/django/utils/autoreload.py", line 252, in raise_last_exception
six.reraise(*_exception)
File "/home/francesco/virtualenvs/TeamCompSite/lib/python3.4/site-packages/django/utils/six.py", line 658, in reraise
raise value.with_traceback(tb)
File "/home/francesco/virtualenvs/TeamCompSite/lib/python3.4/site-packages/django/utils/autoreload.py", line 229, in wrapper
fn(*args, **kwargs)
File "/home/francesco/virtualenvs/TeamCompSite/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/francesco/virtualenvs/TeamCompSite/lib/python3.4/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/media/francesco/A6528DA1528D76B9/Programmazione/Python/Spark/team_comp_site/teamcomp/apps.py", line 19, in ready
client.get_stats()
File "/home/francesco/virtualenvs/TeamCompSite/lib/python3.4/site-packages/memcache.py", line 338, in get_stats
stats = line.split(' ', 2)
TypeError: 'str' does not support the buffer interface
看起来python-memcached只支持python2(我不能事先检查)
让我们试试python3-memcached
网站加载!!!
只是为了向我展示熟悉的错误页面
Exception Value: local variable 'val' referenced before assignment
Exception Location: /home/xxxxx/virtualenvs/xxxx/lib/python3.4/site-packages/memcache.py in _recv_value, line 1026
Python Executable: /home/xxxxx/virtualenvs/xxxxx/bin/python
Python Version: 3.4.3
那么,python3(.4)memcached客户端有哪些选项?
答案 0 :(得分:0)
使用python3-memcached只会触发更清晰的字符串和字节缓冲区管理。
在python2中,unicode字符串是字节数组,字符串是ascii或\uXXXX
字符链。 ascii string到bytestring之间的转换是静默的,但是从bytestring到string explicite。
在python3中:unicode类型不再存在。您只有str
并且只有bytearray
。因为一切都必须明确,所以一切都更容易预测。 python-memcached库被重新开发以适应这种新的 - 更简单 - 处理py3中字符串的方式。