{"id":535,"date":"2008-09-28T00:00:00","date_gmt":"2008-09-27T16:00:00","guid":{"rendered":"http:\/\/www.strongd.net\/?p=535"},"modified":"2011-07-15T09:15:03","modified_gmt":"2011-07-15T01:15:03","slug":"%e5%88%a9%e7%94%a8memcached-java-client%e4%b8%80%e4%b8%aa%e7%ae%80%e5%8d%95%e7%9a%84%e5%ba%94%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=535","title":{"rendered":"\u5229\u7528memcached java client\u4e00\u4e2a\u7b80\u5355\u7684\u5e94\u7528"},"content":{"rendered":"<p><STRONG>\u5229\u7528memcached java client\u4e00\u4e2a\u7b80\u5355\u7684\u5e94\u7528<\/STRONG><br \/>\n<DIV class=blog_content><br \/>\n<P><FONT face=Arial>1.memcached java client\u4e00\u4e2a\u5b9e\u73b0\u7684\u4e0b\u8f7d\u5730\u5740<\/FONT><\/P><br \/>\n<P><FONT face=Arial>http:\/\/www.whalin.com\/memcached\/#download<BR>2.&nbsp; \u5229\u7528memcached java client \u4e00\u4e2a\u7b80\u5355\u7684\u5e94\u7528<\/FONT><\/P><br \/>\n<DIV class=code_title>java \u4ee3\u7801<\/DIV><br \/>\n<DIV class=dp-highlighter><br \/>\n<DIV class=bar><\/DIV><br \/>\n<OL class=dp-j><br \/>\n<LI class=alt><SPAN><SPAN class=keyword><STRONG><FONT color=#7f0055>package<\/FONT><\/STRONG><\/SPAN><SPAN>&nbsp;com.danga.MemCached.test; &nbsp;&nbsp;<\/SPAN><\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN><\/SPAN><SPAN class=keyword><STRONG><FONT color=#7f0055>import<\/FONT><\/STRONG><\/SPAN><SPAN>&nbsp;java.util.Date; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN><\/SPAN><SPAN class=keyword><STRONG><FONT color=#7f0055>import<\/FONT><\/STRONG><\/SPAN><SPAN>&nbsp;com.danga.MemCached.MemCachedClient; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN><\/SPAN><SPAN class=keyword><STRONG><FONT color=#7f0055>import<\/FONT><\/STRONG><\/SPAN><SPAN>&nbsp;com.danga.MemCached.SockIOPool; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN><\/SPAN><SPAN class=keyword><STRONG><FONT color=#7f0055>public<\/FONT><\/STRONG><\/SPAN><SPAN>&nbsp;<\/SPAN><SPAN class=keyword><STRONG><FONT color=#7f0055>class<\/FONT><\/STRONG><\/SPAN><SPAN>&nbsp;Test&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=keyword><STRONG><FONT color=#7f0055>protected<\/FONT><\/STRONG><\/SPAN><SPAN>&nbsp;<\/SPAN><SPAN class=keyword><STRONG><FONT color=#7f0055>static<\/FONT><\/STRONG><\/SPAN><SPAN>&nbsp;MemCachedClient&nbsp;mcc&nbsp;=&nbsp;<\/SPAN><SPAN class=keyword><STRONG><FONT color=#7f0055>new<\/FONT><\/STRONG><\/SPAN><SPAN>&nbsp;MemCachedClient();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=keyword><STRONG><FONT color=#7f0055>static<\/FONT><\/STRONG><\/SPAN><SPAN>&nbsp;{&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String[]&nbsp;servers&nbsp;={<\/SPAN><SPAN class=string><FONT color=#0000ff>&#8220;192.168.40.4:12000&#8221;<\/FONT><\/SPAN><SPAN>};&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Integer[]&nbsp;weights&nbsp;=&nbsp;{&nbsp;<\/SPAN><SPAN class=number>3<\/SPAN><SPAN>&nbsp;};&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=comment><FONT color=#008200>\/\/\u521b\u5efa\u4e00\u4e2a\u5b9e\u4f8b\u5bf9\u8c61SockIOPool&nbsp; <\/FONT><\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SockIOPool&nbsp;pool&nbsp;=&nbsp;SockIOPool.getInstance();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=comment><FONT color=#008200>\/\/&nbsp;set&nbsp;the&nbsp;servers&nbsp;and&nbsp;the&nbsp;weights <\/FONT><\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=comment><FONT color=#008200>\/\/\u8bbe\u7f6eMemcached&nbsp;Server <\/FONT><\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pool.setServers(&nbsp;servers&nbsp;);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pool.setWeights(&nbsp;weights&nbsp;);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=comment><FONT color=#008200>\/\/&nbsp;set&nbsp;some&nbsp;basic&nbsp;pool&nbsp;settings&nbsp;&nbsp;&nbsp; <\/FONT><\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=comment><FONT color=#008200>\/\/&nbsp;5&nbsp;initial,&nbsp;5&nbsp;min,&nbsp;and&nbsp;250&nbsp;max&nbsp;conns&nbsp;&nbsp;&nbsp; <\/FONT><\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=comment><FONT color=#008200>\/\/&nbsp;and&nbsp;set&nbsp;the&nbsp;max&nbsp;idle&nbsp;time&nbsp;for&nbsp;a&nbsp;conn&nbsp;&nbsp;&nbsp; <\/FONT><\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=comment><FONT color=#008200>\/\/&nbsp;to&nbsp;6&nbsp;hours&nbsp;&nbsp;&nbsp; <\/FONT><\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pool.setInitConn(&nbsp;<\/SPAN><SPAN class=number>5<\/SPAN><SPAN>&nbsp;);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pool.setMinConn(&nbsp;<\/SPAN><SPAN class=number>5<\/SPAN><SPAN>&nbsp;);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pool.setMaxConn(&nbsp;<\/SPAN><SPAN class=number>250<\/SPAN><SPAN>&nbsp;);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pool.setMaxIdle(&nbsp;<\/SPAN><SPAN class=number>1000<\/SPAN><SPAN>&nbsp;*&nbsp;<\/SPAN><SPAN class=number>60<\/SPAN><SPAN>&nbsp;*&nbsp;<\/SPAN><SPAN class=number>60<\/SPAN><SPAN>&nbsp;*&nbsp;<\/SPAN><SPAN class=number>6<\/SPAN><SPAN>&nbsp;);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=comment><FONT color=#008200>\/\/&nbsp;set&nbsp;the&nbsp;sleep&nbsp;for&nbsp;the&nbsp;maint&nbsp;thread&nbsp;&nbsp;&nbsp; <\/FONT><\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=comment><FONT color=#008200>\/\/&nbsp;it&nbsp;will&nbsp;wake&nbsp;up&nbsp;every&nbsp;x&nbsp;seconds&nbsp;and&nbsp;&nbsp;&nbsp; <\/FONT><\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=comment><FONT color=#008200>\/\/&nbsp;maintain&nbsp;the&nbsp;pool&nbsp;size&nbsp;&nbsp;&nbsp; <\/FONT><\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pool.setMaintSleep(&nbsp;<\/SPAN><SPAN class=number>30<\/SPAN><SPAN>&nbsp;);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN><\/SPAN><SPAN class=comment><FONT color=#008200>\/\/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Tcp\u7684\u89c4\u5219\u5c31\u662f\u5728\u53d1\u9001\u4e00\u4e2a\u5305\u4e4b\u524d\uff0c\u672c\u5730\u673a\u5668\u4f1a\u7b49\u5f85\u8fdc\u7a0b\u4e3b\u673a <\/FONT><\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN><\/SPAN><SPAN class=comment><FONT color=#008200>\/\/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u5bf9\u4e0a\u4e00\u6b21\u53d1\u9001\u7684\u5305\u7684\u786e\u8ba4\u4fe1\u606f\u5230\u6765\uff1b\u8fd9\u4e2a\u65b9\u6cd5\u5c31\u53ef\u4ee5\u5173\u95ed\u5957\u63a5\u5b57\u7684\u7f13\u5b58\uff0c <\/FONT><\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN><\/SPAN><SPAN class=comment><FONT color=#008200>\/\/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u4ee5\u81f3\u8fd9\u4e2a\u5305\u51c6\u5907\u597d\u4e86\u5c31\u53d1\uff1b <\/FONT><\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pool.setNagle(&nbsp;<\/SPAN><SPAN class=keyword><STRONG><FONT color=#7f0055>false<\/FONT><\/STRONG><\/SPAN><SPAN>&nbsp;);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=comment><FONT color=#008200>\/\/\u8fde\u63a5\u5efa\u7acb\u540e\u5bf9\u8d85\u65f6\u7684\u63a7\u5236 <\/FONT><\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pool.setSocketTO(&nbsp;<\/SPAN><SPAN class=number>3000<\/SPAN><SPAN>&nbsp;); &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=comment><FONT color=#008200>\/\/\u8fde\u63a5\u5efa\u7acb\u65f6\u5bf9\u8d85\u65f6\u7684\u63a7\u5236 <\/FONT><\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pool.setSocketConnectTO(&nbsp;<\/SPAN><SPAN class=number>0<\/SPAN><SPAN>&nbsp;);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=comment><FONT color=#008200>\/\/&nbsp;initialize&nbsp;the&nbsp;connection&nbsp;pool&nbsp;&nbsp;&nbsp; <\/FONT><\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=comment><FONT color=#008200>\/\/\u521d\u59cb\u5316\u4e00\u4e9b\u503c\u5e76\u4e0eMemcachedServer\u6bb5\u5efa\u7acb\u8fde\u63a5 <\/FONT><\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pool.initialize(); &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=comment><FONT color=#008200>\/\/&nbsp;lets&nbsp;set&nbsp;some&nbsp;compression&nbsp;on&nbsp;for&nbsp;the&nbsp;client&nbsp;&nbsp;&nbsp; <\/FONT><\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=comment><FONT color=#008200>\/\/&nbsp;compress&nbsp;anything&nbsp;larger&nbsp;than&nbsp;64k&nbsp;&nbsp;&nbsp; <\/FONT><\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mcc.setCompressEnable(&nbsp;<\/SPAN><SPAN class=keyword><STRONG><FONT color=#7f0055>true<\/FONT><\/STRONG><\/SPAN><SPAN>&nbsp;);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mcc.setCompressThreshold(&nbsp;<\/SPAN><SPAN class=number>64<\/SPAN><SPAN>&nbsp;*&nbsp;<\/SPAN><SPAN class=number>1024<\/SPAN><SPAN>&nbsp;);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=keyword><STRONG><FONT color=#7f0055>public<\/FONT><\/STRONG><\/SPAN><SPAN>&nbsp;<\/SPAN><SPAN class=keyword><STRONG><FONT color=#7f0055>static<\/FONT><\/STRONG><\/SPAN><SPAN>&nbsp;<\/SPAN><SPAN class=keyword><STRONG><FONT color=#7f0055>void<\/FONT><\/STRONG><\/SPAN><SPAN>&nbsp;bulidCache(){&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=comment><FONT color=#008200>\/\/set(key,value,Date)&nbsp;,Date\u662f\u4e00\u4e2a\u8fc7\u671f\u65f6\u95f4\uff0c\u5982\u679c\u60f3\u8ba9\u8fd9\u4e2a\u8fc7\u671f\u65f6\u95f4\u751f\u6548\u7684\u8bdd\uff0c\u8fd9\u91cc\u4f20\u9012\u7684new&nbsp;Date(long&nbsp;date)&nbsp;\u4e2d\u53c2\u6570date\uff0c\u9700\u8981\u662f\u4e2a\u5927\u4e8e\u6216\u7b49\u4e8e1000\u7684\u503c\u3002 <\/FONT><\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=comment><FONT color=#008200>\/\/\u56e0\u4e3ajava&nbsp;client\u7684\u5b9e\u73b0\u6e90\u7801\u91cc\u662f\u8fd9\u6837\u5b9e\u73b0\u7684&nbsp;expiry.getTime()&nbsp;\/&nbsp;1000&nbsp;\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c&nbsp;\u5c0f\u4e8e1000\u7684\u503c\uff0c\u9664\u4ee51000\u4ee5\u540e\u90fd\u662f0\uff0c\u5373\u6c38\u4e0d\u8fc7\u671f <\/FONT><\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mcc.set(&nbsp;<\/SPAN><SPAN class=string><FONT color=#0000ff>&#8220;test&#8221;<\/FONT><\/SPAN><SPAN>,&nbsp;<\/SPAN><SPAN class=string><FONT color=#0000ff>&#8220;This&nbsp;is&nbsp;a&nbsp;test&nbsp;String&#8221;<\/FONT><\/SPAN><SPAN>&nbsp;,<\/SPAN><SPAN class=keyword><STRONG><FONT color=#7f0055>new<\/FONT><\/STRONG><\/SPAN><SPAN>&nbsp;Date(<\/SPAN><SPAN class=number>10000<\/SPAN><SPAN>));&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=comment><FONT color=#008200>\/\/\u5341\u79d2\u540e\u8fc7\u671f <\/FONT><\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=keyword><STRONG><FONT color=#7f0055>public<\/FONT><\/STRONG><\/SPAN><SPAN>&nbsp;<\/SPAN><SPAN class=keyword><STRONG><FONT color=#7f0055>static<\/FONT><\/STRONG><\/SPAN><SPAN>&nbsp;<\/SPAN><SPAN class=keyword><STRONG><FONT color=#7f0055>void<\/FONT><\/STRONG><\/SPAN><SPAN>&nbsp;output()&nbsp;{&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=comment><FONT color=#008200>\/\/\u4ececache\u91cc\u53d6\u503c <\/FONT><\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;value&nbsp;=&nbsp;(String)&nbsp;mcc.get(&nbsp;<\/SPAN><SPAN class=string><FONT color=#0000ff>&#8220;test&#8221;<\/FONT><\/SPAN><SPAN>&nbsp;);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(value);&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN class=keyword><STRONG><FONT color=#7f0055>public<\/FONT><\/STRONG><\/SPAN><SPAN>&nbsp;<\/SPAN><SPAN class=keyword><STRONG><FONT color=#7f0055>static<\/FONT><\/STRONG><\/SPAN><SPAN>&nbsp;<\/SPAN><SPAN class=keyword><STRONG><FONT color=#7f0055>void<\/FONT><\/STRONG><\/SPAN><SPAN>&nbsp;main(String[]&nbsp;args){&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bulidCache();&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;output();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=\"\"><SPAN>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN><br \/>\n<LI class=alt><SPAN>}&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<\/SPAN> <\/LI><\/OL><\/DIV><br \/>\n<P>&nbsp;<\/P><FONT face=Arial><br \/>\n<P><BR>\u8fd0\u884c\u8f93\u51fa\u503c\u4e3a:<\/P><br \/>\n<P><BR>This is a test String&nbsp;&nbsp; <\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>3.\u6ce8\u91ca\u6389buildCache();<\/P><br \/>\n<P>\u5341\u79d2\u540e\u8fd0\u884c\uff0c\u8f93\u51fa\u503c\u4e3a null<\/P><\/FONT><\/DIV><br \/>\n<DIV><\/DIV><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5229\u7528memcached java client\u4e00\u4e2a\u7b80\u5355\u7684\u5e94\u7528 1.memcached java client\u4e00\u4e2a\u5b9e\u73b0\u7684\u4e0b\u8f7d\u5730\u5740 http:\/\/www.whalin.com\/memcached\/#download2.&nbsp; \u5229\u7528memcached java client \u4e00\u4e2a\u7b80\u5355\u7684\u5e94\u7528 java \u4ee3\u7801 package&nbsp;com.danga.MemCached.test; &nbsp;&nbsp; &nbsp;&nbsp; import&nbsp;java.util.Date; &nbsp;&nbsp; &nbsp;&nbsp; import&nbsp;com.danga.MemCached.MemCachedClient; &nbsp;&nbsp; import&nbsp;com.danga.MemCached.SockIOPool; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; public&nbsp;class&nbsp;Test&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;static&nbsp;MemCachedClient&nbsp;mcc&nbsp;=&nbsp;new&nbsp;MemCachedClient();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;{&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String[]&nbsp;servers&nbsp;={&#8220;192.168.40.4:12000&#8221;};&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Integer[]&nbsp;weights&nbsp;=&nbsp;{&nbsp;3&nbsp;};&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u521b\u5efa\u4e00\u4e2a\u5b9e\u4f8b\u5bf9\u8c61SockIOPool&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SockIOPool&nbsp;pool&nbsp;=&nbsp;SockIOPool.getInstance();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;set&nbsp;the&nbsp;servers&nbsp;and&nbsp;the&nbsp;weights &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u8bbe\u7f6eMemcached&nbsp;Server &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pool.setServers(&nbsp;servers&nbsp;);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pool.setWeights(&nbsp;weights&nbsp;);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &hellip; <a href=\"https:\/\/www.strongd.net\/?p=535\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">\u5229\u7528memcached java client\u4e00\u4e2a\u7b80\u5355\u7684\u5e94\u7528<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,35,20],"tags":[34],"class_list":["post-535","post","type-post","status-publish","format-standard","hentry","category-linux","category-35","category-20","tag-memcached"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/535","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=535"}],"version-history":[{"count":1,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/535\/revisions"}],"predecessor-version":[{"id":835,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/535\/revisions\/835"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=535"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}