今天找了很久,如何在服務器直接查看memcache 的值, 來確定php中memcache是否已經寫進去了
https://www.ttlsa.com/memcache/memcache-list-all-keys/ 這個方法不僅適用於windowns 的cmd . 也適用於linux 命令行操作, 下面是具體內容
今天在做一個Memcache的session測試,但是在測試的過程中,發現Memcache沒有一個比較簡單的方法可以直接象redis那樣keys *列出所有的Session key,並根據key get對應的session內容,於是,我開始查找資料,翻出來的大部分是一些memcache常用命令等,但是對列出key的辦法,講解卻不多,於是來到google,找到了一個國外的資料
具體的內容我套用我的測試環境中,操作如下
1. cmd上登錄memcache
1
|
> telnet 127.0.0.1 11211
|
2. 列出所有keys
1
2
3
4
|
stats items // 這條是命令
STAT items:7:number 1
STAT items:7:age 188
END
|
3. 通過itemid獲取key
接下來基於列出的items id,本例中為7,第2個參數為列出的長度,0為全部列出
1
2
3
|
stats cachedump 7 0 // 這條是命令
ITEM Sess_sidsvpc1473t1np08qnkvhf6j2 [183 b; 1394527347 s]
END
|
4. 通過get獲取key值
上面的stats cachedump命令列出了我的session key,接下來就用get命令查找對應的session值
1
2
3
4
5
6
7
|
get Sess_sidsvpc1473t1np08qnkvhf6j2 //這條是命令
VALUE
Sess_sidsvpc1473t1np08qnkvhf6j2 1440 1
83
Sess_|a:5:{s:6:"verify";s:32:"e70981fd305170c41a5632b2a24bbcaa";s:3:"uid";s:1:"1
";s:8:"username";s:5:"admin";s:9:"logintime";s:19:"2014-03-11 16:24:25";s:7:"log
inip";s:9:"127.0.0.1";}
|
以上操作是直接復制的,本人親測,沒有問題
http://blog.csdn.net/liu414226580/article/details/8263445 這里面的方法是直接set, get.
1.一種
- telnet localhost 200001 #登陸
- stats #查看狀態
- flush_all #清理
- quit #退出
2.又學到一個:
echo 'flush_all' | nc localhost 200001
3.
1、數據存儲(假設key為test,value為12345)
- printf "set test 0 0 5\r\n12345\r\n" | nc 127.0.0.1 200001
- STORED
2、數據取回(假設key為test)
- printf "get test\r\n" | nc 127.0.0.1 200001
- VALUE test 0 5
- 12345
- END
3、數值增加1(假設key為test,並且value為正整數)
printf "incr test 1\r\n" | nc 127.0.0.1 200001
12346
4、數值減少3(假設key為test,並且value為正整數)
- printf "decr test 3\r\n" | nc 127.0.0.1 200001
- 12343
5、數據刪除(假設key為test)
- printf "delete test\r\n" | nc 127.0.0.1 11211
- DELETED
6、查看Memcached狀態
- printf "stats\r\n" | nc 127.0.0.1 200001
- STAT pid 3025
- STAT uptime 4120500
- STAT time 1228021767
- STAT version 1.2.6
- STAT pointer_size 32
- STAT rusage_user 433.463103
- STAT rusage_system 1224.515845
- STAT curr_items 1132460
- STAT total_items 8980260
- STAT bytes 1895325386
- STAT curr_connections 252
- STAT total_connections 547850
- STAT connection_structures 1189
- STAT cmd_get 13619685
- STAT cmd_set 8980260
- STAT get_hits 6851607
- STAT get_misses 6768078
- STAT evictions 0
- STAT bytes_read 160396238246
- STAT bytes_written 260080686529
- STAT limit_maxbytes 2147483648
- STAT threads 1
- END
7、模擬top命令,查看Memcached狀態:
- printf "stats\r\n" | nc 127.0.0.1 200001
- 或者
- watch "echo stats | nc 127.0.0.1 200001"