{"id":779,"date":"2018-02-02T17:00:01","date_gmt":"2018-02-02T09:00:01","guid":{"rendered":"http:\/\/www.withonly.com\/?p=779"},"modified":"2018-08-13T10:14:31","modified_gmt":"2018-08-13T02:14:31","slug":"%e8%a7%a3%e5%86%b3-python-3-%e8%b0%83%e7%94%a8-redis-%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%98%be%e7%a4%ba-b-%e5%89%8d%e7%bc%80%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/blog.5danyuan.com\/?p=779","title":{"rendered":"\u89e3\u51b3 Python 3 \u8c03\u7528 Redis \u5b57\u7b26\u4e32\u663e\u793a b \u524d\u7f00\u7684\u95ee\u9898"},"content":{"rendered":"<p>\u6628\u5929\u6709\u6309\u7167\u7f51\u4e0a\u7684\u6559\u7a0b\u53bb\u4f7f\u7528 Python \u8c03\u7528Redis \uff0c\u4ee3\u7801\u5f88\u7b80\u5355\uff0c\u5c31\u50cf\u4e0b\u9762\u8fd9\u6837\u5b50\uff1a<\/p>\n<p><a href=\"\/wp-content\/uploads\/2018\/02\/python-redis.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-780 size-full\" src=\"\/wp-content\/uploads\/2018\/02\/python-redis.png\" alt=\"\" width=\"824\" height=\"288\" srcset=\"https:\/\/blog.5danyuan.com\/wp-content\/uploads\/2018\/02\/python-redis.png 824w, https:\/\/blog.5danyuan.com\/wp-content\/uploads\/2018\/02\/python-redis-300x105.png 300w, https:\/\/blog.5danyuan.com\/wp-content\/uploads\/2018\/02\/python-redis-768x268.png 768w\" sizes=\"auto, (max-width: 824px) 100vw, 824px\" \/><\/a><\/p>\n<p>\u4f46\u662f\uff0c\u8fd0\u884c\u540e\u7684\u7ed3\u679c\u663e\u793a\u00a0 b&#8217;python&#8217; \uff0c\u591a\u4e86\u4e00\u4e2ab\uff0c\u4f46\u662f\u83b7\u53d6\u5b57\u7b26\u957f\u5ea6\u7684\u786e\u53c8\u662f\u5bf9\u7684\uff0c\u89c9\u5f97\u5f88\u662f\u5947\u602a\u3002<\/p>\n<p>\u4eca\u5929\u6709\u5411\u540c\u4e8b\u59b9\u5b50\u8bf7\u6559\uff0c\u540e\u6765\u5f97\u51fa\u7684\u7ed3\u8bba\u662f\u7528\u56de python 2.7\u3002\u548c\u59b9\u5b50\u7ee7\u7eed\u641c\u7d22\uff0c\u53d1\u73b0\u4e86\u89e3\u51b3\u65b9\u6cd5\uff1asys.stdout.buffer.write(r.get(&#8220;name&#8221;)) \uff0c\u8fd9\u4e48\u4e00\u6765\u9700\u8981\u518d\u5f15\u5165 sys \u5e93\uff0c\u800c\u4e14\u9700\u8981\u81ea\u5df1\u6dfb\u52a0\u6362\u884c\u7b26\u4e86\u3002<\/p>\n<p>\u7ee7\u7eed\u641c\u7d22\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u00a0print(r.get(&#8216;name&#8217;).decode(&#8216;utf-8&#8217;))\uff0c\u5373\u89e3\u7801\u4e00\u4e0b\u7136\u540e\u518d\u663e\u793a\u3002\u7a0d\u5fae\u597d\u4e86\u4e00\u70b9\uff0c\u4f46\u662f\u6bcf\u6b21\u8981\u8bfb\u53d6 Redis \u6570\u503c\u7684\u65f6\u5019\uff0c\u90fd\u8981\u8fd9\u4e48\u6765\u8f6c\u6362\u4e0b\u786e\u5b9e\u663e\u5f97\u6709\u70b9\u7325\u7410\u3002<\/p>\n<p>\u6211\u5728\u60f3\uff0c\u4e00\u5b9a\u8fd8\u6709\u66f4\u7b80\u5355\u7684\u65b9\u5f0f\u3002\u6700\u540e\u770b\u5230 stackoverflow \u548c\u7b80\u4e66\u4e0a\u4e5f\u8ba8\u8bba\u4e86\u8fd9\u4e2a\u4e8b\u60c5\uff0c\u6709\u4e00\u4e2a\u5251\u8d70\u504f\u950b\u7684\u8bbe\u7f6e\uff0c\u5c31\u662f\u5728\u6570\u636e\u5e93\u7684\u8fde\u63a5\u5b57\u7b26\u4e32\u91cc\u591a\u6dfb\u52a0\u4e00\u4e2a\u53c2\u6570\u00a0decode_responses=True\uff0c\u8fd9\u4e48\u4e00\u6765\u5c31\u4f1a\u81ea\u52a8\u5c06 response \u89e3\u7801\u3002\u8fd9\u4e48\u505a\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u662f\u6ca1\u6709\u95ee\u9898\u7684\uff0c\u9700\u8981\u989d\u5916\u6ce8\u610f\u7684\u662f\uff0c\u5982\u679c\u4fdd\u5b58\u5728 Redis \u6570\u636e\u5e93\u91cc\u7684\u539f\u59cb\u6570\u636e\u5c31\u662f\u4e8c\u8fdb\u5236\u7684\uff0c\u90a3\u4e48\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u53ef\u80fd\u5f97\u4e0d\u5230\u81ea\u5df1\u60f3\u8981\u7684\u7ed3\u679c\u3002<\/p>\n<p>\u5728\u5b9e\u9645\u8fd0\u7528\u7684\u65f6\u5019\uff0c\u5c31\u53ef\u4ee5\u7075\u6d3b\u8003\u8651\u4e86\uff0c\u9002\u5f53\u7684\u65f6\u5019\u7efc\u5408\u4f7f\u7528\u8fd9\u4e24\u79cd\u65b9\u5f0f\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6628\u5929\u6709\u6309\u7167\u7f51\u4e0a\u7684\u6559\u7a0b\u53bb\u4f7f\u7528 Python \u8c03\u7528Redis \uff0c\u4ee3\u7801\u5f88\u7b80\u5355\uff0c\u5c31\u50cf\u4e0b\u9762\u8fd9\u6837\u5b50\uff1a \u4f46\u662f\uff0c\u8fd0\u884c\u540e\u7684\u7ed3\u679c\u663e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[300],"tags":[217,303],"class_list":["post-779","post","type-post","status-publish","format-standard","hentry","category-python","tag-python","tag-redis"],"_links":{"self":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/posts\/779","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=779"}],"version-history":[{"count":0,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/posts\/779\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=779"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=779"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}