[文章作者:张宴 本文版本:v1.0 最后修改:2008.11.30 转载请注明原文链接:http://blog.zyan.cc/post/384/]

  首先,需要了解Memcached协议,如果不清楚可参考《Memcached 协议中英文对照》。

  1、数据存储(假设key为zhangyan,value为12345)
printf "set zhangyan 0 0 5\r\n12345\r\n" | nc 127.0.0.1 11211
 STORED

  2、数据取回(假设key为zhangyan)
printf "get zhangyan\r\n" | nc 127.0.0.1 11211
 VALUE zhangyan 0 5
 12345
 END


  3、数值增加1(假设key为zhangyan,并且value为正整数)
printf "incr zhangyan 1\r\n" | nc 127.0.0.1 11211
 12346

  4、数值减少3(假设key为zhangyan,并且value为正整数)
printf "decr zhangyan 3\r\n" | nc 127.0.0.1 11211
 12343

  5、数据删除(假设key为zhangyan)
printf "delete zhangyan\r\n" | nc 127.0.0.1 11211
 DELETED

  6、查看Memcached状态
printf "stats\r\n" | nc 127.0.0.1 11211
 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状态:
watch "printf 'stats\r\n' | nc 127.0.0.1 11211"

  或者
watch "echo stats | nc 127.0.0.1 11211"





技术大类 » Cache与存储 | 评论(52) | 引用(0) | 阅读(76050)
xi2008wang
2008-12-1 00:31
沙发.
maker Homepage
2008-12-1 01:14
张宴周末也不休息?你博客的访问量很不错啊
dayan
2009-3-3 14:11
当然,张宴就是偶像
ONLY
2009-4-10 15:34
请问:

如何在memcached中保存文件?

例如:

cp -rf /var/www/images/* nc 127.0.0.1 11211

这样的,感谢!
VeroModa
2009-4-10 15:36
你好!

请问下,如何向memcached中写入文件,就像是向某个目录中写入文件一样的?

例如:

cp -rf /var/www/images/ nc 127.0.0.1 11211

这样的实现,谢谢!
ONLY
2009-4-13 09:55
在网上找到段代码,据说是向memcached中写入文件的。试过了,什么也没发生!
张宴大大帮看看,是哪里的问题?
引用
<?php

function rscandir($base='', &$data=array()) {
$array = array_diff(scandir($base), array('.', '..'));

foreach($array as $value) :
  if (is_dir($base.$value)) {
    $data = rscandir($base.$value.'/', $data);

  }
  elseif (is_file($base.$value)) {
   $rest = substr($value, -4);
   if ((!strcmp($rest,'.jpg')) || (!strcmp($rest,'.png'))
                                || (!strcmp($rest,'.gif')) ){
         $data[] = $base.$value;
   }
}

endforeach;
return $data;
}

$mylist=rscandir("/var/www/mysite");

$srch = array('/var/www/mysite');
$newval = array('');

$memcache_obj = memcache_connect("192.168.2.1", 11211);

while (list($key, $val) = each($mylist)) {
  $url=str_replace($srch,$newval,$val);
  echo "$key => $val -> ".filesize($val)."\n";
  $value = file_get_contents($val);
  memcache_add($memcache_obj, $url, $value, false, 0);
}
?>

万分感谢!
cnrainbing
2011-8-31 13:53
请问在memcache里面保存文件那么怎么取出来呢?保存:cp -rf /var/www/images/* nc 127.0.0.1 11211获取:命令是?
louis vuitton uk Email Homepage
2011-11-23 09:06
This louis vuitton uk for sale belongs to the sounding just what are termed as Louis Vuitton vintage best sellers, many other products and services for the reason that range appearing companies.You will easily notice the unfold zippers of this coach outlet store online. That is the decoration. There are some inside pockets for you as well. They are easy to match your clothes and to carry.Let us inspire your inner beauty with fine christian louboutin sale. Purse the elegance in bridal wedding. Enjoy the fashion.
Louis Vuitton Neverfull Email Homepage
2012-4-21 17:34
www.lvbagsclassic.com are authorized authentic Louis Vuitton handbags outlet store. All the items at our site are 100% authentic. All our Louis Vuitton handbags will come with the authenticity card, serial Number, dust bag and care booklet. We promise you will be 100% satisfied when you get such cheap authentic Louis Vuitton handbags from us!
Louis Vuitton Neverfull
Hogan
2012-5-10 18:10
Mentre youre gestione di problemi complessi tra cui PAYE insieme con le imprese del prelievo, l'idea è sicuramente intelligente per acquisire specializzata fare qualcosa di sicuro si sta usando la vostra organizzazione. Self-employmentSelf lavoratori uomini e donne potrebbe anche fare pieno uso Hogan dei ragionieri in tutta Stansted, quando hanno l'effetto della loro prelievo unico e sì, è spesso sconcertante. Stare di fronte a una buona varietà prelievo può essere schiacciante, di conseguenza, il
coach factory outlet Email Homepage
2012-5-17 11:56
Today, following half a century, mentor leather-bases coach factory outlet continues to be the delicate craft of leather-based master is accountable for,Would you like to meet more friends, or go with the times? If yes, coach factory online is opening welcome doors to you.in the market you definitely can find various colorways that are designed in as well as the high quality that applied in. For most of you would like to come. So just come to our coach factory outlet online store to choose one.
louis vuitton sale Email Homepage
2012-5-17 11:56
Louis Vuitton belt at louis vuitton sale is one kind of fashion accessory with high cost performance among the Louis Vuitton accessories.Offering quality LV products with favorable prices, louis vuitton outlet store is at your service. Hurry up, or you can not seize the chance.in fact, louis vuitton is one of the most famous fashion design master.he opened the fist suitcase shop called after his name.
coach outlet online Email Homepage
2012-5-17 11:56
I heard of coach outlet online through the advertisement when I was shopping. And now I often brow the webpage and buy Coach bags online.It is a symbol regarding position not to mention nature.Here I would like to launch a excellent bags pertaining to business men.Which may be coach outlet store.coach outlet has always been simple,durable style features to win consumers.The products are more flexible,with easy bleaching,wear characteristics,and simply use a damp cloth.
coach outlet, Email Homepage
2012-5-17 11:56
Remember the coach outlet provide coach bags which won't be deteriorated into its overall styles by any means. It will maintain its looks, colors, and uniqueness for long time.coach outlet store online has been voted by Hour Detroit magazine readers as the Best of Detroit in their 12th annual readers'poll.Lots of women like which usually amount normally include a coach outlet online ,it provides coziness to many girls that don't even think it is a great bushel of great interest directly to them.
Coach Outlet Online Email Homepage
2012-5-18 10:18
to obtain Coach Outlet Online in Hainan is amongst the brand new darling from residential holiday makers.He has served as Chairman and Chief Executive Officer of Coach since November 1995. He has served as a member of Coach Outlet Board of Directors since June 1, 2000, the date of incorporation. 
Coach  Outlet Email Homepage
2012-5-18 10:40
Coach Outlet was founded in 1941, in a loft in New York City.as a partnership called the Gail Manufacturing Company. Gail Manufacturing Company began as a family-owned business, with six leatherworkers who made small leather goods, such as wallets and handbags.Coach Outlet Online Store guarantee that all the coach handbags offered are own high quality. In addition , all of them are sold at an unexpected low price.If you want to purchase, just visit their website. 
Coach  Outlet Email Homepage
2012-5-18 10:47
Five years later in 1985, the Cahns decided to sell Coach Outlet after determining that none of their three children had any desire to take over the family leatherware business . Coach was then sold to Sara Lee Corporation for $30 million dollars.electric, diesel and mainline electric multiple units (EMU, DMU, MEMU), metro Coach Outlet Canada and Diesel Electric Tower Cars (DETC), Accident Relief Medical Vans (ARMV), Inspection Cars (RA), Fuel Test Cars, Track Recording Cars, the latest coaches are for the Deccan Odyssey . 
Louis Vuitton Email Homepage
2012-5-18 10:53
During this period, Louis Vuitton incorporated its leather into most of its products, ranging from small purses and wallets to larger pieces of luggage.To emphasize Jacobs's fashionable volte face, Kate Moss-last season's saucy Louis Vuitton UK dominatrix was recast for spring as the ballerina on that music box in a gleaming white baby doll frock and Barbie white stilettos. 
分页: 1/3 第一页 1 2 3 下页 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]