1、memcached 概述php
Memcache(内存,缓存) : 是一个高性能的分布式的内存对象缓存系统。经过在内存里维护一个巨大的hash表。(key=value)windows
key(键) | value(值) |
var1 | "123456" |
var2 | array('ab','cd') |
var3 | object值 |
2、memcached 安装(windows)缓存
一、下载 memcached 软件。 点击下载>>session
二、将 memcached 软件拷贝到某个目录,最好放在 php 开发环境目录下,便于管理。app
三、进入 windows 端的命令控制台,进入该目录下,安装 memcached.exe –d install [卸载使用 memcached.exe -d uninstall]分布式
注:将 memcached 所在的目录添加到 Path 中,就能够在命令控制台中直接使用 memcached 命令了。具体操做请点击查看相似操做步骤。memcached
四、启动/中止 memcached 服务,memcached -d start[stop]性能
若启动成功,能够在服务中看到:ui
五、memcached 的默认使用端口是:11211spa
特别说明:memcached 默认启动的最大内存为 64 M。若是须要的 memcached 的内存大于 64M,应当这样启动
3、memcached 的基本命令
安装、卸载、启动、配置相关
-p 监听的端口
-l 链接的IP地址, 默认是本机
-d start 启动memcached服务
-d restart 重起memcached服务
-d stop|shutdown 关闭正在运行的memcached服务
-d install 安装memcached服务
-d uninstall 卸载memcached服务
-u 以的身份运行 (仅在以root运行的时候有效)
-m 最大内存使用,单位MB。默认64MB
-M 内存耗尽时返回错误,而不是删除项
-c 最大同时链接数,默认是1024
-f 块大小增加因子,默认是1.25
-n 最小分配空间,key+value+flags默认是48
-h 显示帮助
4、操做 memcached
telnet localhost 11211 --telnet memcached
Command |
Description |
Example |
get |
Reads a value |
get mykey |
set |
Set a key unconditionally |
set mykey 0 60 5 |
add |
Add a new key |
add newkey 0 60 5 |
replace |
Overwrite existing key |
replace key 0 60 5 |
append |
Append data to existing key |
append key 0 60 15 |
prepend |
Prepend data to existing key |
prepend key 0 60 15 |
incr |
Increments numerical key value by given number |
incr mykey 2 |
decr |
Decrements numerical key value by given number |
decr mykey 5 |
delete |
Deletes an existing key |
delete mykey |
flush_all |
Invalidate specific items immediately |
flush_all |
Invalidate all items in n seconds |
flush_all 900 |
|
stats |
Prints general statistics |
stats |
Prints memory statistics |
stats slabs |
|
Prints memory statistics |
stats malloc |
|
Print higher level allocation statistics |
stats items |
|
stats detail |
||
stats sizes |
||
Resets statistics |
stats reset |
|
version |
Prints server version. |
version |
verbosity |
Increases log level |
verbosity |
quit |
Terminate telnet session |
quit |