﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Skynet-随笔分类-cache</title><link>http://www.blogjava.net/Skynet/category/38248.html</link><description>十一长假 整理 www.blogjava.net/Good-Game 中
打搬家了 
;)</description><language>zh-cn</language><lastBuildDate>Thu, 26 Mar 2009 04:46:06 GMT</lastBuildDate><pubDate>Thu, 26 Mar 2009 04:46:06 GMT</pubDate><ttl>60</ttl><item><title>memcachedb </title><link>http://www.blogjava.net/Skynet/archive/2009/02/26/256836.html</link><dc:creator>刘凯毅</dc:creator><author>刘凯毅</author><pubDate>Thu, 26 Feb 2009 08:23:00 GMT</pubDate><guid>http://www.blogjava.net/Skynet/archive/2009/02/26/256836.html</guid><wfw:comment>http://www.blogjava.net/Skynet/comments/256836.html</wfw:comment><comments>http://www.blogjava.net/Skynet/archive/2009/02/26/256836.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Skynet/comments/commentRss/256836.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Skynet/services/trackbacks/256836.html</trackback:ping><description><![CDATA[<br />
安装参考：<br />
&nbsp;&nbsp; http://www.cnblogs.com/cerxp/archive/2008/04/22/1165620.html<br />
<br />
相对 memcached 增强的功能：<br />
&nbsp; 1. 坠机后，&#8220;缓存&#8221;初始化回到断电前<br />
&nbsp; 2. 支持同步（可看成集群）<a id="AjaxHolder_ctl01_TitleUrl" class="postTitle2" href="http://www.cnblogs.com/pc-funning/archive/2009/02/11/1388020.html">Memcachedb 简单使用</a><br />
<br />
代价：<br />
&nbsp; 比 memcached 慢 15%<br />
参考：http://swik.net/Jabber-linux/Jabber+XMPP+resource/memcachedb%E7%9A%84%E6%80%A7%E8%83%BD%E6%B5%8B%E8%AF%95/b1odq<br />
<br />
<img src ="http://www.blogjava.net/Skynet/aggbug/256836.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Skynet/" target="_blank">刘凯毅</a> 2009-02-26 16:23 <a href="http://www.blogjava.net/Skynet/archive/2009/02/26/256836.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Memcached 对话 Google ProtocolBuffers (perl)</title><link>http://www.blogjava.net/Skynet/archive/2009/02/26/256804.html</link><dc:creator>刘凯毅</dc:creator><author>刘凯毅</author><pubDate>Thu, 26 Feb 2009 05:45:00 GMT</pubDate><guid>http://www.blogjava.net/Skynet/archive/2009/02/26/256804.html</guid><wfw:comment>http://www.blogjava.net/Skynet/comments/256804.html</wfw:comment><comments>http://www.blogjava.net/Skynet/archive/2009/02/26/256804.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Skynet/comments/commentRss/256804.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Skynet/services/trackbacks/256804.html</trackback:ping><description><![CDATA[<br />
<br />
&nbsp;
看看我这张 web&nbsp; 系统架构图，那就知道 <strong>使用统一存储格式的好处了。<br />
&nbsp;
在这种结构中你就单纯使用 java ，或 php 某一种单一语言描述格式，存储你集群交互的数据吗！？使用</strong><strong>ProtocolBuffers</strong> 吧，<strong>Google 已经有 现成的api来帮你扩展了。</strong><br />
<strong>
<br />
参考：</strong>http://blog.csdn.net/lcj8/archive/2009/02/17/3900157.aspx
<p><img src="http://p.blog.csdn.net/images/p_blog_csdn_net/wanghao72214/EntryImages/20090131/1224059455_ddvip_6170.jpg" alt="" width="289" height="263" /></p>
<br />
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;
作为 <strong>Memcached </strong>就是为集群使用，那么作为在缓存存储的数据我想也应该适用与各种环境，这时候 数据结构协议 <strong>Google ProtocolBuffers </strong><br />
<strong>参考：</strong>http://code.google.com/apis/protocolbuffers/docs/overview.html<br />
<strong>其他语言：</strong>http://code.google.com/p/protobuf/wiki/OtherLanguages<br />
（可适用与多种语言，<br />
&nbsp;&nbsp;&nbsp; javascript 读取缓存中的数据 ,你可以想象下你的 web服务开发 的将来！）<br />
<br />
<br />
<br />
目前学习perl 中 就先上个这的代码：<br />
<strong>参考：</strong><br />
http://search.cpan.org/~gariev/Google-ProtocolBuffers-0.08/lib/Google/ProtocolBuffers.pm#___top
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">!/bin/perl&nbsp;-w</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">use</span><span style="color: rgb(0, 0, 0);">&nbsp;Cache</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">Memcached;<br />
</span><span style="color: rgb(0, 0, 255);">use</span><span style="color: rgb(0, 0, 0);">&nbsp;Google</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">ProtocolBuffers;<br />
<span style="color: rgb(8, 255, 69);"><span style="color: rgb(34, 182, 43);">#开启 memd</span></span><br />
</span><span style="color: rgb(0, 0, 255);">my</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">$memd</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;new&nbsp;Cache</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">Memcached{servers&nbsp;</span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);">&nbsp;[</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">10.0.2.15:11211</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">]&nbsp;};<br />
<br />
<span style="color: rgb(29, 136, 56);">#声明 缓存 存储 protocol 格式</span><br />
</span><span style="color: rgb(0, 0, 255);">my</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">$key</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">test</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">;<br />
Google</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">ProtocolBuffers</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">parse(</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;"><br />
&nbsp;&nbsp;message&nbsp;Person{<br />
&nbsp;&nbsp;&nbsp;&nbsp;required&nbsp;int32&nbsp;id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;required&nbsp;string&nbsp;name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=2;<br />
&nbsp;&nbsp;}<br />
</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">{create_accessors</span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(128, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">});<br />
<br />
</span><span style="color: rgb(0, 0, 255);">my</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">$data</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">Person</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">encode({<br />
&nbsp;&nbsp;id</span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(128, 0, 0);">123</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;name</span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">liukaiyi</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);"><br />
});<br />
<br />
<span style="color: rgb(53, 142, 75);">#缓存存储</span><br />
</span><span style="color: rgb(128, 0, 128);">$memd</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">add(</span><span style="color: rgb(128, 0, 128);">$key</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(128, 0, 128);">$data</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">3600</span><span style="color: rgb(0, 0, 0);">);<br />
<br />
</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">######################################################################</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">my</span>&nbsp;<span style="color: rgb(128, 0, 128);">$memd</span>&nbsp;<span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;new&nbsp;Cache</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">Memcached{servers&nbsp;</span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);">&nbsp;[</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">10.0.2.15:11211</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">]&nbsp;};</span><br />
<span style="color: rgb(0, 0, 255);">my</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">$person</span><span style="color: rgb(0, 0, 0);">;{<br />
&nbsp; <span style="color: rgb(21, 140, 51);">#从缓存中取出</span><br />
&nbsp;&nbsp;</span><span style="color: rgb(128, 0, 128);">$person</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;Person</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">decode(</span><span style="color: rgb(128, 0, 128);">$memd</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">get(</span><span style="color: rgb(128, 0, 128);">$key</span><span style="color: rgb(0, 0, 0);">));<br />
}<br />
<br />
</span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">$person</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">id</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">-</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 128);">$person</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">name;<br />
<br />
</span></div>
&nbsp;<br />
<br />
<br />
结果：<br />
&nbsp; 123-liukaiyi<br />
<br />
<br />
<img src ="http://www.blogjava.net/Skynet/aggbug/256804.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Skynet/" target="_blank">刘凯毅</a> 2009-02-26 13:45 <a href="http://www.blogjava.net/Skynet/archive/2009/02/26/256804.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>memcached 使用（perl）</title><link>http://www.blogjava.net/Skynet/archive/2009/02/25/256642.html</link><dc:creator>刘凯毅</dc:creator><author>刘凯毅</author><pubDate>Wed, 25 Feb 2009 08:23:00 GMT</pubDate><guid>http://www.blogjava.net/Skynet/archive/2009/02/25/256642.html</guid><wfw:comment>http://www.blogjava.net/Skynet/comments/256642.html</wfw:comment><comments>http://www.blogjava.net/Skynet/archive/2009/02/25/256642.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Skynet/comments/commentRss/256642.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Skynet/services/trackbacks/256642.html</trackback:ping><description><![CDATA[&nbsp; <br />
&nbsp; 这大体上可以看出，服务器端口缓存技术。<br />
<br />
&nbsp; memcached 官方：http://www.danga.com/memcached/<br />
&nbsp; 安装前，先安装 <a href="http://www.monkey.org/%7Eprovos/libevent/">libevent</a><br />
&nbsp; 其上为 linux 软件一般安装，看他们readme文档 <br />
&nbsp; $&gt;memcached -d -u nobody -m 512 127.0.0.1 -p 11211<br />
&nbsp; <br />
&nbsp; 如果有异常，<br />
&nbsp; <strong><span style="color: rgb(53, 24, 255);">ln -s /usr/local/lib/libevent-1.4.so.2 /lib/libevent-1.4.so.2<br />
&nbsp; 参考&nbsp; </span></strong>http://blog.chinaunix.net/u2/70049/showart_1665279.html<br />
<strong><span style="color: rgb(53, 24, 255);">&nbsp; </span></strong>我这就使用 <strong>perl</strong> 语言了，<br />
&nbsp;&nbsp; 其他语言参考 http://code.google.com/p/memcached/wiki/Clients<br />
<br />
&nbsp;&nbsp; perl 使用 cpan&gt; install <span style="color: rgb(0, 0, 0);">Cache</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">Memcached ;<strong>#会使用 perl 我就不说了</strong></span><br />
代码说明：不停对 key 为test 的值进行递增 &nbsp; <br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">!/bin/perl&nbsp;-w</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">use</span><span style="color: rgb(0, 0, 0);">&nbsp;Cache</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">Memcached;<br />
<br />
</span><span style="color: rgb(0, 0, 255);">my</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">$memd</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;new&nbsp;Cache</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">Memcached{servers&nbsp;</span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);">&nbsp;[</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">127.0.0.1:11211</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">]&nbsp;};<br />
</span><span style="color: rgb(0, 0, 255);">my</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">$key</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">test</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">;<br />
</span><span style="color: rgb(128, 0, 128);">$memd</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">add(</span><span style="color: rgb(128, 0, 128);">$key</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">3600</span><span style="color: rgb(0, 0, 0);">)&nbsp;or&nbsp;</span><span style="color: rgb(0, 0, 255);">warn</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">Alread&nbsp;added</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">;<br />
</span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">){<br />
&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">$memd</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">get(</span><span style="color: rgb(128, 0, 128);">$key</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">\n</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0);">;<br />
&nbsp;&nbsp;</span><span style="color: rgb(128, 0, 128);">$memd</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">incr(</span><span style="color: rgb(128, 0, 128);">$key</span><span style="color: rgb(0, 0, 0);">)&nbsp;or&nbsp;</span><span style="color: rgb(0, 0, 255);">warn</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">FAIL!</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">;<br />
}</span><span style="color: rgb(0, 0, 0);"><br />
</span></div>
<strong></strong>
<br />
使用 telnet 127.0.0.1 11211<br />
&nbsp; &nbsp;&nbsp; $&gt; get&nbsp; test <br />
&nbsp; &nbsp;&nbsp; VALUE test 0 2<br />
&nbsp; &nbsp;&nbsp; <strong><span style="color: rgb(248, 0, 0);">97</span></strong> <strong>#这就是我们递增的值,当然你使用什么语言取都是一样的 <br />
</strong>&nbsp; &nbsp;&nbsp; END <br />
<br />
<img src ="http://www.blogjava.net/Skynet/aggbug/256642.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Skynet/" target="_blank">刘凯毅</a> 2009-02-25 16:23 <a href="http://www.blogjava.net/Skynet/archive/2009/02/25/256642.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>