{"id":636,"date":"2023-02-26T11:44:24","date_gmt":"2023-02-26T03:44:24","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=636"},"modified":"2023-04-29T20:00:09","modified_gmt":"2023-04-29T12:00:09","slug":"redis-pipeline-technology","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/26\/redis-pipeline-technology\/","title":{"rendered":"Redis \u7ba1\u9053\u6280\u672f"},"content":{"rendered":"<p>Redis\u662f\u4e00\u79cd\u57fa\u4e8e\u5ba2\u6237\u7aef-\u670d\u52a1\u7aef\u6a21\u578b\u4ee5\u53ca\u8bf7\u6c42\/\u54cd\u5e94\u534f\u8bae\u7684TCP\u670d\u52a1\u3002\u8fd9\u610f\u5473\u7740\u901a\u5e38\u60c5\u51b5\u4e0b\u4e00\u4e2a\u8bf7\u6c42\u4f1a\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ul>\n<li>\u5ba2\u6237\u7aef\u5411\u670d\u52a1\u7aef\u53d1\u9001\u4e00\u4e2a\u67e5\u8be2\u8bf7\u6c42\uff0c\u5e76\u76d1\u542cSocket\u8fd4\u56de\uff0c\u901a\u5e38\u662f\u4ee5\u963b\u585e\u6a21\u5f0f\uff0c\u7b49\u5f85\u670d\u52a1\u7aef\u54cd\u5e94<\/li>\n<li>\u670d\u52a1\u7aef\u5904\u7406\u547d\u4ee4\uff0c\u5e76\u5c06\u7ed3\u679c\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef<\/li>\n<\/ul>\n<p><!-- more --><\/p>\n<h2>Redis \u7ba1\u9053\u6280\u672f<\/h2>\n<p>Redis \u7ba1\u9053\u6280\u672f\u53ef\u4ee5\u5728\u670d\u52a1\u7aef\u672a\u54cd\u5e94\u65f6\uff0c\u5ba2\u6237\u7aef\u53ef\u4ee5\u7ee7\u7eed\u5411\u670d\u52a1\u7aef\u53d1\u9001\u8bf7\u6c42\uff0c\u5e76\u6700\u7ec8\u4e00\u6b21\u6027\u8bfb\u53d6\u6240\u6709\u670d\u52a1\u7aef\u7684\u54cd\u5e94<\/p>\n<p>\u67e5\u770b Redis \u7ba1\u9053\uff0c\u53ea\u9700\u8981\u542f\u52a8 Redis \u5b9e\u4f8b\u5e76\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code class=\"language-bash\">$ (echo -en &quot;PING\\r\\n SET appblog redis\\r\\nGET appblog\\r\\nINCR visitor\\r\\nINCR visitor\\r\\nINCR visitor\\r\\n&quot;; sleep 10) | nc localhost 6379\n\n+PONG\n+OK\nredis\n:1\n:2\n:3<\/code><\/pre>\n<p>\u4ee5\u4e0a\u5b9e\u4f8b\u4e2d\u6211\u4eec\u901a\u8fc7\u4f7f\u7528 PING \u547d\u4ee4\u67e5\u770b Redis \u670d\u52a1\u662f\u5426\u53ef\u7528\uff0c\u4e4b\u540e\u6211\u4eec\u8bbe\u7f6e\u4e86 appblog \u7684\u503c\u4e3a redis\uff0c\u7136\u540e\u6211\u4eec\u83b7\u53d6 appblog \u7684\u503c\u5e76\u4f7f\u5f97 visitor \u81ea\u589e 3 \u6b21\u3002<\/p>\n<p>\u5728\u8fd4\u56de\u7684\u7ed3\u679c\u4e2d\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u8fd9\u4e9b\u547d\u4ee4\u4e00\u6b21\u6027\u5411 Redis \u670d\u52a1\u63d0\u4ea4\uff0c\u5e76\u6700\u7ec8\u4e00\u6b21\u6027\u8bfb\u53d6\u6240\u6709\u670d\u52a1\u7aef\u7684\u54cd\u5e94<\/p>\n<h2>\u7ba1\u9053\u6280\u672f\u7684\u4f18\u52bf<\/h2>\n<p>\u7ba1\u9053\u6280\u672f\u6700\u663e\u8457\u7684\u4f18\u52bf\u662f\u63d0\u9ad8\u4e86 Redis \u670d\u52a1\u7684\u6027\u80fd<\/p>\n<p>\u5728\u4e0b\u9762\u7684\u6d4b\u8bd5\u4e2d\uff0c\u6211\u4eec\u5c06\u4f7f\u7528Redis\u7684Ruby\u5ba2\u6237\u7aef\uff0c\u652f\u6301\u7ba1\u9053\u6280\u672f\u7279\u6027\uff0c\u6d4b\u8bd5\u7ba1\u9053\u6280\u672f\u5bf9\u901f\u5ea6\u7684\u63d0\u5347\u6548\u679c<\/p>\n<pre><code class=\"language-ruby\">require &#039;rubygems&#039; \nrequire &#039;redis&#039;\ndef bench(descr) \nstart = Time.now \nyield \nputs &quot;#{descr} #{Time.now-start} seconds&quot; \nend\ndef without_pipelining \nr = Redis.new \n10000.times { \n    r.ping \n} \nend\ndef with_pipelining \nr = Redis.new \nr.pipelined { \n    10000.times { \n        r.ping \n    } \n} \nend\nbench(&quot;without pipelining&quot;) { \n    without_pipelining \n} \nbench(&quot;with pipelining&quot;) { \n    with_pipelining \n}<\/code><\/pre>\n<p>\u4ece\u5904\u4e8e\u5c40\u57df\u7f51\u4e2d\u7684Mac OS X\u7cfb\u7edf\u4e0a\u6267\u884c\u4e0a\u9762\u8fd9\u4e2a\u7b80\u5355\u811a\u672c\u7684\u6570\u636e\u8868\u660e\uff0c\u5f00\u542f\u4e86\u7ba1\u9053\u64cd\u4f5c\u540e\uff0c\u5f80\u8fd4\u5ef6\u65f6\u5df2\u7ecf\u88ab\u6539\u5584\u5f97\u76f8\u5f53\u4f4e\u4e86<\/p>\n<pre><code class=\"language-bash\">without pipelining 1.185238 seconds \nwith pipelining 0.250783 seconds<\/code><\/pre>\n<p>\u5982\u4f60\u6240\u89c1\uff0c\u5f00\u542f\u7ba1\u9053\u540e\uff0c\u6211\u4eec\u7684\u901f\u5ea6\u6548\u7387\u63d0\u5347\u4e865\u500d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Redis\u662f\u4e00\u79cd\u57fa\u4e8e\u5ba2\u6237\u7aef-\u670d\u52a1\u7aef\u6a21\u578b\u4ee5\u53ca\u8bf7\u6c42\/\u54cd\u5e94\u534f\u8bae\u7684TCP\u670d\u52a1\u3002\u8fd9\u610f\u5473\u7740\u901a\u5e38\u60c5\u51b5\u4e0b\u4e00\u4e2a\u8bf7\u6c42\u4f1a\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-636","post","type-post","status-publish","format-standard","hentry","category-redis"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/636","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=636"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/636\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=636"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=636"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=636"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}