<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>smallfish logs &#187; Memcached</title>
	<atom:link href="http://chenxiaoyu.org/blog/archives/tag/memcached/feed" rel="self" type="application/rss+xml" />
	<link>http://chenxiaoyu.org</link>
	<description>关注 Python &#38; Go &#38; PostgreSQL</description>
	<lastBuildDate>Sat, 07 Aug 2010 10:31:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Memcached Java &amp;&amp; Python Client API 共享</title>
		<link>http://chenxiaoyu.org/blog/archives/114</link>
		<comments>http://chenxiaoyu.org/blog/archives/114#comments</comments>
		<pubDate>Tue, 15 Dec 2009 01:24:22 +0000</pubDate>
		<dc:creator>smallfish</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Memcached]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://chenxiaoyu.org/blog/?p=114</guid>
		<description><![CDATA[用Python写了一个计划任务，定时更新Memcached中一个key值，写的很happy，几分钟搞定。
然后在Java Servlet测试，代码写的也很happy，编译 &#8211; 刷新，一气呵成。
然后发现值一直是null，再tail日志看看，异常不断：
com.danga.MemCached.MemCachedClient Mon Jul 20 09:37:04 CST 2009 - ++++ exception thrown while trying to get object from cache for key: test_num
 com.danga.MemCached.MemCachedClient Mon Jul 20 09:37:04 CST 2009 - 3
 com.danga.MemCached.NestedIOException: 3
 at com.danga.MemCached.MemCachedClient.get(MemCachedClient.java:1408)
 at com.danga.MemCached.MemCachedClient.get(MemCachedClient.java:1270)
晕倒，记得以前为了让两个语言实现API读写共享，手动去修改了两个的API包，实现了中文互读写。难不成今儿个还要手动去搞一把？
然后手动试了下：

shell&#62; telnet xxxxxx 11211
get test_num
VALUE test_num 4 2
23
经查证VALUE协议返回的是 key flags len \r\n value 这样的格式，大悟：原来flags不一样啊，Java里面对int型赋值以后flags是0，而Python里则不一样，两者序列化的东西不同啊。懒得去 折腾两者序列化有啥不同。来点直接的把。
然后打开Python Memcached API，大概578行_val_to_store_info方法里，可以看到flags部分，是根据变量类型进行定义的，isinstance(val, [...]]]></description>
			<content:encoded><![CDATA[<p>用Python写了一个计划任务，定时更新Memcached中一个key值，写的很happy，几分钟搞定。</p>
<p>然后在Java Servlet测试，代码写的也很happy，编译 &#8211; 刷新，一气呵成。</p>
<p>然后发现值一直是null，再tail日志看看，异常不断：</p>
<pre>com.danga.MemCached.MemCachedClient Mon Jul 20 09:37:04 CST 2009 - ++++ exception thrown while trying to get object from cache for key: test_num
 com.danga.MemCached.MemCachedClient Mon Jul 20 09:37:04 CST 2009 - 3
 com.danga.MemCached.NestedIOException: 3
 at com.danga.MemCached.MemCachedClient.get(MemCachedClient.java:1408)
 at com.danga.MemCached.MemCachedClient.get(MemCachedClient.java:1270)</pre>
<p>晕倒，记得以前为了让两个语言实现API读写共享，手动去修改了两个的API包，实现了中文互读写。难不成今儿个还要手动去搞一把？</p>
<p>然后手动试了下：</p>
<pre>
shell&gt; telnet xxxxxx 11211
get test_num
VALUE test_num 4 2
23</pre>
<p>经查证VALUE协议返回的是 key flags len \r\n value 这样的格式，大悟：原来flags不一样啊，Java里面对int型赋值以后flags是0，而Python里则不一样，两者序列化的东西不同啊。懒得去 折腾两者序列化有啥不同。来点直接的把。</p>
<p>然后打开Python Memcached API，大概578行_val_to_store_info方法里，可以看到flags部分，是根据变量类型进行定义的，isinstance(val, str) 如果是str则pass。</p>
<p>到这里就简单了，直接在py代码里：mc.set(&#8216;test_num&#8217;, str(num))</p>
<p>Java读取OK。</p>
<hr />
<p><small>© smallfish for <a href="http://chenxiaoyu.org">smallfish logs</a>, 2009. |
<a href="http://chenxiaoyu.org/blog/archives/114">Permalink</a> |
<a href="http://chenxiaoyu.org/blog/archives/114#comments">No comment</a> |
Add to
<a href="http://del.icio.us/post?url=http://chenxiaoyu.org/blog/archives/114&title=Memcached Java &#038;&#038; Python Client API 共享">del.icio.us</a>
<br/>
Post tags: <a href="http://chenxiaoyu.org/blog/archives/tag/java" rel="tag">Java</a>, <a href="http://chenxiaoyu.org/blog/archives/tag/memcached" rel="tag">Memcached</a>, <a href="http://chenxiaoyu.org/blog/archives/tag/python" rel="tag">Python</a><br/>
</small></p>
<p>
<script type="text/javascript"><!--
google_ad_client = "pub-8914011260472945";
/* 468x60, 创建于 09-11-19 */
google_ad_slot = "7198645178";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</p>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://chenxiaoyu.org/blog/archives/114/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSH Tunnel &amp;&amp; Memcached</title>
		<link>http://chenxiaoyu.org/blog/archives/103</link>
		<comments>http://chenxiaoyu.org/blog/archives/103#comments</comments>
		<pubDate>Tue, 15 Dec 2009 01:15:09 +0000</pubDate>
		<dc:creator>smallfish</dc:creator>
				<category><![CDATA[Memcached]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://chenxiaoyu.org/blog/?p=103</guid>
		<description><![CDATA[最近一台服务器放进了移动机房，需要访问原电信机房一台Memcached服务器，Memcached服务是以内网形式启动。
依靠google大神，搜索出解决思路，在本地起一个SSH链接，通过本地一个端口实现对另外机器的映射或者叫做转发。
上周本来已经搞定，本周突发灵异事件，竟然不管了，最后百般尝试，完成结果如下：
移动机器IP：220.xxx.xxx.xxx 电信机器IP：155.xxx.xxx.xxx
在移动机器上执行：
shell &#62; ssh -N -f -L 11211:192.168.0.xxx:11211 root@155.xxx.xxx.xxx
11211:192.168.0.xxx:11211，格式为：本地端口:memcache启动的IP:端口
这里没有用RSA认证，就直接输入密码。-N 是不需要shell，-f 是程序后台执行，其他参数参见ssh &#8211;help。
shell &#62; ps aux
可以看见进程已经在了，下面开始测试代码。

&#62;&#62;&#62; import memcache
&#62;&#62;&#62; mc = memcache.Client(['127.0.0.1:11211'],debug=True)
&#62;&#62;&#62; print mc.get('name')

© smallfish for smallfish logs, 2009. &#124;
Permalink &#124;
No comment &#124;
Add to
del.icio.us

Post tags: Memcached, SSH







Feed enhanced by Better Feed from  Ozh
]]></description>
			<content:encoded><![CDATA[<p>最近一台服务器放进了移动机房，需要访问原电信机房一台Memcached服务器，Memcached服务是以内网形式启动。</p>
<p>依靠google大神，搜索出解决思路，在本地起一个SSH链接，通过本地一个端口实现对另外机器的映射或者叫做转发。</p>
<p>上周本来已经搞定，本周突发灵异事件，竟然不管了，最后百般尝试，完成结果如下：</p>
<p>移动机器IP：220.xxx.xxx.xxx 电信机器IP：155.xxx.xxx.xxx</p>
<p>在移动机器上执行：</p>
<pre>shell &gt; ssh -N -f -L 11211:192.168.0.xxx:11211 root@155.xxx.xxx.xxx</pre>
<p>11211:192.168.0.xxx:11211，格式为：本地端口:memcache启动的IP:端口<br />
这里没有用RSA认证，就直接输入密码。-N 是不需要shell，-f 是程序后台执行，其他参数参见ssh &#8211;help。</p>
<pre>shell &gt; ps aux</pre>
<p>可以看见进程已经在了，下面开始测试代码。</p>
<pre>
&gt;&gt;&gt; import memcache
&gt;&gt;&gt; mc = memcache.Client(['127.0.0.1:11211'],debug=True)
&gt;&gt;&gt; print mc.get('name')</pre>
<hr />
<p><small>© smallfish for <a href="http://chenxiaoyu.org">smallfish logs</a>, 2009. |
<a href="http://chenxiaoyu.org/blog/archives/103">Permalink</a> |
<a href="http://chenxiaoyu.org/blog/archives/103#comments">No comment</a> |
Add to
<a href="http://del.icio.us/post?url=http://chenxiaoyu.org/blog/archives/103&title=SSH Tunnel &#038;&#038; Memcached">del.icio.us</a>
<br/>
Post tags: <a href="http://chenxiaoyu.org/blog/archives/tag/memcached" rel="tag">Memcached</a>, <a href="http://chenxiaoyu.org/blog/archives/tag/ssh" rel="tag">SSH</a><br/>
</small></p>
<p>
<script type="text/javascript"><!--
google_ad_client = "pub-8914011260472945";
/* 468x60, 创建于 09-11-19 */
google_ad_slot = "7198645178";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</p>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://chenxiaoyu.org/blog/archives/103/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
