1.使用方法
1. 連接到memcached
telnet 192.168.1.100 11211
add name 0 60 5 [說明 add 是指令名 name 是key的名字 (是以key/value存放), 0 標志, 60 表示數據存放 60s 5表示 放入多大數據 ], 如果一個key已經存在,再放入是失敗的.
get name [獲取 name的值]
//更新
set name 0 60 5 [如果 name 這個key存在,就是更新, 如果key不存在,就是添加]
//刪除
delete key值
2. 常用命令
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 顯示幫助
memcached的基本命令(當memcached 啟動后 用於對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 |
對查看的信息的關鍵字中英文對照表
pid |
memcache服務器的進程ID |
uptime |
服務器已經運行的秒數 |
time |
服務器當前的unix時間戳 |
version |
memcache版本 |
pointer_size |
當前操作系統的指針大小(32位系統一般是32bit) |
rusage_user |
進程的累計用戶時間 |
rusage_system |
進程的累計系統時間 |
curr_items |
服務器當前存儲的items數量 |
total_items |
從服務器啟動以后存儲的items總數量 |
bytes |
當前服務器存儲items占用的字節數 |
curr_connections |
當前打開着的連接數 |
total_connections |
從服務器啟動以后曾經打開過的連接數 |
connection_structures |
服務器分配的連接構造數 |
cmd_get |
get命令(獲取)總請求次數 |
cmd_set |
set命令(保存)總請求次數 |
get_hits |
總命中次數 |
get_misses |
總未命中次數 |
evictions |
為獲取空閑內存而刪除的items數(分配給memcache的空間用滿后需要刪除舊的items來得到空間分配給新的items) |
bytes_read |
總讀取字節數(請求字節數) |
bytes_written |
總發送字節數(結果字節數) |
limit_maxbytes |
分配給memcache的內存大小(字節) |
threads |
當前線程數 |
特別注意:
memcached –m 256m –d start
如果memcached 使用的內存超過了定義的內存,就會把最不常用的內存刪除,該算法是LRU
如果你希望換一個端口
memcached -d -m 30 -l 127.0.0.1 -p 9000 -d start 此命令不適用unix
轉自:http://blog.163.com/xiao66_fei/blog/static/1099087642012911114848150/