{"id":248397,"date":"2020-12-31T20:19:39","date_gmt":"2020-12-31T12:19:39","guid":{"rendered":"http:\/\/4563.org\/?p=248397"},"modified":"2020-12-31T20:19:39","modified_gmt":"2020-12-31T12:19:39","slug":"%e5%85%a8%e9%87%8f%e8%af%bb%e5%8f%96%e9%80%9f%e5%ba%a6","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=248397","title":{"rendered":"\u5168\u91cf\u8bfb\u53d6\u901f\u5ea6"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5168\u91cf\u8bfb\u53d6\u901f\u5ea6               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : fxrocks <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        \u6709 1 \u4e07\u591a\u4e2a\u7528\u6237\uff0c\u7528\u6237\u540d\u4e3a key\uff0chash \u5f62\u5f0f\u5b58\u50a8\uff0cuse1:{k1:v1, k2: v2,&#8230;kn: vn}, \u6bcf\u5929\u9700\u8981 load \u4e00\u6b21\u6240\u6709\u7528\u6237\uff0c\u6bcf\u4e2a\u7528\u6237\u6bcf\u6b21\u63d0\u53d6\u5927\u6982 10 \u4e2a\u5b57\u6bb5\u3002<\/p>\n<p>\u6c42\u95ee<br \/>1 \u3002server \u672c\u673a\u4e0a\u7528 Python redis \u8fd9\u6837\u8bfb\u4e00\u6b21\u5927\u6982\u591a\u4e45\uff1f 10 \u4e07\u5462\uff1f<br \/>2 \u3002user \u5217\u8868\u662f\u5426\u8981\u6709\u5fc5\u8981\u5355\u72ec\u4e00\u6761 kv \u5b58\u50a8\uff1f      <\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>14<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4824353\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : YouLMAO <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u626b\u5e93\u64cd\u4f5c, \u81ea\u52a8\u88ab dba \u7684\u76d1\u63a7\u811a\u672c\u62e6\u622a\u4e86, \u4e0d\u8981\u9a9a\u64cd\u4f5c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4824354\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : fxrocks <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @YouLMAO \u81ea\u5df1\u641e\u5f97\uff0c\u6ca1\u6709 dba :D\uff0c\u90a3\u6709\u5176\u4ed6\u529e\u6cd5\u5417\uff1f\u6211\u7528 Python redis                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4824355\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : YouLMAO <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5206\u6bb5\u626b\u63cf SCAN 0 COUNT 100 MATCH papapa*                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4824356\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : RedisMasterNode <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53ea\u6709 1w \u4e2a\u7528\u6237\uff0c\u65e2\u7136\u6ca1\u6709 dba\uff0c\u8003\u8651\u5230\u6570\u636e\u91cf\u4e5f\u5f88\u5c0f\uff0c\u5982\u679c\u53ef\u4ee5\u63a5\u53d7\u963b\u585e\u5176\u4ed6\u547d\u4ee4\uff0c\u76f4\u63a5 keys user:*\u8fd9\u6837\u7684\u64cd\u4f5c\u5373\u53ef\u3002\u4ece\u54c8\u5e0c\u8868\u4e2d scan \u51fa\u8fd9\u4e48\u70b9\u6570\u636e\u8017\u65f6\u4f1a\u5f88\u4f4e\uff1b\u800c\u4e14\u4e0d\u662f\u53ef\u4ee5\u81ea\u5df1\u5b9e\u8df5\u6d4b\u8bd5\u4e00\u4e0b\u5417\uff0c\u5411 redis \u91cc\u9762\u5199 10w \u4e2a\u7528\u6237 key \u975e\u5e38\u5feb\u5427                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4824357\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : niubee1 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u5148\u641e\u6e05\u695a\u4e3a\u561b\u8981\u8fd9\u6837\u505a\uff0c\u4ece\u6e90\u5934\u5206\u6790\uff0c\u4e07\u4e00\u4f60\u7684\u65b9\u6848\u4ece\u6839\u672c\u4e0a\u5c31\u4e0d\u5bf9\u5462                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4824358\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Ptu2sha <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e00\u4e07\u6761\u5c0f case \u554a redis \u5f88\u5feb\u7684 <br \/>\u5f53\u7136\u5355\u673a rdb \u6216\u4ece\u673a\u62c9\u4e0b\u6765\u5904\u7406\u6700\u597d                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4824359\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : fxrocks <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @niubee1 \u56e0\u4e3a\u5077\u61d2\u4e0d\u60f3\u641e mysql \u4e4b\u7c7b\uff0c\u641e\u5173\u7cfb\u9ebb\u70e6\uff0credis \u90fd\u5806\u5728\u4e00\u4e2a hash \u91cc\u65b9\u4fbf\u554a :D\uff0c \u67e5\u8be2\u548c\u66f4\u65b0\u5355\u4e2a\u7528\u6237\u6570\u636e\u4e5f\u5feb\u3002\u5c31\u662f\u6bcf\u5929\u8bfb\u4e00\u6b21\u6240\u6709 key \u611f\u89c9\u4e0d\u592a\u723d\u3002<\/p>\n<p>@RedisMasterNode \u55ef\uff0c\u7b49\u4e0b\u8bd5\u4e00\u8bd5\u3002<\/p>\n<p>@Ptu2sha \u5355\u673a rdb \u662f\u6307\u590d\u5236 rdb \u5230\u53e6\u5916\u673a\u5668\u7136\u540e\u518d\u8bfb\u53d6\uff1f\u3002\u3002\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4824360\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : crclz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u662f\u51c6\u5907\u628a redis \u5f53 mysql \u4f7f\u5417\uff1f\u60f3\u60f3 ACID \u6709\u4fdd\u969c\u5417\uff1f<br \/>\u5982\u679c\u662f\u5bf9 redis \u4ee5\u53ca\u7f13\u5b58\u4e86\u89e3\u4e0d\u6df1\u7684\u4eba\uff0c\u6211\u63a8\u8350\u4f60\u53ea\u5c06 redis \u7528\u4e8e\u7f13\u5b58\uff0c\u4e25\u683c\u6309\u7167\uff1a\u67e5\u6570\u636e\u5e93\u65f6\u5199\u7f13\u5b58\u3001\u6570\u636e\u5e93\u66f4\u65b0\u65f6 invalidate \u7f13\u5b58\u3001\u7f13\u5b58\u6761\u76ee\u81ea\u52a8\u8fc7\u671f\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u5982\u679c\u60f3\u8981\u65b9\u4fbf\uff0c\u53ef\u4ee5\u7528 mysql json \u6216\u8005 postgres jsonb\uff0c\u6216\u8005 mongo                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4824361\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : fxrocks <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @RedisMasterNode <\/p>\n<p>\u8bd5\u4e86\u4e00\u4e0b\u8bfb\u5199 10 \u4e07\u6761 10 \u4e2a\u5b57\u6bb5\u5728 15 \u79d2\u4ee5\u5185\uff0c1 \u4e07\u6761\u5728 3 \u79d2\u4ee5\u5185\uff0c\u5b8c\u5168\u53ef\u4ee5\u63a5\u53d7\u3002\u53cd\u6b63\u6bcf\u5929\u624d\u4e00\u6b21\uff0c\u800c\u4e14\u77ed\u671f\u4e0d\u4f1a\u6709 1 \u4e07\u4e2a\u7528\u6237\u3002\u5c31\u8fd9\u4e48\u641e\u7b97\u4e86\u3002\u4f30\u8ba1\u653e\u5230\u4e91\u4e0a\u8981\u5feb\u4e9b\uff0c\u73b0\u5728\u662f\u5728\u6811\u8393\u6d3e 4 \u4e0a\u6d4b\u8bd5\u7684\u3002<\/p>\n<p>t0=time.time()<br \/>pool = redis.ConnectionPool(host=&#8217;192.168.31.115&#8242;, port=6379, db=0,decode_responses=True) <br \/>r = redis.Redis(connection_pool=pool)<\/p>\n<p>with r.pipeline(transaction=False) as p: <br \/> for n in range(100000):<br \/> k=f&#8221;client_{n}&#8221;<br \/> v={&#8220;k1&#8243;:&#8221;v1&#8243;,&#8221;k2&#8243;:&#8221;v2&#8243;,&#8221;k3&#8243;:&#8221;v3&#8243;,&#8221;k4&#8243;:&#8221;v4&#8243;,&#8221;k5&#8243;:&#8221;v5&#8243;,&#8221;k6&#8243;:&#8221;v6&#8243;,&#8221;k7&#8243;:&#8221;v7&#8243;,&#8221;k8&#8243;:&#8221;v8&#8243;,&#8221;k9&#8243;:&#8221;v9&#8243;,&#8221;k10&#8243;:&#8221;v10&#8221;}<br \/> p.hmset(k,v)<br \/> t1=time.time()<br \/> print(f&#8221;set in pip in {t1-t0} secs&#8221;)<br \/> p.execute()<br \/> t2=time.time()<br \/> print(f&#8221;pipe exec in {t2-t1} secs&#8221;)<br \/> print(f&#8221;total write in {t2-t0} secs&#8221;)<\/p>\n<p>t0=time.time() <br \/>with r.pipeline(transaction=False) as p: <br \/> for n in range(100000):<br \/> k=f&#8221;client_{n}&#8221; <br \/> p.hgetall(k)<br \/> t1=time.time()<br \/> print(f&#8221;read in pip in {t1-t0} secs&#8221;)<br \/> result=p.execute()<br \/> t2=time.time()<br \/> print(f&#8221;pipe exec in {t2-t1} secs&#8221;)<br \/> print(f&#8221;total read in {t2-t0} secs&#8221;)<br \/>&lt;ipython-input-71-ba09b5712492&gt;:9: DeprecationWarning: Pipeline.hmset() is deprecated. Use Pipeline.hset() instead.<br \/> p.hmset(k,v)<br \/>set in pip in 0.4727442264556885 secs<br \/>pipe exec in 14.024574041366577 secs<br \/>total write in 14.497318267822266 secs<\/p>\n<p>read in pip in 0.18680548667907715 secs<br \/>pipe exec in 12.720657110214233 secs<br \/>total read in 12.90746259689331 secs                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4824362\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : fxrocks <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @crclz <\/p>\n<p>\u611f\u8c22\u63d0\u9192\u3002ACID\uff0c\u6211\u7684\u4e1a\u52a1\u6bd4\u8f83\u7279\u6b8a\uff0c\u5927\u90e8\u5206\u8bfb\u5199\u90fd\u5728\u67d0\u4e2a\u56fa\u5b9a\u65f6\u95f4\u6bb5\uff0c\u51e0\u4e4e\u6bcf 10 \u79d2\u5c31\u66f4\u65b0\uff0c\u8fc7\u4e86\u4e1a\u52a1\u65f6\u95f4\u6bb5\u540e\uff0c\u57fa\u672c\u5c31\u6ca1\u6709\u64cd\u4f5c\u4e86\uff0c\u6240\u4ee5 D \u95ee\u9898\u4e0d\u5927\u3002A \u7684\u8bdd\uff0c\u6211\u8fd8\u4e0d\u77e5\u9053\u4e8b\u52a1\u5931\u8d25\u4f1a\u4e0d\u4f1a\u88ab python redis \u6355\u83b7\u3002\u3002\u3002\u8981\u67e5\u770b\u4e00\u4e0b\u3002<\/p>\n<p>\u53e6\u5916 mongoDB \u5c31\u6ca1\u6709\u8fd9\u4e2a\u95ee\u9898\u4e48\uff1f<\/p>\n<p>\u770b\u6765\u6ca1\u6709\u4eba\u7528\u7eaf redis \u54c8\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4824363\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : php8 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u666e\u901a\u670d\u52a1\u5668\uff0c\u5355\u6761 1kb \u4ee5\u5185\uff0credis \u8bfb\u53d6\u5927\u6982 10 \u4e07\u6bcf\u79d2                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4824364\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wellsc <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u624d\u4e00\u4e07\u591a\u6570\u636e\uff0c\u5206\u5206\u949f\u641e\u5b9a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4824365\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : pkupyx <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5355\u673a redis\uff0c\u81f3\u5c11\u6297\u4e2a 1Wqps \u5427\u3002<br \/>\u4e0d\u8fc7\u5e72\u561b\u4e0d\u5b58 mysql\uff0c\u7f13\u5b58\u5f00\u5927\u70b9\u751a\u81f3\u6574\u4e2a user \u8868\u90fd\u5728\u5185\u5b58\u91cc\u4e86\u3002\u3002\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4824366\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : nooper <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             10w \u4e00\u79d2\u949f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5168\u91cf\u8bfb\u53d6\u901f\u5ea6 \u8cc7\u6df1\u5927\u4f6c : fxr&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/248397"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=248397"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/248397\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=248397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=248397"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=248397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}