<?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>Neo 时刻准备着</title>
	<atom:link href="http://neoremind.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://neoremind.net</link>
	<description>面对恐惧男人的战栗往往不是来自胆怯，而是极度的兴奋</description>
	<lastBuildDate>Mon, 14 May 2012 09:22:05 +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>应用系统常用性能指标</title>
		<link>http://neoremind.net/2012/05/%e5%ba%94%e7%94%a8%e7%b3%bb%e7%bb%9f%e5%b8%b8%e7%94%a8%e6%80%a7%e8%83%bd%e6%8c%87%e6%a0%87/</link>
		<comments>http://neoremind.net/2012/05/%e5%ba%94%e7%94%a8%e7%b3%bb%e7%bb%9f%e5%b8%b8%e7%94%a8%e6%80%a7%e8%83%bd%e6%8c%87%e6%a0%87/#comments</comments>
		<pubDate>Mon, 14 May 2012 09:22:05 +0000</pubDate>
		<dc:creator>neo</dc:creator>
				<category><![CDATA[系统]]></category>

		<guid isPermaLink="false">http://neoremind.net/?p=923</guid>
		<description><![CDATA[<strong>PV</strong>
PV是Page View的缩写。用户通过浏览器访问页面，对应用服务器产生的每一次请求，记为一个PV。可以将这个概念做了延伸，系统真实处理的一个请求，视为一个PV。即，PV的概念也适用于接口。PV的统计一般可以通过一些监控或者统计访问日志统计得出。说到PV还有个特殊的情况，叫PeakPV，指一天[......]<p class='read-more'><a href='http://neoremind.net/2012/05/%e5%ba%94%e7%94%a8%e7%b3%bb%e7%bb%9f%e5%b8%b8%e7%94%a8%e6%80%a7%e8%83%bd%e6%8c%87%e6%a0%87/'>继续阅读</a></p><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="Redis典型应用场景" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fredis%25E5%2585%25B8%25E5%259E%258B%25E5%25BA%2594%25E7%2594%25A8%25E5%259C%25BA%25E6%2599%25AF%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%25BA%2594%25E7%2594%25A8%25E7%25B3%25BB%25E7%25BB%259F%25E5%25B8%25B8%25E7%2594%25A8%25E6%2580%25A7%25E8%2583%25BD%25E6%258C%2587%25E6%25A0%2587%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Redis典型应用场景</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="分布式应用通信协议" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%2588%2586%25E5%25B8%2583%25E5%25BC%258F%25E5%25BA%2594%25E7%2594%25A8%25E9%2580%259A%25E4%25BF%25A1%25E5%258D%258F%25E8%25AE%25AE%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%25BA%2594%25E7%2594%25A8%25E7%25B3%25BB%25E7%25BB%259F%25E5%25B8%25B8%25E7%2594%25A8%25E6%2580%25A7%25E8%2583%25BD%25E6%258C%2587%25E6%25A0%2587%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">分布式应用通信协议</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Ajax与Jython结合的简单应用" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F02%2Fajax%25E4%25B8%258Ejython%25E7%25BB%2593%25E5%2590%2588%25E7%259A%2584%25E7%25AE%2580%25E5%258D%2595%25E5%25BA%2594%25E7%2594%25A8%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%25BA%2594%25E7%2594%25A8%25E7%25B3%25BB%25E7%25BB%259F%25E5%25B8%25B8%25E7%2594%25A8%25E6%2580%25A7%25E8%2583%25BD%25E6%258C%2587%25E6%25A0%2587%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/02/11/15256894.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Ajax与Jython结合的简单应用</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Shell中数组的应用" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F04%2Fshell%25E4%25B8%25AD%25E6%2595%25B0%25E7%25BB%2584%25E7%259A%2584%25E5%25BA%2594%25E7%2594%25A8%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%25BA%2594%25E7%2594%25A8%25E7%25B3%25BB%25E7%25BB%259F%25E5%25B8%25B8%25E7%2594%25A8%25E6%2580%25A7%25E8%2583%25BD%25E6%258C%2587%25E6%25A0%2587%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Shell中数组的应用</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="proc文件系统" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F02%2Fproc%25E6%2596%2587%25E4%25BB%25B6%25E7%25B3%25BB%25E7%25BB%259F%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%25BA%2594%25E7%2594%25A8%25E7%25B3%25BB%25E7%25BB%259F%25E5%25B8%25B8%25E7%2594%25A8%25E6%2580%25A7%25E8%2583%25BD%25E6%258C%2587%25E6%25A0%2587%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">proc文件系统</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<h3 style="color: red; "><strong>PV</strong></h3>
<div>PV是Page View的缩写。用户通过浏览器访问页面，对应用服务器产生的每一次请求，记为一个PV。可以将这个概念做了延伸，系统真实处理的一个请求，视为一个PV。即，PV的概念也适用于接口。PV的统计一般可以通过一些监控或者统计访问日志统计得出。说到PV还有个特殊的情况，叫PeakPV，指一天中 PV数达到的高峰PV值。</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<h3 style="color: red; "><strong>QPS/TPS</strong></h3>
<div>QPS是Queries Per Second的缩写，是一台服务器每秒能够响应的查询次数，是对一个特定的查询服务器在规定时间内所处理流量多少的衡量标准。我的理解QPS更趋向于&ldquo;读操作&rdquo;。</div>
<div>&nbsp;</div>
<div>TPS是Transactions PerSecond 的缩写，也就是每秒能够响应的事务次数。我的理解TPS更趋向于&ldquo;写操作&rdquo;。</div>
<div>&nbsp;</div>
<div>两个指标都能表示系统的吞吐量，一般还有一个Lantency的概念，表示延迟。</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<h3 style="color: red; "><strong>响应时间</strong></h3>
<div>响应时间(Response-time, RT)是指从客户端发一个请求开始计时，到客户端接收到从服务器端返回的响应结果结束所经历的时间，响应时间由请求发送时间、网络传输时间和服务器处理时间三部分组成。</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<h3 style="color: red; "><strong>其他性能指标</strong></h3>
<div>CPU_IDLE</div>
<div>IO读写情况（每秒多少KB）</div>
<div>内存使用情况（剩余多少内存，VM有多少）</div>
<div>&nbsp;</div>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="Redis典型应用场景" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fredis%25E5%2585%25B8%25E5%259E%258B%25E5%25BA%2594%25E7%2594%25A8%25E5%259C%25BA%25E6%2599%25AF%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%25BA%2594%25E7%2594%25A8%25E7%25B3%25BB%25E7%25BB%259F%25E5%25B8%25B8%25E7%2594%25A8%25E6%2580%25A7%25E8%2583%25BD%25E6%258C%2587%25E6%25A0%2587%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Redis典型应用场景</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="分布式应用通信协议" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%2588%2586%25E5%25B8%2583%25E5%25BC%258F%25E5%25BA%2594%25E7%2594%25A8%25E9%2580%259A%25E4%25BF%25A1%25E5%258D%258F%25E8%25AE%25AE%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%25BA%2594%25E7%2594%25A8%25E7%25B3%25BB%25E7%25BB%259F%25E5%25B8%25B8%25E7%2594%25A8%25E6%2580%25A7%25E8%2583%25BD%25E6%258C%2587%25E6%25A0%2587%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">分布式应用通信协议</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Ajax与Jython结合的简单应用" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F02%2Fajax%25E4%25B8%258Ejython%25E7%25BB%2593%25E5%2590%2588%25E7%259A%2584%25E7%25AE%2580%25E5%258D%2595%25E5%25BA%2594%25E7%2594%25A8%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%25BA%2594%25E7%2594%25A8%25E7%25B3%25BB%25E7%25BB%259F%25E5%25B8%25B8%25E7%2594%25A8%25E6%2580%25A7%25E8%2583%25BD%25E6%258C%2587%25E6%25A0%2587%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/02/11/15256894.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Ajax与Jython结合的简单应用</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Shell中数组的应用" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F04%2Fshell%25E4%25B8%25AD%25E6%2595%25B0%25E7%25BB%2584%25E7%259A%2584%25E5%25BA%2594%25E7%2594%25A8%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%25BA%2594%25E7%2594%25A8%25E7%25B3%25BB%25E7%25BB%259F%25E5%25B8%25B8%25E7%2594%25A8%25E6%2580%25A7%25E8%2583%25BD%25E6%258C%2587%25E6%25A0%2587%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Shell中数组的应用</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="proc文件系统" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F02%2Fproc%25E6%2596%2587%25E4%25BB%25B6%25E7%25B3%25BB%25E7%25BB%259F%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%25BA%2594%25E7%2594%25A8%25E7%25B3%25BB%25E7%25BB%259F%25E5%25B8%25B8%25E7%2594%25A8%25E6%2580%25A7%25E8%2583%25BD%25E6%258C%2587%25E6%25A0%2587%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">proc文件系统</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://neoremind.net/2012/05/%e5%ba%94%e7%94%a8%e7%b3%bb%e7%bb%9f%e5%b8%b8%e7%94%a8%e6%80%a7%e8%83%bd%e6%8c%87%e6%a0%87/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Is memcached a dinosaur in comparison to Redis?</title>
		<link>http://neoremind.net/2012/05/is-memcached-a-dinosaur-in-comparison-to-redis/</link>
		<comments>http://neoremind.net/2012/05/is-memcached-a-dinosaur-in-comparison-to-redis/#comments</comments>
		<pubDate>Sun, 13 May 2012 07:02:24 +0000</pubDate>
		<dc:creator>neo</dc:creator>
				<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[Redis]]></category>

		<guid isPermaLink="false">http://neoremind.net/?p=921</guid>
		<description><![CDATA[下面内容来自Redis作者在stackoverflow上的一个回答，对应的问题是《Is memcached a dinosaur in comparison to Redis?》（相比Redis，Memcached真的过时了吗？）
&#160;
You should not care too muc[......]<p class='read-more'><a href='http://neoremind.net/2012/05/is-memcached-a-dinosaur-in-comparison-to-redis/'>继续阅读</a></p><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="Redis典型应用场景" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fredis%25E5%2585%25B8%25E5%259E%258B%25E5%25BA%2594%25E7%2594%25A8%25E5%259C%25BA%25E6%2599%25AF%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fis-memcached-a-dinosaur-in-comparison-to-redis%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Redis典型应用场景</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="[转]Redis几个认识误区" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E8%25BD%25ACredis%25E5%2587%25A0%25E4%25B8%25AA%25E8%25AE%25A4%25E8%25AF%2586%25E8%25AF%25AF%25E5%258C%25BA%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fis-memcached-a-dinosaur-in-comparison-to-redis%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">[转]Redis几个认识误区</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="查看memcached运行状态" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F02%2F%25E6%259F%25A5%25E7%259C%258Bmemcached%25E8%25BF%2590%25E8%25A1%258C%25E7%258A%25B6%25E6%2580%2581%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fis-memcached-a-dinosaur-in-comparison-to-redis%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">查看memcached运行状态</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="mongodb学习笔记" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fmongodb%25E5%25AD%25A6%25E4%25B9%25A0%25E7%25AC%2594%25E8%25AE%25B0%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fis-memcached-a-dinosaur-in-comparison-to-redis%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">mongodb学习笔记</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Dojo实现Ajax之提交表单与异常处理" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F03%2Fdojo%25E5%25AE%259E%25E7%258E%25B0ajax%25E4%25B9%258B%25E6%258F%2590%25E4%25BA%25A4%25E8%25A1%25A8%25E5%258D%2595%25E4%25B8%258E%25E5%25BC%2582%25E5%25B8%25B8%25E5%25A4%2584%25E7%2590%2586%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fis-memcached-a-dinosaur-in-comparison-to-redis%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/02/11/15256328.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Dojo实现Ajax之提交表单与异常处理</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<div>下面内容来自Redis作者在stackoverflow上的一个回答，对应的问题是《Is memcached a dinosaur in comparison to Redis?》（相比Redis，Memcached真的过时了吗？）</div>
<div>&nbsp;</div>
<div>You should not care too much about performances. Redis is faster per core with small values, but memcached is able to use multiple cores with a single executable and TCP port without help from the client. Also memcached is faster with big values in the order of 100k. Redis recently improved a lot about big values (unstable branch) but still memcached is faster in this use case. The point here is: nor one or the other will likely going to be your bottleneck for the query-per-second they can deliver.</div>
<div>没有必要过多的关心性能，因为二者的性能都已经足够高了。由于Redis只使用单核，而Memcached可以使用多核，所以在比较上，平均每一个核上Redis在存储小数据时比Memcached性能更高。而在100k以上的数据中，Memcached性能要高于Redis，虽然Redis最近也在存储大数据的性能上进行优化，但是比起Memcached，还是稍有逊色。说了这么多，结论是，无论你使用哪一个，每秒处理请求的次数都不会成为瓶颈。（比如瓶颈可能会在网卡）</div>
<div>&nbsp;</div>
<div>You should care about memory usage. For simple key-value pairs memcached is more memory efficient. If you use Redis hashes, Redis is more memory efficient. Depends on the use case.</div>
<div>如果要说内存使用效率，使用简单的key-value存储的话，Memcached的内存利用率更高，而如果Redis采用hash结构来做key-value存储，由于其组合式的压缩，其内存利用率会高于Memcached。当然，这和你的应用场景和数据特性有关。</div>
<div>&nbsp;</div>
<div>You should care about persistence and replication, two features only available in Redis. Even if your goal is to build a cache it helps that after an upgrade or a reboot your data are still there.</div>
<div>如果你对数据持久化和数据同步有所要求，那么推荐你选择Redis，因为这两个特性Memcached都不具备。即使你只是希望在升级或者重启系统后缓存数据不会丢失，选择Redis也是明智的。</div>
<div>&nbsp;</div>
<div>You should care about the kind of operations you need. In Redis there are a lot of complex operations, even just considering the caching use case, you often can do a lot more in a single operation, without requiring data to be processed client side (a lot of I/O is sometimes needed). This operations are often as fast as plain GET and SET. So if you don&rsquo;t need just GEt/SET but more complex things Redis can help a lot (think at timeline caching).</div>
<div>当然，最后还得说到你的具体应用需求。Redis相比Memcached来说，拥有更多的数据结构和并支持更丰富的数据操作，通常在Memcached里，你需要将数据拿到客户端来进行类似的修改再set回去。这大大增加了网络IO的次数和数据体积。在Redis中，这些复杂的操作通常和一般的GET/SET一样高效。所以，如果你需要缓存能够支持更复杂的结构和操作，那么Redis会是不错的选择。</div>
<div>&nbsp;</div>
<div>转自<a href="http://blog.nosqlfan.com/html/3729.html" target="_blank">NoSQLFan</a></div>
<div>&nbsp;</div>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="Redis典型应用场景" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fredis%25E5%2585%25B8%25E5%259E%258B%25E5%25BA%2594%25E7%2594%25A8%25E5%259C%25BA%25E6%2599%25AF%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fis-memcached-a-dinosaur-in-comparison-to-redis%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Redis典型应用场景</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="[转]Redis几个认识误区" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E8%25BD%25ACredis%25E5%2587%25A0%25E4%25B8%25AA%25E8%25AE%25A4%25E8%25AF%2586%25E8%25AF%25AF%25E5%258C%25BA%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fis-memcached-a-dinosaur-in-comparison-to-redis%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">[转]Redis几个认识误区</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="查看memcached运行状态" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F02%2F%25E6%259F%25A5%25E7%259C%258Bmemcached%25E8%25BF%2590%25E8%25A1%258C%25E7%258A%25B6%25E6%2580%2581%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fis-memcached-a-dinosaur-in-comparison-to-redis%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">查看memcached运行状态</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="mongodb学习笔记" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fmongodb%25E5%25AD%25A6%25E4%25B9%25A0%25E7%25AC%2594%25E8%25AE%25B0%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fis-memcached-a-dinosaur-in-comparison-to-redis%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">mongodb学习笔记</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="利用RAD开发JAX-RPC标准的Webservice" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F03%2F%25E5%2588%25A9%25E7%2594%25A8rad%25E5%25BC%2580%25E5%258F%2591jax-rpc%25E6%25A0%2587%25E5%2587%2586%25E7%259A%2584webservice%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fis-memcached-a-dinosaur-in-comparison-to-redis%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/02/11/15257223.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">利用RAD开发JAX-RPC标准的Webservice</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://neoremind.net/2012/05/is-memcached-a-dinosaur-in-comparison-to-redis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[转]Redis几个认识误区</title>
		<link>http://neoremind.net/2012/05/%e8%bd%acredis%e5%87%a0%e4%b8%aa%e8%ae%a4%e8%af%86%e8%af%af%e5%8c%ba/</link>
		<comments>http://neoremind.net/2012/05/%e8%bd%acredis%e5%87%a0%e4%b8%aa%e8%ae%a4%e8%af%86%e8%af%af%e5%8c%ba/#comments</comments>
		<pubDate>Sat, 12 May 2012 11:45:33 +0000</pubDate>
		<dc:creator>neo</dc:creator>
				<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[Redis]]></category>

		<guid isPermaLink="false">http://neoremind.net/?p=917</guid>
		<description><![CDATA[<strong>1. Redis介绍</strong>
这个问题的结果影响了我们怎么用Redis。如果你认为Redis是一个<strong>key value store</strong>, 那可能会用它来代替MySQL；如果认为它是一个<strong>可持久化的cache,</strong> 可能只是它保存一些频繁访问的临时数据。Redis是<strong>REmote DIctionary Server</strong>的缩写，[......]<p class='read-more'><a href='http://neoremind.net/2012/05/%e8%bd%acredis%e5%87%a0%e4%b8%aa%e8%ae%a4%e8%af%86%e8%af%af%e5%8c%ba/'>继续阅读</a></p><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="Is memcached a dinosaur in comparison to Redis?" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fis-memcached-a-dinosaur-in-comparison-to-redis%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E8%25BD%25ACredis%25E5%2587%25A0%25E4%25B8%25AA%25E8%25AE%25A4%25E8%25AF%2586%25E8%25AF%25AF%25E5%258C%25BA%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Is memcached a dinosaur in comparison to Redis?</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Redis典型应用场景" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fredis%25E5%2585%25B8%25E5%259E%258B%25E5%25BA%2594%25E7%2594%25A8%25E5%259C%25BA%25E6%2599%25AF%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E8%25BD%25ACredis%25E5%2587%25A0%25E4%25B8%25AA%25E8%25AE%25A4%25E8%25AF%2586%25E8%25AF%25AF%25E5%258C%25BA%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Redis典型应用场景</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="mongodb学习笔记" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fmongodb%25E5%25AD%25A6%25E4%25B9%25A0%25E7%25AC%2594%25E8%25AE%25B0%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E8%25BD%25ACredis%25E5%2587%25A0%25E4%25B8%25AA%25E8%25AE%25A4%25E8%25AF%2586%25E8%25AF%25AF%25E5%258C%25BA%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">mongodb学习笔记</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="利用Tivoli Storage Manager做系统备份" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F04%2F%25E5%2588%25A9%25E7%2594%25A8tivoli-storage-manager%25E5%2581%259A%25E7%25B3%25BB%25E7%25BB%259F%25E5%25A4%2587%25E4%25BB%25BD%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E8%25BD%25ACredis%25E5%2587%25A0%25E4%25B8%25AA%25E8%25AE%25A4%25E8%25AF%2586%25E8%25AF%25AF%25E5%258C%25BA%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/02/11/15257142.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">利用Tivoli Storage Manager做系统备份</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="异步消息处理的办法——MDB" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F03%2F%25E5%25BC%2582%25E6%25AD%25A5%25E6%25B6%2588%25E6%2581%25AF%25E5%25A4%2584%25E7%2590%2586%25E7%259A%2584%25E5%258A%259E%25E6%25B3%2595%25E2%2580%2594%25E2%2580%2594mdb%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E8%25BD%25ACredis%25E5%2587%25A0%25E4%25B8%25AA%25E8%25AE%25A4%25E8%25AF%2586%25E8%25AF%25AF%25E5%258C%25BA%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/02/11/15256767.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">异步消息处理的办法——MDB</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p><strong>1. Redis介绍</strong></p>
<div>这个问题的结果影响了我们怎么用Redis。如果你认为Redis是一个<strong>key value store</strong>, 那可能会用它来代替MySQL；如果认为它是一个<strong>可持久化的cache,</strong> 可能只是它保存一些频繁访问的临时数据。Redis是<strong>REmote DIctionary Server</strong>的缩写，在Redis在官方网站的的副标题是<span style="color: rgb(0, 0, 255); "><strong><span style="font-size: larger; ">A persistent key-value database with built-in net interface written in ANSI-C for Posix systems</span></strong></span>，这个定义偏向key value store。还有一些看法则认为Redis是一个<strong>memory database</strong>，因为它的高性能都是基于内存操作的基础。另外一些人则认为Redis是一个<strong>data structure server</strong>，因为Redis支持复杂的数据特性，比如List, Set等。对Redis的作用的不同解读决定了你对Redis的使用方式。</div>
<div>&nbsp;</div>
<div>互联网数据目前基本使用两种方式来存储，关系数据库或者key value。但是这些互联网业务本身并不属于这两种数据类型，比如用户在社会化平台中的关系，它是一个list，如果要用关系数据库存储就需要转换成一种多行记录的形式，这种形式存在很多冗余数据，每一行需要存储一些重复信息。如果用key value存储则修改和删除比较麻烦，需要将全部数据读出再写入。Redis在内存中设计了各种数据类型，<strong>让业务能够高速原子的访问这些数据结构，并且不需要关心持久存储的问题</strong>，从架构上解决了前面两种存储需要走一些弯路的问题。</div>
<div>&nbsp;</div>
<div>其实，简单理解 <span style="font-size: larger; "><strong><span style="color: rgb(0, 0, 255); ">redis = 高性能网络接口 + 数据结构集合</span></strong></span></div>
<div>&nbsp;</div>
<div>Redis的高性能网络接口采用单线程IO复用来开发，采用aeEvent机制，默认支持1万的连接(1024*10)，之所以不采用多线程是引入锁带来的复杂性。</div>
<div>&nbsp;</div>
<div>Redis数据类型包括：</div>
<div>string</div>
<div>hash</div>
<div>list</div>
<div>set</div>
<div>sorted set（zset）</div>
<div>&nbsp;</div>
<div><strong>2. Redis不可能比Memcache快</strong></div>
<div>很多开发者都认为Redis不可能比Memcached快，Memcached完全基于内存，而Redis具有持久化保存特性，即使是异步的，Redis也不可能比Memcached快。但是测试结果基本是Redis占绝对优势。一直在思考这个原因，目前想到的原因有这几方面。</div>
<div>&nbsp;</div>
<div>Libevent。和Memcached不同，Redis并没有选择libevent。Libevent为了迎合通用性造成代码庞大(目前Redis代码还不到libevent的1/3)及牺牲了在特定平台的不少性能。Redis用libevent中两个文件修改实现了自己的epoll event loop(4)。业界不少开发者也建议Redis使用另外一个libevent高性能替代libev，但是作者还是坚持Redis应该小巧并去依赖的思路。一个印象深刻的细节是编译Redis之前并不需要执行./configure。</div>
<div>&nbsp;</div>
<div>CAS问题。CAS是Memcached中比较方便的一种防止竞争修改资源的方法。CAS实现需要为每个cache key设置一个隐藏的cas token，cas相当value版本号，每次set会token需要递增，因此带来CPU和内存的双重开销，虽然这些开销很小，但是到单机10G+ cache以及QPS上万之后这些开销就会给双方相对带来一些细微性能差别(5)。</div>
<div>&nbsp;</div>
<div><strong>3. 单台Redis的存放数据必须比物理内存小</strong></div>
<div>Redis的数据全部放在内存带来了高速的性能，但是也带来一些不合理之处。比如一个中型网站有100万注册用户，如果这些资料要用Redis来存储，内存的容量必须能够容纳这100万用户。但是业务实际情况是100万用户只有5万活跃用户，1周来访问过1次的也只有15万用户，因此全部100万用户的数据都放在内存有不合理之处，RAM需要为冷数据买单。</div>
<div>&nbsp;</div>
<div>这跟操作系统非常相似，操作系统所有应用访问的数据都在内存，但是如果物理内存容纳不下新的数据，操作系统会智能将部分长期没有访问的数据交换到磁盘，为新的应用留出空间。现代操作系统给应用提供的并不是物理内存，而是虚拟内存(Virtual Memory)的概念。</div>
<div>&nbsp;</div>
<div>基于相同的考虑，Redis 2.0也增加了VM特性。让Redis数据容量突破了物理内存的限制。并实现了<strong>数据冷热分离</strong>。</div>
<div>&nbsp;</div>
<div>但是目前据使用过redis2.0.2, 发现当vm模式打开的时候, 并发连接数在1500以上时, redis latency会大大增加.平均每个请求的latency会超过4000ms, 观察redis的进程cpu占用率, 会超过100%. 最后迫于无奈,关掉了redis的vm功能. 此时并发连接不变的情况下,redis的latency下降到2ms以下. cpu占用率下降到1%.没有深入研究过这个症状,但初步怀疑是redis的vm实现有点不靠谱.</div>
<div>&nbsp;</div>
<div><strong>4. Redis的VM实现是重复造轮子</strong></div>
<div>Redis的VM依照之前的epoll实现思路依旧是自己实现。但是在前面操作系统的介绍提到OS也可以自动帮程序实现冷热数据分离，Redis只需要OS申请一块大内存，OS会自动将热数据放入物理内存，冷数据交换到硬盘，另外一个知名的&ldquo;理解了现代操作系统(3)&rdquo;的Varnish就是这样实现，也取得了非常成功的效果。</div>
<div>&nbsp;</div>
<div>作者antirez在解释为什么要自己实现VM中提到几个原因(6)。主要OS的VM换入换出是基于Page概念，比如OS VM1个Page是4K, 4K中只要还有一个元素即使只有1个字节被访问，这个页也不会被SWAP, 换入也同样道理，读到一个字节可能会换入4K无用的内存。而Redis自己实现则可以达到控制换入的粒度。另外访问操作系统SWAP内存区域时block进程，也是导致Redis要自己实现VM原因之一。</div>
<div>&nbsp;</div>
<div><strong>5. 用get/set方式使用Redis</strong></div>
<div>作为一个key value存在，很多开发者自然的使用set/get方式来使用Redis，实际上这并不是最优化的使用方法。尤其在未启用VM情况下，Redis全部数据需要放入内存，节约内存尤其重要。</div>
<div>&nbsp;</div>
<div>假如一个key-value单元需要最小占用512字节，即使只存一个字节也占了512字节。这时候就有一个设计模式，可以把key复用，几个key-value放入一个key中，value再作为一个set存入，这样同样512字节就会存放10-100倍的容量。</div>
<div>&nbsp;</div>
<div>这就是为了节约内存，建议使用hashset而不是set/get的方式来使用Redis，详细方法见参考文献(7)。</div>
<div>&nbsp;</div>
<div><strong>6. 使用aof代替snapshot</strong></div>
<div>Redis有两种存储方式，默认是snapshot方式，实现方法是定时将内存的快照(snapshot)持久化到硬盘，这种方法缺点是持久化之后如果出现crash则会丢失一段数据。因此在完美主义者的推动下作者增加了aof方式。aof即append only mode，在写入内存数据的同时将操作命令保存到日志文件，在一个并发更改上万的系统中，命令日志是一个非常庞大的数据，管理维护成本非常高，恢复重建时间会非常长，这样导致失去aof高可用性本意。另外更重要的是Redis是一个内存数据结构模型，所有的优势都是建立在对内存复杂数据结构高效的原子操作上，这样就看出aof是一个非常不协调的部分。</div>
<div>&nbsp;</div>
<div>其实aof目的主要是数据可靠性及高可用性，在Redis中有另外一种方法来达到目的：Replication。由于Redis的高性能，复制基本没有延迟。这样达到了防止单点故障及实现了高可用。</div>
<div>&nbsp;</div>
<div><strong>小结</strong></div>
<div>要想成功使用一种产品，我们需要深入了解它的特性。Redis性能突出，如果能够熟练的驾驭，对国内很多大型应用具有很大帮助。希望更多同行加入到Redis使用及代码研究行列。</div>
<div>&nbsp;</div>
<div>转自<a href="http://timyang.net/data/redis-misunderstanding/" target="_blank">Tim[后端技术]</a>&nbsp;+ 自己加工下介绍与vm部分。</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<p>&nbsp;</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="Is memcached a dinosaur in comparison to Redis?" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fis-memcached-a-dinosaur-in-comparison-to-redis%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E8%25BD%25ACredis%25E5%2587%25A0%25E4%25B8%25AA%25E8%25AE%25A4%25E8%25AF%2586%25E8%25AF%25AF%25E5%258C%25BA%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Is memcached a dinosaur in comparison to Redis?</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Redis典型应用场景" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fredis%25E5%2585%25B8%25E5%259E%258B%25E5%25BA%2594%25E7%2594%25A8%25E5%259C%25BA%25E6%2599%25AF%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E8%25BD%25ACredis%25E5%2587%25A0%25E4%25B8%25AA%25E8%25AE%25A4%25E8%25AF%2586%25E8%25AF%25AF%25E5%258C%25BA%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Redis典型应用场景</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="mongodb学习笔记" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fmongodb%25E5%25AD%25A6%25E4%25B9%25A0%25E7%25AC%2594%25E8%25AE%25B0%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E8%25BD%25ACredis%25E5%2587%25A0%25E4%25B8%25AA%25E8%25AE%25A4%25E8%25AF%2586%25E8%25AF%25AF%25E5%258C%25BA%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">mongodb学习笔记</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="利用RAD开发JAX-RPC标准的Webservice" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F03%2F%25E5%2588%25A9%25E7%2594%25A8rad%25E5%25BC%2580%25E5%258F%2591jax-rpc%25E6%25A0%2587%25E5%2587%2586%25E7%259A%2584webservice%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E8%25BD%25ACredis%25E5%2587%25A0%25E4%25B8%25AA%25E8%25AE%25A4%25E8%25AF%2586%25E8%25AF%25AF%25E5%258C%25BA%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/02/11/15257223.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">利用RAD开发JAX-RPC标准的Webservice</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="设计模式学习总结-模板模式" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F07%2Fdesignpattern_template_%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E8%25BD%25ACredis%25E5%2587%25A0%25E4%25B8%25AA%25E8%25AE%25A4%25E8%25AF%2586%25E8%25AF%25AF%25E5%258C%25BA%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/02/11/15257192.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">设计模式学习总结-模板模式</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://neoremind.net/2012/05/%e8%bd%acredis%e5%87%a0%e4%b8%aa%e8%ae%a4%e8%af%86%e8%af%af%e5%8c%ba/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redis典型应用场景</title>
		<link>http://neoremind.net/2012/05/redis%e5%85%b8%e5%9e%8b%e5%ba%94%e7%94%a8%e5%9c%ba%e6%99%af/</link>
		<comments>http://neoremind.net/2012/05/redis%e5%85%b8%e5%9e%8b%e5%ba%94%e7%94%a8%e5%9c%ba%e6%99%af/#comments</comments>
		<pubDate>Sat, 12 May 2012 11:25:39 +0000</pubDate>
		<dc:creator>neo</dc:creator>
				<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[Redis]]></category>

		<guid isPermaLink="false">http://neoremind.net/?p=915</guid>
		<description><![CDATA[毫无疑问，Redis开创了一种新的数据存储思路，使用Redis，我们不用在面对功能单调的数据库时，<strong>把精力放在如何把大象放进冰箱这样的问题上，而是利用Redis灵活多变的数据结构和数据操作，为不同的大象构建不同的冰箱</strong>。希望你喜欢这个比喻。
&#160;
下面是一篇新鲜出炉的文章，其作者是Redis作者[......]<p class='read-more'><a href='http://neoremind.net/2012/05/redis%e5%85%b8%e5%9e%8b%e5%ba%94%e7%94%a8%e5%9c%ba%e6%99%af/'>继续阅读</a></p><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="[转]Redis几个认识误区" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E8%25BD%25ACredis%25E5%2587%25A0%25E4%25B8%25AA%25E8%25AE%25A4%25E8%25AF%2586%25E8%25AF%25AF%25E5%258C%25BA%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fredis%25E5%2585%25B8%25E5%259E%258B%25E5%25BA%2594%25E7%2594%25A8%25E5%259C%25BA%25E6%2599%25AF%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">[转]Redis几个认识误区</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Is memcached a dinosaur in comparison to Redis?" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fis-memcached-a-dinosaur-in-comparison-to-redis%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fredis%25E5%2585%25B8%25E5%259E%258B%25E5%25BA%2594%25E7%2594%25A8%25E5%259C%25BA%25E6%2599%25AF%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Is memcached a dinosaur in comparison to Redis?</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="mongodb学习笔记" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fmongodb%25E5%25AD%25A6%25E4%25B9%25A0%25E7%25AC%2594%25E8%25AE%25B0%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fredis%25E5%2585%25B8%25E5%259E%258B%25E5%25BA%2594%25E7%2594%25A8%25E5%259C%25BA%25E6%2599%25AF%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">mongodb学习笔记</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="应用系统常用性能指标" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%25BA%2594%25E7%2594%25A8%25E7%25B3%25BB%25E7%25BB%259F%25E5%25B8%25B8%25E7%2594%25A8%25E6%2580%25A7%25E8%2583%25BD%25E6%258C%2587%25E6%25A0%2587%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fredis%25E5%2585%25B8%25E5%259E%258B%25E5%25BA%2594%25E7%2594%25A8%25E5%259C%25BA%25E6%2599%25AF%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">应用系统常用性能指标</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="分布式应用通信协议" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%2588%2586%25E5%25B8%2583%25E5%25BC%258F%25E5%25BA%2594%25E7%2594%25A8%25E9%2580%259A%25E4%25BF%25A1%25E5%258D%258F%25E8%25AE%25AE%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fredis%25E5%2585%25B8%25E5%259E%258B%25E5%25BA%2594%25E7%2594%25A8%25E5%259C%25BA%25E6%2599%25AF%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">分布式应用通信协议</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>毫无疑问，Redis开创了一种新的数据存储思路，使用Redis，我们不用在面对功能单调的数据库时，<strong>把精力放在如何把大象放进冰箱这样的问题上，而是利用Redis灵活多变的数据结构和数据操作，为不同的大象构建不同的冰箱</strong>。希望你喜欢这个比喻。</p>
<p>&nbsp;</p>
<div>下面是一篇新鲜出炉的文章，其作者是Redis作者@antirez，他描述了Redis比较适合的一些应用场景：</div>
<div>&nbsp;</div>
<div><strong>1.取最新N个数据的操作</strong></div>
<div>比如典型的取你网站的最新文章，通过下面方式，我们可以将最新的5000条评论的ID放在Redis的List集合中，并将超出集合部分从数据库获取</div>
<div>使用LPUSH latest.comments&lt;ID&gt;命令，向list集合中插入数据</div>
<div>插入完成后再用LTRIM latest.comments 0 5000命令使其永远只保存最近5000个ID</div>
<div>然后我们在客户端获取某一页评论时可以用下面的逻辑（伪代码）</div>
<div>FUNCTION get_latest_comments(start,num_items):</div>
<div>&nbsp; &nbsp; id_list = redis.lrange(&quot;latest.comments&quot;,start,start+num_items-1)</div>
<div>&nbsp; &nbsp; IF id_list.length &lt; num_items</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; id_list = SQL_DB(&quot;SELECT &#8230; ORDER BY time LIMIT &#8230;&quot;)</div>
<div>&nbsp; &nbsp; END</div>
<div>&nbsp; &nbsp; RETURN id_list</div>
<div>END</div>
<div>如果你还有不同的筛选维度，比如某个分类的最新N条，那么你可以再建一个按此分类的List，只存ID的话，Redis是非常高效的。</div>
<div>&nbsp;</div>
<div><strong>2.排行榜应用，取TOP N操作</strong></div>
<div>这个需求与上面需求的不同之处在于，前面操作以时间为权重，这个是以某个条件为权重，比如按顶的次数排序，这时候就需要我们的sorted set出马了，将你要排序的值设置成sorted set的score，将具体的数据设置成相应的value，每次只需要执行一条ZADD命令即可。</div>
<div>&nbsp;</div>
<div><strong>3.需要精准设定过期时间的应用</strong></div>
<div>比如你可以把上面说到的sorted set的score值设置成过期时间的时间戳，那么就可以简单地通过过期时间排序，定时清除过期数据了，不仅是清除Redis中的过期数据，你完全可以把Redis里这个过期时间当成是对数据库中数据的索引，用Redis来找出哪些数据需要过期删除，然后再精准地从数据库中删除相应的记录。</div>
<div>&nbsp;</div>
<div><strong>4.计数器应用</strong></div>
<div>Redis的命令都是原子性的，你可以轻松地利用INCR，DECR命令来构建计数器系统。</div>
<div>&nbsp;</div>
<div><strong>5.Uniq操作，获取某段时间所有数据排重值</strong></div>
<div>这个使用Redis的set数据结构最合适了，只需要不断地将数据往set中扔就行了，set意为集合，所以会自动排重。</div>
<div>&nbsp;</div>
<div><strong>6.实时系统，反垃圾系统</strong></div>
<div>通过上面说到的set功能，你可以知道一个终端用户是否进行了某个操作，可以找到其操作的集合并进行分析统计对比等。没有做不到，只有想不到。</div>
<div>&nbsp;</div>
<div><strong>7.Pub/Sub构建实时消息系统</strong></div>
<div>Redis的Pub/Sub系统可以构建实时的消息系统，比如很多用Pub/Sub构建的实时聊天系统的例子。</div>
<div>&nbsp;</div>
<div><strong>8.构建队列系统</strong></div>
<div>使用list可以构建队列系统，使用sorted set甚至可以构建有优先级的队列系统。</div>
<div>&nbsp;</div>
<div><strong>9.缓存</strong></div>
<div>这个不必说了，性能优于Memcached，数据结构更多样化。这里介绍补充一种架构：<span style="font-size: larger; "><strong><span style="color: rgb(0, 0, 255); ">异构读写分离</span></strong></span></div>
<div><img src="http://neoremind.net/wp-content/uploads/image/2012-5-12%2019-39-32.png" alt="" /></div>
<div>&nbsp;</div>
<div>转自<a href="http://blog.nosqlfan.com/html/2235.html" target="_blank">NoSQLFan</a></div>
<div>&nbsp;</div>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="[转]Redis几个认识误区" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E8%25BD%25ACredis%25E5%2587%25A0%25E4%25B8%25AA%25E8%25AE%25A4%25E8%25AF%2586%25E8%25AF%25AF%25E5%258C%25BA%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fredis%25E5%2585%25B8%25E5%259E%258B%25E5%25BA%2594%25E7%2594%25A8%25E5%259C%25BA%25E6%2599%25AF%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">[转]Redis几个认识误区</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Is memcached a dinosaur in comparison to Redis?" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fis-memcached-a-dinosaur-in-comparison-to-redis%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fredis%25E5%2585%25B8%25E5%259E%258B%25E5%25BA%2594%25E7%2594%25A8%25E5%259C%25BA%25E6%2599%25AF%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Is memcached a dinosaur in comparison to Redis?</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="mongodb学习笔记" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fmongodb%25E5%25AD%25A6%25E4%25B9%25A0%25E7%25AC%2594%25E8%25AE%25B0%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fredis%25E5%2585%25B8%25E5%259E%258B%25E5%25BA%2594%25E7%2594%25A8%25E5%259C%25BA%25E6%2599%25AF%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">mongodb学习笔记</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="应用系统常用性能指标" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%25BA%2594%25E7%2594%25A8%25E7%25B3%25BB%25E7%25BB%259F%25E5%25B8%25B8%25E7%2594%25A8%25E6%2580%25A7%25E8%2583%25BD%25E6%258C%2587%25E6%25A0%2587%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fredis%25E5%2585%25B8%25E5%259E%258B%25E5%25BA%2594%25E7%2594%25A8%25E5%259C%25BA%25E6%2599%25AF%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">应用系统常用性能指标</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="分布式应用通信协议" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%2588%2586%25E5%25B8%2583%25E5%25BC%258F%25E5%25BA%2594%25E7%2594%25A8%25E9%2580%259A%25E4%25BF%25A1%25E5%258D%258F%25E8%25AE%25AE%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fredis%25E5%2585%25B8%25E5%259E%258B%25E5%25BA%2594%25E7%2594%25A8%25E5%259C%25BA%25E6%2599%25AF%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">分布式应用通信协议</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://neoremind.net/2012/05/redis%e5%85%b8%e5%9e%8b%e5%ba%94%e7%94%a8%e5%9c%ba%e6%99%af/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>pymongo批量插入</title>
		<link>http://neoremind.net/2012/05/pymongo%e6%89%b9%e9%87%8f%e6%8f%92%e5%85%a5/</link>
		<comments>http://neoremind.net/2012/05/pymongo%e6%89%b9%e9%87%8f%e6%8f%92%e5%85%a5/#comments</comments>
		<pubDate>Sat, 12 May 2012 06:53:02 +0000</pubDate>
		<dc:creator>neo</dc:creator>
				<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://neoremind.net/?p=877</guid>
		<description><![CDATA[通常我们可以用pymongo这个驱动来作为API操作mongodb，一个典型的需求就是批量插入大量的document（文档），我们知道mongodb是fire-and-forget的模型，即发送数据到mongdb-server后，客户端就认为数据已经保存，这种类似于非阻塞的方式，可以立刻返回。要保存[......]<p class='read-more'><a href='http://neoremind.net/2012/05/pymongo%e6%89%b9%e9%87%8f%e6%8f%92%e5%85%a5/'>继续阅读</a></p><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="有关Python拼SQL操作数据库的故事" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E6%259C%2589%25E5%2585%25B3python%25E6%258B%25BCsql%25E6%2593%258D%25E4%25BD%259C%25E6%2595%25B0%25E6%258D%25AE%25E5%25BA%2593%25E7%259A%2584%25E6%2595%2585%25E4%25BA%258B%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpymongo%25E6%2589%25B9%25E9%2587%258F%25E6%258F%2592%25E5%2585%25A5%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/05/12/25889060.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">有关Python拼SQL操作数据库的故事</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="mongodb学习笔记" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fmongodb%25E5%25AD%25A6%25E4%25B9%25A0%25E7%25AC%2594%25E8%25AE%25B0%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpymongo%25E6%2589%25B9%25E9%2587%258F%25E6%258F%2592%25E5%2585%25A5%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">mongodb学习笔记</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="python脚本在crontab中无法执行解决" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpython%25E8%2584%259A%25E6%259C%25AC%25E5%259C%25A8crontab%25E4%25B8%25AD%25E6%2597%25A0%25E6%25B3%2595%25E6%2589%25A7%25E8%25A1%258C%25E8%25A7%25A3%25E5%2586%25B3%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpymongo%25E6%2589%25B9%25E9%2587%258F%25E6%258F%2592%25E5%2585%25A5%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">python脚本在crontab中无法执行解决</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用pdb调试python程序" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F02%2F%25E4%25BD%25BF%25E7%2594%25A8pdb%25E8%25B0%2583%25E8%25AF%2595python%25E7%25A8%258B%25E5%25BA%258F%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpymongo%25E6%2589%25B9%25E9%2587%258F%25E6%258F%2592%25E5%2585%25A5%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用pdb调试python程序</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python执行系统命令的3种方法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F02%2Fpython%25E6%2589%25A7%25E8%25A1%258C%25E7%25B3%25BB%25E7%25BB%259F%25E5%2591%25BD%25E4%25BB%25A4%25E7%259A%25843%25E7%25A7%258D%25E6%2596%25B9%25E6%25B3%2595%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpymongo%25E6%2589%25B9%25E9%2587%258F%25E6%258F%2592%25E5%2585%25A5%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python执行系统命令的3种方法</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>通常我们可以用pymongo这个驱动来作为API操作mongodb，一个典型的需求就是批量插入大量的document（文档），我们知道mongodb是fire-and-forget的模型，即发送数据到mongdb-server后，客户端就认为数据已经保存，这种类似于非阻塞的方式，可以立刻返回。要保存的文档可以放在一个python的数据结构list中，那么如果这list过于庞大，那拍脑袋想想也不利于mongo-server插入内存，更何况内存碎片，网络IO等风险。所以批量操作吧，见下面的一段代码。</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> pymongo <span style="color: #ff7700;font-weight:bold;">import</span> Connection
&nbsp;
loadsplitsize = <span style="color: #ff4500;">10000</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#init a list</span>
<span style="color: #008000;">list</span>=<span style="color: black;">&#91;</span><span style="color: #483d8b;">'a'</span>,<span style="color: #483d8b;">'b'</span>,<span style="color: #483d8b;">'c'</span><span style="color: black;">&#93;</span>
&nbsp;
con = Connection<span style="color: black;">&#40;</span><span style="color: #483d8b;">'192.168.1.1'</span>,<span style="color: #ff4500;">12701</span><span style="color: black;">&#41;</span>
db = con<span style="color: black;">&#91;</span><span style="color: #483d8b;">'mydb'</span><span style="color: black;">&#93;</span>
db.<span style="color: black;">authenticate</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'username'</span>, <span style="color: #483d8b;">'passw0rd'</span><span style="color: black;">&#41;</span>
mycollection = db<span style="color: black;">&#91;</span><span style="color: #483d8b;">'mycollection'</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># 分页的插入数据库</span>
offset=<span style="color: #ff4500;">0</span>
<span style="color: #ff7700;font-weight:bold;">while</span><span style="color: black;">&#40;</span>offset <span style="color: #66cc66;">&lt;</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #008000;">list</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
	mycollection.<span style="color: black;">insert</span><span style="color: black;">&#40;</span><span style="color: #008000;">list</span><span style="color: black;">&#91;</span>offset:offset+loadsplitsize<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
	offset += loadsplitsize</pre></div></div>

<div>&nbsp;</div>
<p>更多pymongo的API使用请参考 <a href="http://api.mongodb.org/python/2.2/tutorial.html" target="_blank">http://api.mongodb.org/python/2.2/tutorial.html</a></p>
<p>&nbsp;</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="有关Python拼SQL操作数据库的故事" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E6%259C%2589%25E5%2585%25B3python%25E6%258B%25BCsql%25E6%2593%258D%25E4%25BD%259C%25E6%2595%25B0%25E6%258D%25AE%25E5%25BA%2593%25E7%259A%2584%25E6%2595%2585%25E4%25BA%258B%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpymongo%25E6%2589%25B9%25E9%2587%258F%25E6%258F%2592%25E5%2585%25A5%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/05/12/25889060.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">有关Python拼SQL操作数据库的故事</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="mongodb学习笔记" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fmongodb%25E5%25AD%25A6%25E4%25B9%25A0%25E7%25AC%2594%25E8%25AE%25B0%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpymongo%25E6%2589%25B9%25E9%2587%258F%25E6%258F%2592%25E5%2585%25A5%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">mongodb学习笔记</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="python脚本在crontab中无法执行解决" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpython%25E8%2584%259A%25E6%259C%25AC%25E5%259C%25A8crontab%25E4%25B8%25AD%25E6%2597%25A0%25E6%25B3%2595%25E6%2589%25A7%25E8%25A1%258C%25E8%25A7%25A3%25E5%2586%25B3%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpymongo%25E6%2589%25B9%25E9%2587%258F%25E6%258F%2592%25E5%2585%25A5%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">python脚本在crontab中无法执行解决</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用pdb调试python程序" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F02%2F%25E4%25BD%25BF%25E7%2594%25A8pdb%25E8%25B0%2583%25E8%25AF%2595python%25E7%25A8%258B%25E5%25BA%258F%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpymongo%25E6%2589%25B9%25E9%2587%258F%25E6%258F%2592%25E5%2585%25A5%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用pdb调试python程序</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python执行系统命令的3种方法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F02%2Fpython%25E6%2589%25A7%25E8%25A1%258C%25E7%25B3%25BB%25E7%25BB%259F%25E5%2591%25BD%25E4%25BB%25A4%25E7%259A%25843%25E7%25A7%258D%25E6%2596%25B9%25E6%25B3%2595%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpymongo%25E6%2589%25B9%25E9%2587%258F%25E6%258F%2592%25E5%2585%25A5%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python执行系统命令的3种方法</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://neoremind.net/2012/05/pymongo%e6%89%b9%e9%87%8f%e6%8f%92%e5%85%a5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>shell中输出从某一天起所有日期的方法</title>
		<link>http://neoremind.net/2012/05/shell%e4%b8%ad%e8%be%93%e5%87%ba%e4%bb%8e%e6%9f%90%e4%b8%80%e5%a4%a9%e8%b5%b7%e6%89%80%e6%9c%89%e6%97%a5%e6%9c%9f%e7%9a%84%e6%96%b9%e6%b3%95/</link>
		<comments>http://neoremind.net/2012/05/shell%e4%b8%ad%e8%be%93%e5%87%ba%e4%bb%8e%e6%9f%90%e4%b8%80%e5%a4%a9%e8%b5%b7%e6%89%80%e6%9c%89%e6%97%a5%e6%9c%9f%e7%9a%84%e6%96%b9%e6%b3%95/#comments</comments>
		<pubDate>Sat, 12 May 2012 06:07:40 +0000</pubDate>
		<dc:creator>neo</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://neoremind.net/?p=875</guid>
		<description><![CDATA[&#160;最近在项目中有这么一个需求，导入历史所有日志到DB中，而导入的脚本usage如下：
./importApiaccessLog-main.py &#60;date like 20120506&#62;
因此需要从一个很早的时间点开始，依次调用该脚本，顺序传入日期。那么每年每个月的天数都会不同，[......]<p class='read-more'><a href='http://neoremind.net/2012/05/shell%e4%b8%ad%e8%be%93%e5%87%ba%e4%bb%8e%e6%9f%90%e4%b8%80%e5%a4%a9%e8%b5%b7%e6%89%80%e6%9c%89%e6%97%a5%e6%9c%9f%e7%9a%84%e6%96%b9%e6%b3%95/'>继续阅读</a></p><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="Shell中数组的应用" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F04%2Fshell%25E4%25B8%25AD%25E6%2595%25B0%25E7%25BB%2584%25E7%259A%2584%25E5%25BA%2594%25E7%2594%25A8%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fshell%25E4%25B8%25AD%25E8%25BE%2593%25E5%2587%25BA%25E4%25BB%258E%25E6%259F%2590%25E4%25B8%2580%25E5%25A4%25A9%25E8%25B5%25B7%25E6%2589%2580%25E6%259C%2589%25E6%2597%25A5%25E6%259C%259F%25E7%259A%2584%25E6%2596%25B9%25E6%25B3%2595%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Shell中数组的应用</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="拒绝labor 拥抱脚本~高效替换所有文件中字符串的Shell" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F08%2Freplace_all_files_keyword_shell_script%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fshell%25E4%25B8%25AD%25E8%25BE%2593%25E5%2587%25BA%25E4%25BB%258E%25E6%259F%2590%25E4%25B8%2580%25E5%25A4%25A9%25E8%25B5%25B7%25E6%2589%2580%25E6%259C%2589%25E6%2597%25A5%25E6%259C%259F%25E7%259A%2584%25E6%2596%25B9%25E6%25B3%2595%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">拒绝labor 拥抱脚本~高效替换所有文件中字符串的Shell</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Shell脚本100%进度条显示" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F02%2Fshell%25E8%2584%259A%25E6%259C%25AC100%25E8%25BF%259B%25E5%25BA%25A6%25E6%259D%25A1%25E6%2598%25BE%25E7%25A4%25BA%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fshell%25E4%25B8%25AD%25E8%25BE%2593%25E5%2587%25BA%25E4%25BB%258E%25E6%259F%2590%25E4%25B8%2580%25E5%25A4%25A9%25E8%25B5%25B7%25E6%2589%2580%25E6%259C%2589%25E6%2597%25A5%25E6%259C%259F%25E7%259A%2584%25E6%2596%25B9%25E6%25B3%2595%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Shell脚本100%进度条显示</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Ant+Shell脚本更新XML文件节点值" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F03%2Fantshell%25E8%2584%259A%25E6%259C%25AC%25E6%259B%25B4%25E6%2596%25B0xml%25E6%2596%2587%25E4%25BB%25B6%25E8%258A%2582%25E7%2582%25B9%25E5%2580%25BC%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fshell%25E4%25B8%25AD%25E8%25BE%2593%25E5%2587%25BA%25E4%25BB%258E%25E6%259F%2590%25E4%25B8%2580%25E5%25A4%25A9%25E8%25B5%25B7%25E6%2589%2580%25E6%259C%2589%25E6%2597%25A5%25E6%259C%259F%25E7%259A%2584%25E6%2596%25B9%25E6%25B3%2595%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Ant+Shell脚本更新XML文件节点值</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="shell字符串的截取" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F02%2Fshell%25E5%25AD%2597%25E7%25AC%25A6%25E4%25B8%25B2%25E7%259A%2584%25E6%2588%25AA%25E5%258F%2596%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fshell%25E4%25B8%25AD%25E8%25BE%2593%25E5%2587%25BA%25E4%25BB%258E%25E6%259F%2590%25E4%25B8%2580%25E5%25A4%25A9%25E8%25B5%25B7%25E6%2589%2580%25E6%259C%2589%25E6%2597%25A5%25E6%259C%259F%25E7%259A%2584%25E6%2596%25B9%25E6%25B3%2595%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">shell字符串的截取</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;最近在项目中有这么一个需求，导入历史所有日志到DB中，而导入的脚本usage如下：</p>
<p>./importApiaccessLog-main.py &lt;date like 20120506&gt;</p>
<p>因此需要从一个很早的时间点开始，依次调用该脚本，顺序传入日期。那么每年每个月的天数都会不同，怎么办，写了个shell脚本，以后面对这种需求，可以直接板砖了。不多说，上脚本：</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">#!/bin/bash
&nbsp;
datefile=&quot;datefile&quot;
echo &gt; $datefile
&nbsp;
function importOneMonthLog()
{
	start_day=1
    year=$1
    month=$2
    total_day_num=$3
    while [ $start_day -le $total_day_num ] 
    do
        if [ $start_day -lt 10 ];then
            echo ${year}${month}0${start_day} &gt;&gt; $datefile
        else
            echo ${year}${month}${start_day} &gt;&gt; $datefile
        fi
        start_day=`expr $start_day + 1`
    done
}
&nbsp;
function importAllLogs()
{
    # 能够符合计算的log月份
    MOST_BEFORE_YEAR_MONTH=&quot;201202&quot;
    n=1
    LAST_YEAR_MONTH=`date -d '1 months ago' +%Y%m`
    while [ $LAST_YEAR_MONTH -gt $MOST_BEFORE_YEAR_MONTH ] 
    do
        LAST_YEAR_MONTH=`date -d ''$n' months ago' +%Y%m`
        LAST_YEAR=`date -d ''$n' months ago' +%Y`
        LAST_MONTH=`date -d ''$n' months ago' +%m`
        LAST_DAY_NUM=`cal $LAST_MONTH $LAST_YEAR | xargs | awk '{print $NF}'`
		importOneMonthLog ${LAST_YEAR} ${LAST_MONTH} ${LAST_DAY_NUM}
        n=`expr $n + 1`
    done
    NOW_YEAR_MONTH=`date +%Y%m`
    NOW_YEAR=`date +%Y`
    NOW_MONTH=`date +%m`
    NOW_DAY_NUM=`date -d &quot;1 day ago&quot; +%d`
	importOneMonthLog ${NOW_YEAR} ${NOW_MONTH} ${NOW_DAY_NUM} 
}
&nbsp;
importAllLogs
&nbsp;
sort $datefile &gt; ${datefile}.sort
while read line
do
    ./importApiaccessLog-main.py $line
    #echo $line
done &lt; ${datefile}.sort</pre></div></div>

<p>&nbsp;</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="Shell中数组的应用" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F04%2Fshell%25E4%25B8%25AD%25E6%2595%25B0%25E7%25BB%2584%25E7%259A%2584%25E5%25BA%2594%25E7%2594%25A8%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fshell%25E4%25B8%25AD%25E8%25BE%2593%25E5%2587%25BA%25E4%25BB%258E%25E6%259F%2590%25E4%25B8%2580%25E5%25A4%25A9%25E8%25B5%25B7%25E6%2589%2580%25E6%259C%2589%25E6%2597%25A5%25E6%259C%259F%25E7%259A%2584%25E6%2596%25B9%25E6%25B3%2595%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Shell中数组的应用</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="拒绝labor 拥抱脚本~高效替换所有文件中字符串的Shell" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F08%2Freplace_all_files_keyword_shell_script%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fshell%25E4%25B8%25AD%25E8%25BE%2593%25E5%2587%25BA%25E4%25BB%258E%25E6%259F%2590%25E4%25B8%2580%25E5%25A4%25A9%25E8%25B5%25B7%25E6%2589%2580%25E6%259C%2589%25E6%2597%25A5%25E6%259C%259F%25E7%259A%2584%25E6%2596%25B9%25E6%25B3%2595%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">拒绝labor 拥抱脚本~高效替换所有文件中字符串的Shell</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Shell脚本100%进度条显示" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F02%2Fshell%25E8%2584%259A%25E6%259C%25AC100%25E8%25BF%259B%25E5%25BA%25A6%25E6%259D%25A1%25E6%2598%25BE%25E7%25A4%25BA%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fshell%25E4%25B8%25AD%25E8%25BE%2593%25E5%2587%25BA%25E4%25BB%258E%25E6%259F%2590%25E4%25B8%2580%25E5%25A4%25A9%25E8%25B5%25B7%25E6%2589%2580%25E6%259C%2589%25E6%2597%25A5%25E6%259C%259F%25E7%259A%2584%25E6%2596%25B9%25E6%25B3%2595%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Shell脚本100%进度条显示</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Ant+Shell脚本更新XML文件节点值" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F03%2Fantshell%25E8%2584%259A%25E6%259C%25AC%25E6%259B%25B4%25E6%2596%25B0xml%25E6%2596%2587%25E4%25BB%25B6%25E8%258A%2582%25E7%2582%25B9%25E5%2580%25BC%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fshell%25E4%25B8%25AD%25E8%25BE%2593%25E5%2587%25BA%25E4%25BB%258E%25E6%259F%2590%25E4%25B8%2580%25E5%25A4%25A9%25E8%25B5%25B7%25E6%2589%2580%25E6%259C%2589%25E6%2597%25A5%25E6%259C%259F%25E7%259A%2584%25E6%2596%25B9%25E6%25B3%2595%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Ant+Shell脚本更新XML文件节点值</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="shell字符串的截取" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F02%2Fshell%25E5%25AD%2597%25E7%25AC%25A6%25E4%25B8%25B2%25E7%259A%2584%25E6%2588%25AA%25E5%258F%2596%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fshell%25E4%25B8%25AD%25E8%25BE%2593%25E5%2587%25BA%25E4%25BB%258E%25E6%259F%2590%25E4%25B8%2580%25E5%25A4%25A9%25E8%25B5%25B7%25E6%2589%2580%25E6%259C%2589%25E6%2597%25A5%25E6%259C%259F%25E7%259A%2584%25E6%2596%25B9%25E6%25B3%2595%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">shell字符串的截取</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://neoremind.net/2012/05/shell%e4%b8%ad%e8%be%93%e5%87%ba%e4%bb%8e%e6%9f%90%e4%b8%80%e5%a4%a9%e8%b5%b7%e6%89%80%e6%9c%89%e6%97%a5%e6%9c%9f%e7%9a%84%e6%96%b9%e6%b3%95/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mongodb学习笔记</title>
		<link>http://neoremind.net/2012/05/mongodb%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0/</link>
		<comments>http://neoremind.net/2012/05/mongodb%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0/#comments</comments>
		<pubDate>Sat, 12 May 2012 05:56:18 +0000</pubDate>
		<dc:creator>neo</dc:creator>
				<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[mongodb]]></category>

		<guid isPermaLink="false">http://neoremind.net/?p=871</guid>
		<description><![CDATA[<strong>mongoDB介绍篇</strong>
mongodb由C++写就，其名字来自humongous这个单词的中间部分。最简洁描述为：<strong>scalable, high-performance, open source, schema-free, document-oriented database</strong>。
&#160;
mongo[......]<p class='read-more'><a href='http://neoremind.net/2012/05/mongodb%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0/'>继续阅读</a></p><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="pymongo批量插入" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpymongo%25E6%2589%25B9%25E9%2587%258F%25E6%258F%2592%25E5%2585%25A5%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fmongodb%25E5%25AD%25A6%25E4%25B9%25A0%25E7%25AC%2594%25E8%25AE%25B0%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">pymongo批量插入</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Redis典型应用场景" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fredis%25E5%2585%25B8%25E5%259E%258B%25E5%25BA%2594%25E7%2594%25A8%25E5%259C%25BA%25E6%2599%25AF%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fmongodb%25E5%25AD%25A6%25E4%25B9%25A0%25E7%25AC%2594%25E8%25AE%25B0%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Redis典型应用场景</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="[转]Redis几个认识误区" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E8%25BD%25ACredis%25E5%2587%25A0%25E4%25B8%25AA%25E8%25AE%25A4%25E8%25AF%2586%25E8%25AF%25AF%25E5%258C%25BA%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fmongodb%25E5%25AD%25A6%25E4%25B9%25A0%25E7%25AC%2594%25E8%25AE%25B0%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">[转]Redis几个认识误区</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Is memcached a dinosaur in comparison to Redis?" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fis-memcached-a-dinosaur-in-comparison-to-redis%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fmongodb%25E5%25AD%25A6%25E4%25B9%25A0%25E7%25AC%2594%25E8%25AE%25B0%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Is memcached a dinosaur in comparison to Redis?</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="设计模式学习总结-命令模式" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F07%2Fcommand_design_patter%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fmongodb%25E5%25AD%25A6%25E4%25B9%25A0%25E7%25AC%2594%25E8%25AE%25B0%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/02/11/15257522.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">设计模式学习总结-命令模式</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<h3 style="color: red; "><strong>mongoDB介绍篇</strong></h3>
<div>mongodb由C++写就，其名字来自humongous这个单词的中间部分。最简洁描述为：<strong><span style="color: rgb(0, 0, 255); "><span style="font-size: larger; "><span style="font-family: 'Courier New'; ">scalable, high-performance, open source, schema-free, document-oriented database</span></span></span></strong>。</div>
<div>&nbsp;</div>
<div>mongoDB是一个基于<strong>分布式文件存储</strong>的数据库<strong>开源项目</strong>，旨在为WEB应用提供可护展的<strong>高性能</strong>数据存储解决方案。Mongodb由专门的公司来开发，公司名叫做10gen，2009年发行了以一个release版本。</div>
<div>&nbsp;</div>
<div>跟mysqld一样，一个mongod服务可以有建立多个数据库，每个数据库可以有多张表，这里的表名叫<strong>集合（collection）</strong>，每个collection 可以存放多个<strong>文档（document）</strong>，每个文档都以<strong>BSON（binary json）</strong>的形式存放于硬盘中。</div>
<div>&nbsp;</div>
<div>跟关系型数据库不一样的地方是，它是的以单文档为单位存储的，你可以任意给一个或一批文档新增或删除字段，而不会对其它文档造成影响，这就是所谓的<strong>schema-free</strong>，这也是文档型数据库最主要的优点，mongodb中稳定以json形式存在，默认的convention是一个collection中的稳定schema相同。所以别问我如何用mongodb做join，这种白痴问题。</div>
<div>&nbsp;</div>
<div>跟一般的key-value数据库不一样的是，它的value中存储了结构信息，所以你又可以像关系型数据库那样对某些域进行读写、统计等操作。可以说是兼备了key-value数据库的方便高效与关系型数据库的强大功能。</div>
<div>&nbsp;</div>
<div>Mongodb不是为事务准备的，只保证最终一致性，ACID的特性只有在RDBMS才具备，所以如果你要是要事务型的解决方案，mongodb并不适合。</div>
<div>&nbsp;</div>
<div>Mongodb有很多特性，包括</div>
<div>高性能</div>
<div>丰富的查询语句，js like</div>
<div>Mapreduce</div>
<div>二级索引</div>
<div>地理位置索引</div>
<div>Replica-sets，就是集群服务，有一个primary，多个nodes，自动做failover</div>
<div>Auto-sharding</div>
<div>丰富的平台、驱动支持</div>
<div>&nbsp;</div>
<div>Mongdb是典型的fire-and-forget模型，为的是高吞吐量（高rps，可以到达10w reads/writes per sec），当然也可以采用safe-mode，等mongo-server确认（为rps做一个tradeoff，5w reads/writes per sec）。这些预估的rps是可能因为你的RAM，CPU，磁盘IO，客户端驱动/APP而有差异的。默认的更新都是在内存里的，所以速度很快，每隔一段时间fsync内存数据到磁盘上。</div>
<div>&nbsp;</div>
<div>Mongodb与传统RDBMS数据库的优势与不足：</div>
<div>优势：为web而生，缓存出色，高性能，高可用性</div>
<div>不足：非事务，ad-hoc BI/data warehouse场景不适用，不能取代复杂的sql查询</div>
<div>&nbsp;</div>
<div>这里特别说明下，mongodb不是万能的，也只是应用于一些场景的NoSQL数据库，它的目标不是取代RDBMS关系型数据库，所以Use the right tool for each task。</div>
<div>&nbsp;</div>
<div>&nbsp;更多的mongodb介绍，<a href="http://blog.nosqlfan.com/html/3548.html" target="_blank">NoSQL Fan网站</a>上有个很全的list可以参考。</div>
<div>&nbsp;</div>
<h3 style="color: red; "><strong>mongoDB安装篇</strong></h3>
<div>&nbsp;</div>
<div>1、下载可执行文件</div>
<div>mongdb不用安装，去官网(<a href="http://www.mongodb.org/">http://www.mongodb.org/</a>)根据平台下载bin即可。</div>
<div>&nbsp;</div>
<div>2、修改$PATH，并使其生效</div>
<div>vim ~/.bash_profile</div>
<div>增加如下两行</div>
<div>export MONGO_HOME=/home/work/mongodb</div>
<div>export PATH=$MONGO_HOME/bin:$PATH</div>
<div>source该文件使其生效</div>
<div>source ~/.bash_profile</div>
<div>&nbsp;</div>
<div>mongoDB安装完毕，then enjoy it！</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<h3 style="color: red; "><strong>mongoDB 实战篇</strong></h3>
<div><strong>1、开启mongoDB服务</strong></div>
<div>&nbsp;</div>
<div>运行mongDB可用如下命令：</div>
<div>./mongod &#8211;port 8017 &#8211;dbpath /home/work/mongodb/data &#8211;logappend &#8211;logpath /home/work/mongodb/log/log.8017 &amp;</div>
<div>参数含义：</div>
<div>port: 可启动时指定服务端口，而无需在配置文件里设置</div>
<div>dbpath: mongDB数据文件的路径</div>
<div>logpath: 打印日志路径</div>
<div>&nbsp;</div>
<div>可以用安装的一个mongoDB在不同端口上启动另一服务，如运行如下命令</div>
<div>./mongod &#8211;port 8019 &#8211;dbpath /home/work/mongodb/data1 &#8211;logappend &#8211;logpath /home/work/mongodb/log/log.8019 &amp;</div>
<div>&nbsp;</div>
<div>后台不同端口上的两个mongoDB都在运行</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div><strong>2、登陆mongoDB，运行简单命令</strong></div>
<div>&nbsp;</div>
<div>登陆mongoDB：mongo 127.0.0.1:8017</div>
<div>&nbsp;</div>
<div>列出当前数据库：show dbs</div>
<div>&nbsp;</div>
<div>定义新的数据库名：use beidou</div>
<div>使用&ldquo;use new-databasename&rdquo;的语法去使用一个新的数据库，注意，即使你的数据库还没建立起来，依然可以这样使用，因为mongodb会在真正插入了数据后，才会真正建立起来</div>
<div>&nbsp;</div>
<div>定义一个collection,名为&ldquo;users&rdquo;,然后插入数据</div>
<div>db.users.save( {username:&quot;neoremind&quot;} )</div>
<div>db.users.find()</div>
<div>mongoDB插入数据就自动建数据库、collections，可以不用像SQL数据库那样有建表的脚本。</div>
<div>&nbsp;</div>
<div>也可以只创建Collection</div>
<div>db.createCollection(&quot;collecName&quot;)</div>
<div>&nbsp;</div>
<div>向mongoDB数据库databaseName的collectionName灌数据，field有两个字段，分别为id和key，输入文件为data.dat</div>
<div>mongoimport &#8211;ignoreBlanks -h127.0.0.1 &#8211;port 8017 &ndash;ddatabaseName -ccollectionName -f&quot;id,key&quot; &#8211;type &quot;tsv&quot; &#8211;file data.dat</div>
<div>&nbsp;</div>
<div>从mongoDB导出数据</div>
<div>mongoexport -h127.0.0.1 &#8211;port 8017 &ndash;ddatabaseName -ccollectionName -f&quot;id,key&quot; &#8211;csv &gt; mongo.out</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div><strong>3、正确关闭mongoDB</strong></div>
<div>&nbsp;</div>
<div>第一种：官方文档说明要使用 kill -15，killall mongod或者在client的shell里，use admin，执行db.shutdownServer()即可。</div>
<div>&nbsp;</div>
<div>第二种：通过replication 使用 一个slave，或者用replica set 来避免单结点数据丢失。</div>
<div>&nbsp;</div>
<div>第三种：在 MongoDB 1.7 版本的最新分支上，就出现了一个新的数据可靠性选项（&ndash;dur）的支持。并且在数据文件修复工具上也有了一些改进。如果在启动MongoDB时加上&ndash;dur 则MongoDB 会在进行写操作前记一份日志，这和在其他一些数据库中的binlog 类似，在MongoDB 数据文件损坏的情况下，可以使用此日志来进行恢复。据说其对性能的影响不大。</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<h3 style="color: red; "><strong>mongoDB 其它常用操作篇</strong></h3>
<div>
<div><strong>常用数据库操作</strong></div>
<div>1. 查看帮助</div>
<div>help</div>
<div>&nbsp;</div>
<div>2. show database names</div>
<div>show dbs &nbsp;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
<div>3. show collections in current database</div>
<div>show collections &nbsp;&nbsp;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div>
<div>4. show users in current database</div>
<div>show users &nbsp;&nbsp;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div>
<div>5. 切换/创建数据库</div>
<div>use yourDB; &nbsp;</div>
<div>&nbsp;</div>
<div>6. 删除当前使用数据库</div>
<div>db.dropDatabase();</div>
<div>&nbsp;</div>
<div>7. 查看当前使用的数据库</div>
<div>db 或者 db.getName();</div>
<div>&nbsp;</div>
<div>8. 显示当前db状态</div>
<div>db.stats();</div>
<div>&nbsp;</div>
<div>9. 当前db版本</div>
<div>db.version();</div>
<div>&nbsp;</div>
<div>10. 查看当前db的链接机器地址</div>
<div>db.getMongo();</div>
<div>&nbsp;</div>
<div><strong>常用集合操作</strong></div>
<div>1. 创建一个聚集集合</div>
<div>db.createCollection(&quot;apilog&quot;});</div>
<div>&nbsp;</div>
<div>2. 查询当前集合的数据条数 &nbsp;</div>
<div>db.apilog.count();</div>
<div>&nbsp;</div>
<div>3. 查看数据空间大小&nbsp;</div>
<div>db.apilog.dataSize(); &nbsp;//单位为KB</div>
<div>&nbsp;</div>
<div>4. 得到当前聚集集合所在的db&nbsp;</div>
<div>db.apilog.getDB();</div>
<div>&nbsp;</div>
<div>5. 得到当前聚集的状态&nbsp;</div>
<div>db.apilog.stats();</div>
<div>&nbsp;</div>
<div>6. 得到聚集集合总大小&nbsp;</div>
<div>db.apilog.totalSize();&nbsp;</div>
<div>&nbsp;</div>
<div>7. 聚集集合储存空间大小&nbsp;</div>
<div>db.apilog.storageSize();</div>
<div>&nbsp;</div>
<div>8. 删除当前聚集集合 db.apilog.drop();</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div><strong>常用查询操作</strong></div>
<div>MongoDB<span class="Apple-tab-span" style="white-space:pre">	</span></div>
<div>关系型数据库（Mysql）</div>
<div>&nbsp;</div>
<div>db.test.find({&#8216;name&#8217;:'foobar&#8217;})<span class="Apple-tab-span" style="white-space:pre">	</span></div>
<div>select * from test where name=&#8217;foobar&#8217;</div>
<div>&nbsp;</div>
<div>db.test.find()<span class="Apple-tab-span" style="white-space:pre">	</span></div>
<div>select * from test</div>
<div>&nbsp;</div>
<div>db.test.find({&#8216;ID&#8217;:10}).count()<span class="Apple-tab-span" style="white-space:pre">	</span></div>
<div>select count(*) from test where ID=10</div>
<div>&nbsp;</div>
<div>db.test.find().skip(10).limit(20)<span class="Apple-tab-span" style="white-space:pre">	</span></div>
<div>select * from test limit 10,20</div>
<div>&nbsp;</div>
<div>db.test.find({&#8216;ID&#8217;:{$in:[25,35,45]}})<span class="Apple-tab-span" style="white-space:pre">	</span></div>
<div>select * from test where ID in (25,35,45)</div>
<div>&nbsp;</div>
<div>db.test.find().sort({&#8216;ID&#8217;:-1})<span class="Apple-tab-span" style="white-space:pre">	</span></div>
<div>select * from test order by ID desc</div>
<div>&nbsp;</div>
<div>db.test.distinct(&#8216;name&#8217;,{&#8216;ID&#8217;:{$lt:20}})<span class="Apple-tab-span" style="white-space:pre">	</span></div>
<div>select distinct(name) from test where ID&lt;20</div>
<div>&nbsp;</div>
<div>db.test.group({key:{&#8216;name&#8217;:true},</div>
<div>cond:{&#8216;name&#8217;:'foo&#8217;},</div>
<div>reduce:function(obj,prev)</div>
<div>{prev.msum+=obj.marks;</div>
<div>},</div>
<div>initial:{msum:0}})<span class="Apple-tab-span" style="white-space:pre">	</span>select name,sum(marks) from test group by name</div>
<div>&nbsp;</div>
<div>db.test.find(&#8216;this.ID&lt;20&#8242;,{name:1})<span class="Apple-tab-span" style="white-space:pre">	</span></div>
<div>select name from test where ID&lt;20</div>
<div>&nbsp;</div>
<div>db.test.insert({&#8216;name&#8217;:'foobar&#8217;,'age&#8217;:25})<span class="Apple-tab-span" style="white-space:pre">	</span></div>
<div>insert into test (&#8216;name&#8217;,'age&#8217;) values(&#8216;foobar&#8217;,25)</div>
<div>&nbsp;</div>
<div>db.test.remove({})<span class="Apple-tab-span" style="white-space:pre">	</span></div>
<div>delete * from test</div>
<div>&nbsp;</div>
<div>db.test.remove({&#8216;age&#8217;:20})<span class="Apple-tab-span" style="white-space:pre">	</span></div>
<div>delete * from test where age=20</div>
<div>&nbsp;</div>
<div>db.test.remove({&#8216;age&#8217;:{$lt:20}})<span class="Apple-tab-span" style="white-space:pre">	</span></div>
<div>delete * from test where age&lt;20</div>
<div>&nbsp;</div>
<div>db.test.remove({&#8216;age&#8217;:{$lte:20}})<span class="Apple-tab-span" style="white-space:pre">	</span></div>
<div>delete * from test where age&lt;=20</div>
<div>&nbsp;</div>
<div>db.test.remove({&#8216;age&#8217;:{$ne:20}})<span class="Apple-tab-span" style="white-space:pre">	</span></div>
<div>delete * from test where age!=20</div>
<div>&nbsp;</div>
<div>db.test.update({&#8216;name&#8217;:'foobar&#8217;},{$set:{&#8216;age&#8217;:36}})<span class="Apple-tab-span" style="white-space:pre">	</span></div>
<div>update test set age=36 where name=&#8217;foobar&#8217;</div>
<div>&nbsp;</div>
<div>db.test.update({&#8216;name&#8217;:'foobar&#8217;},{$inc:{&#8216;age&#8217;:3}})<span class="Apple-tab-span" style="white-space:pre">	</span></div>
<div>update test set age=age+3 where name=&#8217;foobar&#8217;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div><strong>索引</strong></div>
<div>1. 创建索引</div>
<div>db.userInfo.ensureIndex({name: 1});</div>
<div>db.userInfo.ensureIndex({name: 1, ts: -1});</div>
<div>&nbsp;</div>
<div>2. 查询当前聚集集合所有索引</div>
<div>db.userInfo.getIndexes();</div>
<div>&nbsp;</div>
<div>3. 查看总索引记录大小</div>
<div>db.userInfo.totalIndexSize();</div>
<div>&nbsp;</div>
<div>4. 读取当前集合的所有index信息</div>
<div>db.users.reIndex();</div>
<div>&nbsp;</div>
<div>5.删除指定索引</div>
<div>db.users.dropIndex(&quot;name_1&quot;);</div>
<div>&nbsp;</div>
<div>6. 删除所有索引索引</div>
<div>db.users.dropIndexes();</div>
</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="pymongo批量插入" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpymongo%25E6%2589%25B9%25E9%2587%258F%25E6%258F%2592%25E5%2585%25A5%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fmongodb%25E5%25AD%25A6%25E4%25B9%25A0%25E7%25AC%2594%25E8%25AE%25B0%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">pymongo批量插入</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Redis典型应用场景" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fredis%25E5%2585%25B8%25E5%259E%258B%25E5%25BA%2594%25E7%2594%25A8%25E5%259C%25BA%25E6%2599%25AF%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fmongodb%25E5%25AD%25A6%25E4%25B9%25A0%25E7%25AC%2594%25E8%25AE%25B0%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Redis典型应用场景</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="[转]Redis几个认识误区" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E8%25BD%25ACredis%25E5%2587%25A0%25E4%25B8%25AA%25E8%25AE%25A4%25E8%25AF%2586%25E8%25AF%25AF%25E5%258C%25BA%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fmongodb%25E5%25AD%25A6%25E4%25B9%25A0%25E7%25AC%2594%25E8%25AE%25B0%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">[转]Redis几个认识误区</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Is memcached a dinosaur in comparison to Redis?" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fis-memcached-a-dinosaur-in-comparison-to-redis%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fmongodb%25E5%25AD%25A6%25E4%25B9%25A0%25E7%25AC%2594%25E8%25AE%25B0%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Is memcached a dinosaur in comparison to Redis?</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="设计模式学习总结-命令模式" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F07%2Fcommand_design_patter%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fmongodb%25E5%25AD%25A6%25E4%25B9%25A0%25E7%25AC%2594%25E8%25AE%25B0%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/02/11/15257522.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">设计模式学习总结-命令模式</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://neoremind.net/2012/05/mongodb%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>有关Python拼SQL操作数据库的故事</title>
		<link>http://neoremind.net/2012/05/%e6%9c%89%e5%85%b3python%e6%8b%bcsql%e6%93%8d%e4%bd%9c%e6%95%b0%e6%8d%ae%e5%ba%93%e7%9a%84%e6%95%85%e4%ba%8b/</link>
		<comments>http://neoremind.net/2012/05/%e6%9c%89%e5%85%b3python%e6%8b%bcsql%e6%93%8d%e4%bd%9c%e6%95%b0%e6%8d%ae%e5%ba%93%e7%9a%84%e6%95%85%e4%ba%8b/#comments</comments>
		<pubDate>Fri, 11 May 2012 16:13:07 +0000</pubDate>
		<dc:creator>neo</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://neoremind.net/?p=867</guid>
		<description><![CDATA[<strong>小白问：</strong>
我想用python操作数据库，我拼sql该怎么半？
&#160;
<strong>PY控：</strong>
想想java吧
&#160;
<strong>小白：</strong>
sql += name
sql += &#8216;, now(),&#8217;
&#8230;
&#160;
<strong>PY控：</strong>
No No No
第一，拼string浪费内存，你这[......]<p class='read-more'><a href='http://neoremind.net/2012/05/%e6%9c%89%e5%85%b3python%e6%8b%bcsql%e6%93%8d%e4%bd%9c%e6%95%b0%e6%8d%ae%e5%ba%93%e7%9a%84%e6%95%85%e4%ba%8b/'>继续阅读</a></p><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title=" SQL中使用WITH AS提高性能" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F07%2Fsql_with_as_performance%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E6%259C%2589%25E5%2585%25B3python%25E6%258B%25BCsql%25E6%2593%258D%25E4%25BD%259C%25E6%2595%25B0%25E6%258D%25AE%25E5%25BA%2593%25E7%259A%2584%25E6%2595%2585%25E4%25BA%258B%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;"> SQL中使用WITH AS提高性能</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="python脚本在crontab中无法执行解决" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpython%25E8%2584%259A%25E6%259C%25AC%25E5%259C%25A8crontab%25E4%25B8%25AD%25E6%2597%25A0%25E6%25B3%2595%25E6%2589%25A7%25E8%25A1%258C%25E8%25A7%25A3%25E5%2586%25B3%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E6%259C%2589%25E5%2585%25B3python%25E6%258B%25BCsql%25E6%2593%258D%25E4%25BD%259C%25E6%2595%25B0%25E6%258D%25AE%25E5%25BA%2593%25E7%259A%2584%25E6%2595%2585%25E4%25BA%258B%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">python脚本在crontab中无法执行解决</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用pdb调试python程序" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F02%2F%25E4%25BD%25BF%25E7%2594%25A8pdb%25E8%25B0%2583%25E8%25AF%2595python%25E7%25A8%258B%25E5%25BA%258F%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E6%259C%2589%25E5%2585%25B3python%25E6%258B%25BCsql%25E6%2593%258D%25E4%25BD%259C%25E6%2595%25B0%25E6%258D%25AE%25E5%25BA%2593%25E7%259A%2584%25E6%2595%2585%25E4%25BA%258B%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用pdb调试python程序</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python time时间用法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F02%2Fpython-time%25E6%2597%25B6%25E9%2597%25B4%25E7%2594%25A8%25E6%25B3%2595%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E6%259C%2589%25E5%2585%25B3python%25E6%258B%25BCsql%25E6%2593%258D%25E4%25BD%259C%25E6%2595%25B0%25E6%258D%25AE%25E5%25BA%2593%25E7%259A%2584%25E6%2595%2585%25E4%25BA%258B%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python time时间用法</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python执行系统命令的3种方法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F02%2Fpython%25E6%2589%25A7%25E8%25A1%258C%25E7%25B3%25BB%25E7%25BB%259F%25E5%2591%25BD%25E4%25BB%25A4%25E7%259A%25843%25E7%25A7%258D%25E6%2596%25B9%25E6%25B3%2595%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E6%259C%2589%25E5%2585%25B3python%25E6%258B%25BCsql%25E6%2593%258D%25E4%25BD%259C%25E6%2595%25B0%25E6%258D%25AE%25E5%25BA%2593%25E7%259A%2584%25E6%2595%2585%25E4%25BA%258B%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python执行系统命令的3种方法</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p><strong>小白问：</strong></p>
<div>我想用python操作数据库，我拼sql该怎么半？</div>
<div>&nbsp;</div>
<div><strong>PY控：</strong></div>
<div>想想java吧</div>
<div>&nbsp;</div>
<div><strong>小白：</strong></div>
<div>sql += name</div>
<div>sql += &#8216;, now(),&#8217;</div>
<div>&#8230;</div>
<div>&nbsp;</div>
<div><strong>PY控：</strong></div>
<div>No No No</div>
<div>第一，拼string浪费内存，你这样不好于StringBuffer(&#8216;123&#8242;+&#8217;ABC&#8217;)的错误。</div>
<div>&nbsp;</div>
<div>第二，这样容易造成了sql注入，看看下面的笑话吧</div>
<div>一个家长接到电话：&nbsp;</div>
<div>Teacher: Hi. This is your son&#8217;s school. We are having some computer trouble.&nbsp;</div>
<div>Mom: Oh dear! Did he break something?&nbsp;</div>
<div>Teacher: In a way&#8230; Did you really name your son &quot;Robert&#8217;); DROP TABLE students &#8211;&quot;?&nbsp;</div>
<div>Mom: Yes. Little Bobby Tables, we call him.&nbsp;</div>
<div>Teacher: Well, we&#8217;ve lost this year&#8217;s student records. I hope you&#8217;re happy.&nbsp;</div>
<div>Mom: And I hope you&#8217;ve learned to sanitize your database input.&nbsp;</div>
<div>&nbsp;</div>
<div><img src="http://neoremind.net/wp-content/uploads/image/exploits_of_a_mom.png" alt="" /></div>
<div>&nbsp;&nbsp;</div>
<div>第三，我说java其实是想让你想想用preparestatment，模板来填入?形式的参数，所以提供给你一段代码吧，不要光板砖，想想为什么。</div>
<div>&nbsp;</div>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python2 </span>
&nbsp;
 <span style="color: #ff7700;font-weight:bold;">import</span> sqlite3 
 <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">datetime</span> 
 <span style="color: #ff7700;font-weight:bold;">import</span> contextlib 
&nbsp;
 <span style="color: #ff7700;font-weight:bold;">with</span> sqlite3.<span style="color: black;">connect</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;testing.db&quot;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">as</span> conn: 
     <span style="color: #ff7700;font-weight:bold;">with</span> contextlib.<span style="color: black;">closing</span><span style="color: black;">&#40;</span>conn.<span style="color: black;">cursor</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">as</span> cursor: 
         cursor.<span style="color: black;">execute</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span><span style="color: #483d8b;">'create table if not exists person ( 
                 id int, 
                 name text, 
                 birthday text 
                 )'</span><span style="color: #483d8b;">''</span><span style="color: black;">&#41;</span> 
&nbsp;
         cursor.<span style="color: black;">execute</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span><span style="color: #483d8b;">'insert into person values 
                 (1, '</span>Zhang San<span style="color: #483d8b;">', &quot;1980-01-02&quot;) 
                 '</span><span style="color: #483d8b;">''</span><span style="color: black;">&#41;</span> 
&nbsp;
         cursor.<span style="color: black;">execute</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span><span style="color: #483d8b;">'insert into person values 
                 (2, '</span>Li Si<span style="color: #483d8b;">', ?) 
                 '</span><span style="color: #483d8b;">''</span>, <span style="color: black;">&#91;</span><span style="color: #dc143c;">datetime</span>.<span style="color: #dc143c;">datetime</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1990</span>,<span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">4</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> 
&nbsp;
         cursor.<span style="color: black;">execute</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span><span style="color: #483d8b;">'insert into person values 
                 (?, ?, ?) 
                 '</span><span style="color: #483d8b;">''</span>, <span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span>, <span style="color: #483d8b;">&quot;Wang Wu&quot;</span>, <span style="color: #dc143c;">datetime</span>.<span style="color: #dc143c;">datetime</span>.<span style="color: black;">now</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> 
&nbsp;
         cursor.<span style="color: black;">executemany</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span><span style="color: #483d8b;">'insert into person values 
                 (?, ?, ?) 
                 '</span><span style="color: #483d8b;">''</span>, <span style="color: black;">&#91;</span> 
                     <span style="color: black;">&#40;</span><span style="color: #ff4500;">4</span>, <span style="color: #483d8b;">&quot;Alice&quot;</span>, <span style="color: #dc143c;">datetime</span>.<span style="color: #dc143c;">datetime</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2001</span>,<span style="color: #ff4500;">7</span>,<span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>, 
                     <span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span>, <span style="color: #483d8b;">&quot;Bob&quot;</span>, <span style="color: #dc143c;">datetime</span>.<span style="color: #dc143c;">datetime</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2002</span>,<span style="color: #ff4500;">9</span>,<span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>, 
                     <span style="color: black;">&#40;</span><span style="color: #ff4500;">6</span>, <span style="color: #483d8b;">&quot;Cindy&quot;</span>, <span style="color: #dc143c;">datetime</span>.<span style="color: #dc143c;">datetime</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2003</span>,<span style="color: #ff4500;">11</span>,<span style="color: #ff4500;">12</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>, 
                     <span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> 
&nbsp;
         d_str = <span style="color: #008000;">raw_input</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Before which date? (in yyyy-MM-dd. for example: 1995-5-6): &quot;</span><span style="color: black;">&#41;</span> 
         d = <span style="color: #dc143c;">datetime</span>.<span style="color: #dc143c;">datetime</span>.<span style="color: black;">strptime</span><span style="color: black;">&#40;</span>d_str, <span style="color: #483d8b;">&quot;%Y-%m-%d&quot;</span><span style="color: black;">&#41;</span> 
&nbsp;
         cursor.<span style="color: black;">execute</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span><span style="color: #483d8b;">'select * from person where birthday &lt; ?'</span><span style="color: #483d8b;">''</span>, 
                 <span style="color: black;">&#91;</span> d <span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> 
&nbsp;
         a = cursor.<span style="color: black;">fetchall</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> 
         <span style="color: #ff7700;font-weight:bold;">print</span> a</pre></div></div>

<div>&nbsp;</div>
<div>&nbsp;文章参考自byr论坛wks同学~</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title=" SQL中使用WITH AS提高性能" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F07%2Fsql_with_as_performance%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E6%259C%2589%25E5%2585%25B3python%25E6%258B%25BCsql%25E6%2593%258D%25E4%25BD%259C%25E6%2595%25B0%25E6%258D%25AE%25E5%25BA%2593%25E7%259A%2584%25E6%2595%2585%25E4%25BA%258B%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;"> SQL中使用WITH AS提高性能</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="python脚本在crontab中无法执行解决" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpython%25E8%2584%259A%25E6%259C%25AC%25E5%259C%25A8crontab%25E4%25B8%25AD%25E6%2597%25A0%25E6%25B3%2595%25E6%2589%25A7%25E8%25A1%258C%25E8%25A7%25A3%25E5%2586%25B3%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E6%259C%2589%25E5%2585%25B3python%25E6%258B%25BCsql%25E6%2593%258D%25E4%25BD%259C%25E6%2595%25B0%25E6%258D%25AE%25E5%25BA%2593%25E7%259A%2584%25E6%2595%2585%25E4%25BA%258B%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">python脚本在crontab中无法执行解决</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用pdb调试python程序" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F02%2F%25E4%25BD%25BF%25E7%2594%25A8pdb%25E8%25B0%2583%25E8%25AF%2595python%25E7%25A8%258B%25E5%25BA%258F%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E6%259C%2589%25E5%2585%25B3python%25E6%258B%25BCsql%25E6%2593%258D%25E4%25BD%259C%25E6%2595%25B0%25E6%258D%25AE%25E5%25BA%2593%25E7%259A%2584%25E6%2595%2585%25E4%25BA%258B%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用pdb调试python程序</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python time时间用法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F02%2Fpython-time%25E6%2597%25B6%25E9%2597%25B4%25E7%2594%25A8%25E6%25B3%2595%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E6%259C%2589%25E5%2585%25B3python%25E6%258B%25BCsql%25E6%2593%258D%25E4%25BD%259C%25E6%2595%25B0%25E6%258D%25AE%25E5%25BA%2593%25E7%259A%2584%25E6%2595%2585%25E4%25BA%258B%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python time时间用法</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python执行系统命令的3种方法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F02%2Fpython%25E6%2589%25A7%25E8%25A1%258C%25E7%25B3%25BB%25E7%25BB%259F%25E5%2591%25BD%25E4%25BB%25A4%25E7%259A%25843%25E7%25A7%258D%25E6%2596%25B9%25E6%25B3%2595%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E6%259C%2589%25E5%2585%25B3python%25E6%258B%25BCsql%25E6%2593%258D%25E4%25BD%259C%25E6%2595%25B0%25E6%258D%25AE%25E5%25BA%2593%25E7%259A%2584%25E6%2595%2585%25E4%25BA%258B%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python执行系统命令的3种方法</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://neoremind.net/2012/05/%e6%9c%89%e5%85%b3python%e6%8b%bcsql%e6%93%8d%e4%bd%9c%e6%95%b0%e6%8d%ae%e5%ba%93%e7%9a%84%e6%95%85%e4%ba%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>利用spring的BeanNameAutoProxyCreator做事务管理配置</title>
		<link>http://neoremind.net/2012/05/%e5%88%a9%e7%94%a8spring%e7%9a%84beannameautoproxycreator%e5%81%9a%e4%ba%8b%e5%8a%a1%e7%ae%a1%e7%90%86%e9%85%8d%e7%bd%ae/</link>
		<comments>http://neoremind.net/2012/05/%e5%88%a9%e7%94%a8spring%e7%9a%84beannameautoproxycreator%e5%81%9a%e4%ba%8b%e5%8a%a1%e7%ae%a1%e7%90%86%e9%85%8d%e7%bd%ae/#comments</comments>
		<pubDate>Wed, 09 May 2012 16:36:21 +0000</pubDate>
		<dc:creator>neo</dc:creator>
				<category><![CDATA[J2EE]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://neoremind.net/?p=865</guid>
		<description><![CDATA[在项目开发时候，很多目标bean需要生成事务代理，可以为每一个目标bean配置一个&#160;TransactionProxyFactoryBean &#160;bean。这样做的话，可能最后变成配置地狱，此时可以考虑使用自动事务代理。&#160;
&#160;
applicationContext[......]<p class='read-more'><a href='http://neoremind.net/2012/05/%e5%88%a9%e7%94%a8spring%e7%9a%84beannameautoproxycreator%e5%81%9a%e4%ba%8b%e5%8a%a1%e7%ae%a1%e7%90%86%e9%85%8d%e7%bd%ae/'>继续阅读</a></p><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="Spring单测中的@Autowired和@Qualifier" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2011%2F08%2Fspring%25E4%25B8%25AD%25E7%259A%2584autowired%25E5%2592%258Cqualifier%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%2588%25A9%25E7%2594%25A8spring%25E7%259A%2584beannameautoproxycreator%25E5%2581%259A%25E4%25BA%258B%25E5%258A%25A1%25E7%25AE%25A1%25E7%2590%2586%25E9%2585%258D%25E7%25BD%25AE%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Spring单测中的@Autowired和@Qualifier</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Spring实现数据库读写分离" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2011%2F06%2Fspring%25E5%25AE%259E%25E7%258E%25B0%25E6%2595%25B0%25E6%258D%25AE%25E5%25BA%2593%25E8%25AF%25BB%25E5%2586%2599%25E5%2588%2586%25E7%25A6%25BB%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%2588%25A9%25E7%2594%25A8spring%25E7%259A%2584beannameautoproxycreator%25E5%2581%259A%25E4%25BA%258B%25E5%258A%25A1%25E7%25AE%25A1%25E7%2590%2586%25E9%2585%258D%25E7%25BD%25AE%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Spring实现数据库读写分离</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="几种Java常用的通信协议比较" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F03%2F%25E5%2587%25A0%25E7%25A7%258Djava%25E5%25B8%25B8%25E7%2594%25A8%25E7%259A%2584%25E9%2580%259A%25E4%25BF%25A1%25E5%258D%258F%25E8%25AE%25AE%25E6%25AF%2594%25E8%25BE%2583%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%2588%25A9%25E7%2594%25A8spring%25E7%259A%2584beannameautoproxycreator%25E5%2581%259A%25E4%25BA%258B%25E5%258A%25A1%25E7%25AE%25A1%25E7%2590%2586%25E9%2585%258D%25E7%25BD%25AE%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">几种Java常用的通信协议比较</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Java内存管理与垃圾回收" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F04%2Fjava%25E5%2586%2585%25E5%25AD%2598%25E7%25AE%25A1%25E7%2590%2586%25E4%25B8%258E%25E5%259E%2583%25E5%259C%25BE%25E5%259B%259E%25E6%2594%25B6%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%2588%25A9%25E7%2594%25A8spring%25E7%259A%2584beannameautoproxycreator%25E5%2581%259A%25E4%25BA%258B%25E5%258A%25A1%25E7%25AE%25A1%25E7%2590%2586%25E9%2585%258D%25E7%25BD%25AE%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/02/11/15256086.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Java内存管理与垃圾回收</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Spring AOP动态代理初学" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2011%2F06%2Fspring-aop%25E5%258A%25A8%25E6%2580%2581%25E4%25BB%25A3%25E7%2590%2586%25E5%2588%259D%25E5%25AD%25A6%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%2588%25A9%25E7%2594%25A8spring%25E7%259A%2584beannameautoproxycreator%25E5%2581%259A%25E4%25BA%258B%25E5%258A%25A1%25E7%25AE%25A1%25E7%2590%2586%25E9%2585%258D%25E7%25BD%25AE%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Spring AOP动态代理初学</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>在项目开发时候，很多目标bean需要生成事务代理，可以为每一个目标bean配置一个&nbsp;TransactionProxyFactoryBean &nbsp;bean。这样做的话，可能最后变成配置地狱，此时可以考虑使用自动事务代理。&nbsp;</p>
<div>&nbsp;</div>
<div>applicationContext.xml配置可以加入如下，不解释：</div>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>  
<span style="color: #00bbdd;">&lt;!DOCTYPE beans PUBLIC &quot;-//SPRING//DTD BEAN//EN&quot; &quot;http://www.springframework.org/dtd/spring-beans.dtd&quot;&gt;</span>  
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;dataSource&quot;</span>  </span>
<span style="color: #009900;">        <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.apache.commons.dbcp.BasicDataSource&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;driverClassName&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>  
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.mysql.jdbc.Driver<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;url&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>  
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jdbc:mysql://localhost:3306/myuser<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;username&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>  
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>lighter<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;password&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>  
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>12345<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;sessionFactory&quot;</span>  </span>
<span style="color: #009900;">        <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.orm.hibernate3.LocalSessionFactoryBean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dataSource&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;dataSource&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernateProperties&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>  
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;props<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prop</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.dialect&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>  
                    org.hibernate.dialect.MySQLDialect  
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prop</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.show_sql&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/props<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;mappingResources&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>  
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org/mmc/dao/domain/User.hbm.xml<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
    <span style="color: #808080; font-style: italic;">&lt;!-- 配置Hibernate的事务管理器 --&gt;</span>  
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;transactionManager&quot;</span>  </span>
<span style="color: #009900;">        <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.orm.hibernate3.HibernateTransactionManager&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;sessionFactory&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;sessionFactory&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>  
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- 定义事务拦截器bean --&gt;</span>  
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;transactionInterceptor&quot;</span>  </span>
<span style="color: #009900;">        <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.transaction.interceptor.TransactionInterceptor&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;transactionManager&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;transactionManager&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;transactionAttributes&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>  
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;props<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prop</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;insert*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>PROPAGATION_REQUIRED<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prop</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;find*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>PROPAGATION_REQUIRED,readOnly<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prop</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>PROPAGATION_REQUIRED<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/props<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- 定义BeanNameAutoProxyCreator--&gt;</span>  
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span>  </span>
<span style="color: #009900;">        <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;beanNames&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>  
        <span style="color: #808080; font-style: italic;">&lt;!-- 所有名字以DAO,Service结尾的bean,将由该&quot;bean后处理器&quot;为其创建事务代理;实际上应该在业务层进行事务管理,这里只是举一个简单例子 --&gt;</span>  
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>*DAO,*Service<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
        <span style="color: #808080; font-style: italic;">&lt;!--  下面定义BeanNameAutoProxyCreator所需的事务拦截器--&gt;</span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;interceptorNames&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>  
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
                <span style="color: #808080; font-style: italic;">&lt;!-- 可以增加其他的拦截器 --&gt;</span>  
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>transactionInterceptor<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- 举下面这一个例子:这时候,这一个bean已经有了事务管理,可以增加类似的bean --&gt;</span>  
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;searchUserDAO&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.mmc.dao.impl.SearchUserDAO&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;sessionFactory&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;sessionFactory&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>  
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="Spring单测中的@Autowired和@Qualifier" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2011%2F08%2Fspring%25E4%25B8%25AD%25E7%259A%2584autowired%25E5%2592%258Cqualifier%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%2588%25A9%25E7%2594%25A8spring%25E7%259A%2584beannameautoproxycreator%25E5%2581%259A%25E4%25BA%258B%25E5%258A%25A1%25E7%25AE%25A1%25E7%2590%2586%25E9%2585%258D%25E7%25BD%25AE%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Spring单测中的@Autowired和@Qualifier</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Spring实现数据库读写分离" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2011%2F06%2Fspring%25E5%25AE%259E%25E7%258E%25B0%25E6%2595%25B0%25E6%258D%25AE%25E5%25BA%2593%25E8%25AF%25BB%25E5%2586%2599%25E5%2588%2586%25E7%25A6%25BB%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%2588%25A9%25E7%2594%25A8spring%25E7%259A%2584beannameautoproxycreator%25E5%2581%259A%25E4%25BA%258B%25E5%258A%25A1%25E7%25AE%25A1%25E7%2590%2586%25E9%2585%258D%25E7%25BD%25AE%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Spring实现数据库读写分离</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="几种Java常用的通信协议比较" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F03%2F%25E5%2587%25A0%25E7%25A7%258Djava%25E5%25B8%25B8%25E7%2594%25A8%25E7%259A%2584%25E9%2580%259A%25E4%25BF%25A1%25E5%258D%258F%25E8%25AE%25AE%25E6%25AF%2594%25E8%25BE%2583%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%2588%25A9%25E7%2594%25A8spring%25E7%259A%2584beannameautoproxycreator%25E5%2581%259A%25E4%25BA%258B%25E5%258A%25A1%25E7%25AE%25A1%25E7%2590%2586%25E9%2585%258D%25E7%25BD%25AE%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">几种Java常用的通信协议比较</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Java内存管理与垃圾回收" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2010%2F04%2Fjava%25E5%2586%2585%25E5%25AD%2598%25E7%25AE%25A1%25E7%2590%2586%25E4%25B8%258E%25E5%259E%2583%25E5%259C%25BE%25E5%259B%259E%25E6%2594%25B6%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%2588%25A9%25E7%2594%25A8spring%25E7%259A%2584beannameautoproxycreator%25E5%2581%259A%25E4%25BA%258B%25E5%258A%25A1%25E7%25AE%25A1%25E7%2590%2586%25E9%2585%258D%25E7%25BD%25AE%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/02/11/15256086.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Java内存管理与垃圾回收</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Spring AOP动态代理初学" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2011%2F06%2Fspring-aop%25E5%258A%25A8%25E6%2580%2581%25E4%25BB%25A3%25E7%2590%2586%25E5%2588%259D%25E5%25AD%25A6%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E5%2588%25A9%25E7%2594%25A8spring%25E7%259A%2584beannameautoproxycreator%25E5%2581%259A%25E4%25BA%258B%25E5%258A%25A1%25E7%25AE%25A1%25E7%2590%2586%25E9%2585%258D%25E7%25BD%25AE%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Spring AOP动态代理初学</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://neoremind.net/2012/05/%e5%88%a9%e7%94%a8spring%e7%9a%84beannameautoproxycreator%e5%81%9a%e4%ba%8b%e5%8a%a1%e7%ae%a1%e7%90%86%e9%85%8d%e7%bd%ae/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>python脚本在crontab中无法执行解决</title>
		<link>http://neoremind.net/2012/05/python%e8%84%9a%e6%9c%ac%e5%9c%a8crontab%e4%b8%ad%e6%97%a0%e6%b3%95%e6%89%a7%e8%a1%8c%e8%a7%a3%e5%86%b3/</link>
		<comments>http://neoremind.net/2012/05/python%e8%84%9a%e6%9c%ac%e5%9c%a8crontab%e4%b8%ad%e6%97%a0%e6%b3%95%e6%89%a7%e8%a1%8c%e8%a7%a3%e5%86%b3/#comments</comments>
		<pubDate>Wed, 09 May 2012 11:40:39 +0000</pubDate>
		<dc:creator>neo</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://neoremind.net/?p=863</guid>
		<description><![CDATA[&#160;今天在crontab里配置了一个python脚本定时执行，配置信息如下：

# crontab -l
35 9 * * * cd /home/work/test; ./test.py

&#160;结果没有任何输出就是执行不了，利用下面命令观察crontab日志。

# su - roo[......]<p class='read-more'><a href='http://neoremind.net/2012/05/python%e8%84%9a%e6%9c%ac%e5%9c%a8crontab%e4%b8%ad%e6%97%a0%e6%b3%95%e6%89%a7%e8%a1%8c%e8%a7%a3%e5%86%b3/'>继续阅读</a></p><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="有关Python拼SQL操作数据库的故事" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E6%259C%2589%25E5%2585%25B3python%25E6%258B%25BCsql%25E6%2593%258D%25E4%25BD%259C%25E6%2595%25B0%25E6%258D%25AE%25E5%25BA%2593%25E7%259A%2584%25E6%2595%2585%25E4%25BA%258B%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpython%25E8%2584%259A%25E6%259C%25AC%25E5%259C%25A8crontab%25E4%25B8%25AD%25E6%2597%25A0%25E6%25B3%2595%25E6%2589%25A7%25E8%25A1%258C%25E8%25A7%25A3%25E5%2586%25B3%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/05/12/25889060.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">有关Python拼SQL操作数据库的故事</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用pdb调试python程序" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F02%2F%25E4%25BD%25BF%25E7%2594%25A8pdb%25E8%25B0%2583%25E8%25AF%2595python%25E7%25A8%258B%25E5%25BA%258F%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpython%25E8%2584%259A%25E6%259C%25AC%25E5%259C%25A8crontab%25E4%25B8%25AD%25E6%2597%25A0%25E6%25B3%2595%25E6%2589%25A7%25E8%25A1%258C%25E8%25A7%25A3%25E5%2586%25B3%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用pdb调试python程序</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python time时间用法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F02%2Fpython-time%25E6%2597%25B6%25E9%2597%25B4%25E7%2594%25A8%25E6%25B3%2595%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpython%25E8%2584%259A%25E6%259C%25AC%25E5%259C%25A8crontab%25E4%25B8%25AD%25E6%2597%25A0%25E6%25B3%2595%25E6%2589%25A7%25E8%25A1%258C%25E8%25A7%25A3%25E5%2586%25B3%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python time时间用法</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python执行系统命令的3种方法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F02%2Fpython%25E6%2589%25A7%25E8%25A1%258C%25E7%25B3%25BB%25E7%25BB%259F%25E5%2591%25BD%25E4%25BB%25A4%25E7%259A%25843%25E7%25A7%258D%25E6%2596%25B9%25E6%25B3%2595%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpython%25E8%2584%259A%25E6%259C%25AC%25E5%259C%25A8crontab%25E4%25B8%25AD%25E6%2597%25A0%25E6%25B3%2595%25E6%2589%25A7%25E8%25A1%258C%25E8%25A7%25A3%25E5%2586%25B3%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python执行系统命令的3种方法</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="pymongo批量插入" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpymongo%25E6%2589%25B9%25E9%2587%258F%25E6%258F%2592%25E5%2585%25A5%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpython%25E8%2584%259A%25E6%259C%25AC%25E5%259C%25A8crontab%25E4%25B8%25AD%25E6%2597%25A0%25E6%25B3%2595%25E6%2589%25A7%25E8%25A1%258C%25E8%25A7%25A3%25E5%2586%25B3%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">pymongo批量插入</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;今天在crontab里配置了一个python脚本定时执行，配置信息如下：</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;"># crontab -l</span>
<span style="color: #0000dd;">35</span> <span style="color: #0000dd;">9</span> <span style="color: #339933;">*</span> <span style="color: #339933;">*</span> <span style="color: #339933;">*</span> cd <span style="color: #339933;">/</span>home<span style="color: #339933;">/</span>work<span style="color: #339933;">/</span>test<span style="color: #339933;">;</span> .<span style="color: #339933;">/</span>test.<span style="color: #202020;">py</span></pre></div></div>

<p>&nbsp;结果没有任何输出就是执行不了，利用下面命令观察crontab日志。</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;"># su - root</span>
<span style="color: #339933;"># tail -f /var/log/cron</span></pre></div></div>

<p>&nbsp;发现任务按时运行了，问题就奇怪了。</p>
<p>后来想到是不是环境变量引起的，于是检查python脚本的头部，将python的执行命令加入进去就好了，例如：</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#!/usr/local/bin/python</span>
<span style="color: #339933;"># coding=utf-8</span>
<span style="color: #339933;">#</span>
<span style="color: #339933;">#   Author: neoremind</span>
<span style="color: #339933;">#   E-mail: neoremind@baidu.com</span>
<span style="color: #339933;">#   Function: xxx</span>
<span style="color: #339933;">#</span></pre></div></div>

<p>&nbsp;将来要记住这个小tip，经验啊经验</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p style="margin:0;padding:0;height:1px;overflow:hidden;">
    <script type="text/javascript"><!--
        var wumiiSitePrefix = "http://neoremind.net";
        var wumiiEnableCustomPos = false;
        var wumiiParams = "&#038;num=5&#038;mode=3&#038;displayInFeed=1&#038;version=1.0.5.5&#038;pf=WordPress2.9.2";
    //--></script><script type="text/javascript" src="http://widget.wumii.com/ext/relatedItemsWidget.htm"></script><a href="http://www.wumii.com/widget/relatedItems.htm" style="border:0;"><img src="http://static.wumii.com/images/pixel.png" alt="无觅相关文章插件，快速提升流量" style="border:0;padding:0;margin:0;" /></a></p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="有关Python拼SQL操作数据库的故事" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2F%25E6%259C%2589%25E5%2585%25B3python%25E6%258B%25BCsql%25E6%2593%258D%25E4%25BD%259C%25E6%2595%25B0%25E6%258D%25AE%25E5%25BA%2593%25E7%259A%2584%25E6%2595%2585%25E4%25BA%258B%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpython%25E8%2584%259A%25E6%259C%25AC%25E5%259C%25A8crontab%25E4%25B8%25AD%25E6%2597%25A0%25E6%25B3%2595%25E6%2589%25A7%25E8%25A1%258C%25E8%25A7%25A3%25E5%2586%25B3%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/05/12/25889060.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">有关Python拼SQL操作数据库的故事</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用pdb调试python程序" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F02%2F%25E4%25BD%25BF%25E7%2594%25A8pdb%25E8%25B0%2583%25E8%25AF%2595python%25E7%25A8%258B%25E5%25BA%258F%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpython%25E8%2584%259A%25E6%259C%25AC%25E5%259C%25A8crontab%25E4%25B8%25AD%25E6%2597%25A0%25E6%25B3%2595%25E6%2589%25A7%25E8%25A1%258C%25E8%25A7%25A3%25E5%2586%25B3%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用pdb调试python程序</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python time时间用法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F02%2Fpython-time%25E6%2597%25B6%25E9%2597%25B4%25E7%2594%25A8%25E6%25B3%2595%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpython%25E8%2584%259A%25E6%259C%25AC%25E5%259C%25A8crontab%25E4%25B8%25AD%25E6%2597%25A0%25E6%25B3%2595%25E6%2589%25A7%25E8%25A1%258C%25E8%25A7%25A3%25E5%2586%25B3%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python time时间用法</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python执行系统命令的3种方法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F02%2Fpython%25E6%2589%25A7%25E8%25A1%258C%25E7%25B3%25BB%25E7%25BB%259F%25E5%2591%25BD%25E4%25BB%25A4%25E7%259A%25843%25E7%25A7%258D%25E6%2596%25B9%25E6%25B3%2595%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpython%25E8%2584%259A%25E6%259C%25AC%25E5%259C%25A8crontab%25E4%25B8%25AD%25E6%2597%25A0%25E6%25B3%2595%25E6%2589%25A7%25E8%25A1%258C%25E8%25A7%25A3%25E5%2586%25B3%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python执行系统命令的3种方法</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="pymongo批量插入" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpymongo%25E6%2589%25B9%25E9%2587%258F%25E6%258F%2592%25E5%2585%25A5%2F&from=http%3A%2F%2Fneoremind.net%2F2012%2F05%2Fpython%25E8%2584%259A%25E6%259C%25AC%25E5%259C%25A8crontab%25E4%25B8%25AD%25E6%2597%25A0%25E6%25B3%2595%25E6%2589%25A7%25E8%25A1%258C%25E8%25A7%25A3%25E5%2586%25B3%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">pymongo批量插入</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://neoremind.net/2012/05/python%e8%84%9a%e6%9c%ac%e5%9c%a8crontab%e4%b8%ad%e6%97%a0%e6%b3%95%e6%89%a7%e8%a1%8c%e8%a7%a3%e5%86%b3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

