今天找了很久,如何在服务器直接查看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
11211

 

2. 列出所有keys

 

 
1
2
3
4
// 这条是命令
1
188
END

 

3. 通过itemid获取key

接下来基于列出的items id,本例中为7,第2个参数为列出的长度,0为全部列出

 
1
2
3
// 这条是命令
]
END

 

4. 通过get获取key值

上面的stats cachedump命令列出了我的session key,接下来就用get命令查找对应的session值

 
1
2
3
4
5
6
7
//这条是命令
VALUE
1
83
}

以上操作是直接复制的,本人亲测,没有问题

http://blog.csdn.net/liu414226580/article/details/8263445    这里面的方法是直接set,   get.

1.一种

  

[plain] view plain copy
 
 print?
  1. telnet localhost 200001 #登陆  
  2.   stats #查看状态  
  3.   flush_all #清理  
  4.   quit #退出  

 

 

  2.又学到一个:

  echo 'flush_all' | nc localhost 200001

  3.

  1、数据存储(假设key为test,value为12345)

  

[plain] view plain copy
 
 print?
  1. printf "set test 0 0 5\r\n12345\r\n" | nc 127.0.0.1 200001  
  2.   STORED  

 

 

  2、数据取回(假设key为test)

  

[plain] view plain copy
 
 print?
  1. printf "get test\r\n" | nc 127.0.0.1 200001  
  2.   VALUE test 0 5  
  3.   12345  
  4.   END  

 

 

  3、数值增加1(假设key为test,并且value为正整数)

  printf "incr test 1\r\n" | nc 127.0.0.1 200001

  12346

  4、数值减少3(假设key为test,并且value为正整数)

 

[plain] view plain copy
 
 print?
  1. printf "decr test 3\r\n" | nc 127.0.0.1 200001  
  2.  12343  

 

 

  5、数据删除(假设key为test)

  

[plain] view plain copy
 
 print?
  1. printf "delete test\r\n" | nc 127.0.0.1 11211  
  2.   DELETED  

 

 

  6、查看Memcached状态

 

[plain] view plain copy
 
 print?
  1. printf "stats\r\n" | nc 127.0.0.1 200001  
  2.  STAT pid 3025  
  3.  STAT uptime 4120500  
  4.  STAT time 1228021767  
  5.  STAT version 1.2.6  
  6.  STAT pointer_size 32  
  7.  STAT rusage_user 433.463103  
  8.  STAT rusage_system 1224.515845  
  9.  STAT curr_items 1132460  
  10.  STAT total_items 8980260  
  11.  STAT bytes 1895325386  
  12.  STAT curr_connections 252  
  13.  STAT total_connections 547850  
  14.  STAT connection_structures 1189  
  15.  STAT cmd_get 13619685  
  16.  STAT cmd_set 8980260  
  17.  STAT get_hits 6851607  
  18.  STAT get_misses 6768078  
  19.  STAT evictions 0  
  20.  STAT bytes_read 160396238246  
  21.  STAT bytes_written 260080686529  
  22.  STAT limit_maxbytes 2147483648  
  23.  STAT threads 1  
  24.  END  

 

 

  7、模拟top命令,查看Memcached状态:

  

[plain] view plain copy
 
 print?
    1. printf "stats\r\n" | nc 127.0.0.1 200001  
    2.   或者  
    3.   watch "echo stats | nc 127.0.0.1 200001"  

 

相关文章:

猜你喜欢
相关资源
相似解决方案