How to increase memcache value size limit with python-memcached on centos¶
By default, the value size of a single memcache item is limited to 1MB. How can we increase it?
In the following chapters, we will set the size limit to 10MB.
Config memcache service¶
Edit file /etc/sysconfig/memcached
and add the following line:
OPTIONS="-I 10M"
Then restart memcache service.
Python client¶
If you are using python-memcached
library to access memcache, you need to update your python code.
Before execute python-memcached
's functions, you should update memcache.SERVER_MAX_VALUE_LENGTH
:
import memcache
# update size limit
memcache.SERVER_MAX_VALUE_LENGTH = 1024 * 1024 * 10
# access memcache later
mc = memcache.Client(['127.0.0.1:11211'], debug=0)
mc.set("some_key", "Some value")
This article is originally created by tooli.top. Please indicate the source when reprinting : https://www.tooli.top/posts/python_memcached
Posted on 2022-04-09
Mail to author