Python connection memcached

Source: Internet
Author: User

1. Download and install

wget HTTP://WWW.MEMCACHED.ORG/FILES/MEMCACHED-1.5.3.TAR.GZTAR-ZXVF MEMCACHED-1.5.3.TAR.GZCD memcached-1.5.3./ Configure--prefix=/data/program/memcachedmake && make install



2. Start Memcache

./memcached-d-U root-l 127.0.0.1-m 50-p 11211-c 512-p/data/program/memcached/logs/memcached.pid

Parameters:

-U Running identity

-P Specify port number (default 11211)

-m specifies the maximum amount of memory to use (default 64MB)

-T thread count (default 4)

-L connected IP address, default is native

-D starts with the daemon process

-c Maximum number of simultaneous connections, default is 1024

-P Develop memecache PID file

-H Printing Help information


3. Connection test

[[Email protected] bin]# telnet 127.0.0.1 11211Trying 127.0.0.1...Connected to 127.0.0.1.Escape character is ' ^] '. Add test 1 0 5helloSTORED



Operation of the 4.memcache cluster

4.1 Download API Module python-memcached

wget https://pypi.python.org/packages/f7/62/14b2448cfb04427366f24104c9da97cf8ea380d7258a3233f066a951a8d8/ Python-memcached-1.58.tar.gz

Linux Environment:

Tar python-memcached-1.58.tar.gzcd python-memcached-1.58python setup.py Install


Reference Links: https://www.cnblogs.com/xiao1/p/5858967.html


4.2 Start

./memcached-d-U root-p 11211./memcached-d-u root-p 11212./memcached-d-u root-p 11213

Example:

#!/usr/bin/env Pythonimport memcache# Initializes a memcache client object with a port weight of 1:2:1 and an open error debug display MC = Memcache. Client (["192.168.2.230:11211", 1), ("192.168.2.230:11212", 2), ("192.168.2.230:11213", 1)],debug=true) mc.set ("Name "," huangzhenping ") Print (Mc.get (" name ")) MC1 = Memcache. The Client (["192.168.2.230:11211"],debug=true) print (Mc1.get ("name")) MC2 = Memcache. The Client (["192.168.2.230:11212"],debug=true) print (Mc1.get ("name")) MC3 = Memcache. Client (["192.168.2.230:11213"],debug=true) print (Mc3.get ("name"))


Operation Result:

Huangzhenping

None

None

Huangzhenping



Python connection memcached

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.