While trying to connect memcached using python I got following error:
ImportError: No module named memcache
Since I imported memcache & it’s not available in my server I got the error message saying that “No module named memcache”.
To resolve this issue we need to install python-memcache module.
Use following command to install python-memcache:
$ pip install python-memcache
If your OS is Ubuntu/Debian following command also works for you:
$ apt-get install python-memcache
After installing python-memcache we can seamlessly connect to memcached.
Following are steps to install memcached from source:
- Download latest version of memcached from http://memcached.org, uncompress it and enter into uncompressed directory.
- Install dependencies make and libevent-dev with apt-get.
$ apt-get install libevent-dev make
- After installation is completed run following commands:
$ make install
This will complete installation of memcached.
Above installation will install will copy memcached executable file in path ”
Now create an alias of memcahed executable in /usr/bin with following command:
$ ln -s /usr/local/memcached/bin/memcached /usr/bin/memcached
Start memcached in localhost
$ memcached -u root -d -m 1024 -p 11211 -l localhost
Above command will start memcached with 1GB memory on port 11211.
To check memcached stats use following command:
$ echo "stats" | nc localhost 11211
It will display some stats related to memcached.
To flush/clear the contents of memcached server use following command
echo 'flush_all' | nc localhost 11211
Where localhost is memcached hostname and 11211 is memcached port number.
echo 'flush_all' | nc server_hostname memcached_port_number