Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载。它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态、数据库驱动网站的速度。
$ sudo apt-get install memcached
$ ps aux | grep memcached
memcache 26355 0.0 0.0 325400 1208 ? Sl 16:30 0:00 /usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1
sudo apt-get install g++ make libevent-dev
curl -O --location http://memcached.org/latest
mv latest memcached-latest.tar.gz
tar vxzf memcached-latest.tar.gz
cd memcached-*
./configure && make
sudo make install
vim /etc/memcached.conf
sudo apt-get install telnet
$ telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.
Escape character is ‘^]‘.
https://github.com/memcached/memcached/blob/master/doc/protocol.txt
stats
STAT pid 26355
STAT uptime 457
STAT time 1404290303
STAT version 1.4.14
STAT libevent 2.0.21-stable
STAT pointer_size 64
STAT rusage_user 0.007959
STAT rusage_system 0.007959
STAT curr_connections 5
STAT total_connections 6
STAT connection_structures 6
STAT reserved_fds 20
STAT cmd_get 0
STAT cmd_set 0
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 0
STAT get_misses 0
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT touch_hits 0
STAT touch_misses 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 7
STAT bytes_written 0
STAT limit_maxbytes 67108864
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT hash_power_level 16
STAT hash_bytes 524288
STAT hash_is_expanding 0
STAT expired_unfetched 0
STAT evicted_unfetched 0
STAT bytes 0
STAT curr_items 0
STAT total_items 0
STAT evictions 0
STAT reclaimed 0
END
stats settings
STAT maxbytes 67108864
STAT maxconns 1024
STAT tcpport 11211
STAT udpport 11211
STAT inter 127.0.0.1
STAT verbosity 0
STAT oldest 0
STAT evictions on
STAT domain_socket NULL
STAT umask 700
STAT growth_factor 1.25
STAT chunk_size 48
STAT num_threads 4
STAT num_threads_per_udp 4
STAT stat_key_prefix :
STAT detail_enabled no
STAT reqs_per_event 20
STAT cas_enabled yes
STAT tcp_backlog 1024
STAT binding_protocol auto-negotiate
STAT auth_enabled_sasl no
STAT item_size_max 1048576
STAT maxconns_fast no
STAT hashpower_init 0
STAT slab_reassign no
STAT slab_automove 0
END
set mykey 0 300 16
I Love Memcached
按回车将会得到STORED
set mykey 0 300 16
I Love Memcached
STORED
现在我们就可以通过get获取值了
get mykey
VALUE mykey 0 16
I Love Memcached
END
set格式:
<command name> <key> <flags> <exptime> <bytes>
$ /etc/init.d/memcached status
* memcached is running
disable
sudo update-rc.d memcached disable
enable
sudo update-rc.d memcached enable
确认运行默认级别:
sudo update-rc.d memcached defaults
memcached -p 3030
memcached -p 3031
import pylibmc
mc = pylibmc.Client(["127.0.0.1:3030", "127.0.0.1:3031"], binary=True,
behaviors={"tcp_nodelay": True, "ketama": True})
mc["ahmed"] = "Hello World"
mc["tek"] = "Hello World"
原文地址:http://www.cnblogs.com/erhuabushuo/p/3820634.html