memcached的安装、常用命令以及在实际开发中的案例
Memcached注意 ? Linux平台 (CentOS)安装Memcached 安装依赖 以下方式任选一种 方式1. 自动安装方式 yum -y install memcached # 方式2. 源代码编译方式安装 wget https://memcached.org/latest mv latest memcached-1.5.20.tar.gz tar -zxvf memcached-.tar.gz cd memcached- ./configure --prefix=/usr/local/memcached make && sudo make install # Linux平台启动 ./memcached -p 11211 -u root -m 64m 或者 ./memcached -p 11211 -u root -m 64m -d 或者 ./memcached -p 11211 -m 64m -d -u root -l 127.0.0.1 -c 256 -P /tmp/memcached.pid # Linux平台服务进程查看 ps -ef | grep memcached # 根据端口查看 netstat -tunpl | grep 11211 # 关闭进程 kill -9 pid号 知识补充: emcached客户端 yum -y install telnet telnet 0.1 Trying 0.1... Connected to . Escape character is '^]'. ctrl + c 退出客户端 Windows 平台 32位系统下载地址 http:downloads.northscale.com/memcached-win32-1.4.4-14.zip # 64位系统下载地址 http:downloads.northscale.com/memcached-win64-1.4.4-14.zip # Windows平台安装启动 C:\memcached\memcached.exe -d install C:\memcached\memcached.exe -d start C:\memcached\memcached.exe -d stop 运行 -> pkgmgr /iu:"TelnetClient" Memcached常用命令 set命令 # 登录客户端 telnet # 存储命令 # set 命令 set www.test.com 1 0 4 best STORED noreply best # getget www.test.com add命令 add www.test.com best NOT_STORED add www.test.com noreply best add new test STORED replace命令 replace www.test.com best STORED replace www.test.com noreply best replace new2 test NOT_STORED append命令 append www.test.com best STORED append www.test.com noreply best append new3 test NOT_STORED prepend命令 prepend www.test.com best STORED prepend www.test.com noreply best prepend new3 test NOT_STORED cas(check-and-set)命令 gets www.imooc.com VALUE www.imooc.com 4 36 best END cas www.imooc.com test STORED get命令 www.test.com VALUE www.test.com test END www.test.com test VALUE www.test.com test VALUE test test END gets命令 gets www.test.com VALUE www.test.com test END gets www.test.com test VALUE www.test.com 37 test END incr命令 set count 1 1 STORED incr count 2 incr count 3 decr命令 decr count decr count 1 stats命令 stats items命令 # stats cachedump 命令 stats cachedump 0 ITEM www.test.com [4 b; s] ITEM test [ s] END stats slabs命令 stats sizes命令 # 需要启动memcached时开启track_sizes stats sizes STAT 96 END # delete 命令 delete www.test.com DELETED flush_all命令 ? 安装PHP的memcached扩展 方式1:自动安装 yum -y install php-memcached 重启httpd服务 service httpd restart 移除yum安装的php-memcached yum -y remove php-memcached (编辑:ASP站长网) |