{"id":193881,"date":"2024-11-13T01:56:20","date_gmt":"2024-11-12T17:56:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/193881\/"},"modified":"2024-11-13T01:56:21","modified_gmt":"2024-11-12T17:56:21","slug":"%e6%a5%ad%e5%8b%99%e5%ad%97%e5%85%b8%e7%b4%a2%e5%bc%95redis%e5%af%a6%e7%8f%be%e7%84%a1%e7%b8%ab%e6%93%b4%e5%b1%95%ef%bc%88%e6%a5%ad%e5%8b%99%e5%ad%97%e5%85%b8%e6%94%be%e5%88%b0redis%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/193881\/","title":{"rendered":"\u696d\u52d9\u5b57\u5178\u7d22\u5f15Redis\u5be6\u73fe\u7121\u7e2b\u64f4\u5c55\uff08\u696d\u52d9\u5b57\u5178\u653e\u5230redis\uff09"},"content":{"rendered":"<h1 id=\"%e6%a5%ad%e5%8b%99%e5%ad%97%e5%85%b8%e7%b4%a2%e5%bc%95redis%e5%af%a6%e7%8f%be%e7%84%a1%e7%b8%ab%e6%93%b4%e5%b1%95%ef%bc%88%e6%a5%ad%e5%8b%99%e5%ad%97%e5%85%b8%e6%94%be%e5%88%b0redis%ef%bc%89-ePArJDaFyh\">\u696d\u52d9\u5b57\u5178\u7d22\u5f15Redis\u5be6\u73fe\u7121\u7e2b\u64f4\u5c55\uff08\u696d\u52d9\u5b57\u5178\u653e\u5230Redis\uff09<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u6642\u4ee3\uff0c\u4f01\u696d\u9700\u8981\u5feb\u901f\u4e14\u9ad8\u6548\u5730\u5b58\u53d6\u548c\u7ba1\u7406\u5927\u91cf\u6578\u64da\u3002\u696d\u52d9\u5b57\u5178\u4f5c\u70ba\u4e00\u7a2e\u95dc\u9375\u7684\u6578\u64da\u7d50\u69cb\uff0c\u80fd\u5920\u5e6b\u52a9\u4f01\u696d\u5728\u4e0d\u540c\u7684\u696d\u52d9\u5834\u666f\u4e2d\u9032\u884c\u6578\u64da\u67e5\u8a62\u548c\u7ba1\u7406\u3002\u96a8\u8457\u696d\u52d9\u9700\u6c42\u7684\u589e\u9577\uff0c\u50b3\u7d71\u7684\u6578\u64da\u5eab\u53ef\u80fd\u7121\u6cd5\u6eff\u8db3\u9ad8\u6548\u64f4\u5c55\u7684\u9700\u6c42\uff0c\u56e0\u6b64\uff0c\u5c07\u696d\u52d9\u5b57\u5178\u653e\u5230Redis\u4e2d\u6210\u70ba\u4e86\u4e00\u7a2e\u7406\u60f3\u7684\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e6%a5%ad%e5%8b%99%e5%ad%97%e5%85%b8%ef%bc%9f-ePArJDaFyh\">\u4ec0\u9ebc\u662f\u696d\u52d9\u5b57\u5178\uff1f<\/h2>\n<p>\u696d\u52d9\u5b57\u5178\u662f\u6307\u4e00\u7d44\u7528\u65bc\u63cf\u8ff0\u696d\u52d9\u6982\u5ff5\u53ca\u5176\u95dc\u4fc2\u7684\u6578\u64da\u7d50\u69cb\u3002\u5b83\u901a\u5e38\u5305\u542b\u4e86\u696d\u52d9\u4e2d\u4f7f\u7528\u7684\u5404\u7a2e\u8853\u8a9e\u3001\u5b9a\u7fa9\u53ca\u5176\u5c6c\u6027\u3002\u696d\u52d9\u5b57\u5178\u7684\u4e3b\u8981\u76ee\u7684\u662f\u63d0\u4f9b\u4e00\u500b\u7d71\u4e00\u7684\u6578\u64da\u8996\u5716\uff0c\u5e6b\u52a9\u4f01\u696d\u5728\u4e0d\u540c\u7684\u7cfb\u7d71\u548c\u61c9\u7528\u4e2d\u4fdd\u6301\u6578\u64da\u7684\u4e00\u81f4\u6027\u548c\u6e96\u78ba\u6027\u3002<\/p>\n<h2 id=\"redis%e7%9a%84%e7%89%b9%e9%bb%9e-ePArJDaFyh\">Redis\u7684\u7279\u9ede<\/h2>\n<p>Redis\u662f\u4e00\u7a2e\u9ad8\u6027\u80fd\u7684\u9375\u503c\u6578\u64da\u5eab\uff0c\u5177\u6709\u4ee5\u4e0b\u5e7e\u500b\u986f\u8457\u7279\u9ede\uff1a<\/p>\n<ul>\n<li><strong>\u9ad8\u6548\u7684\u6578\u64da\u5b58\u53d6\uff1a<\/strong>Redis\u652f\u6301\u5feb\u901f\u7684\u8b80\u53d6\u548c\u5beb\u5165\u64cd\u4f5c\uff0c\u80fd\u5920\u5728\u6beb\u79d2\u7d1a\u5225\u5167\u5b8c\u6210\u6578\u64da\u67e5\u8a62\u3002<\/li>\n<li><strong>\u652f\u6301\u591a\u7a2e\u6578\u64da\u7d50\u69cb\uff1a<\/strong>\u9664\u4e86\u57fa\u672c\u7684\u9375\u503c\u5c0d\uff0cRedis\u9084\u652f\u6301\u5217\u8868\u3001\u96c6\u5408\u3001\u6709\u5e8f\u96c6\u5408\u548c\u54c8\u5e0c\u7b49\u591a\u7a2e\u6578\u64da\u7d50\u69cb\uff0c\u9019\u4f7f\u5f97\u5b83\u5728\u8655\u7406\u8907\u96dc\u6578\u64da\u6642\u66f4\u52a0\u9748\u6d3b\u3002<\/li>\n<li><strong>\u6301\u4e45\u5316\u9078\u9805\uff1a<\/strong>Redis\u63d0\u4f9b\u4e86\u591a\u7a2e\u6301\u4e45\u5316\u6a5f\u5236\uff0c\u80fd\u5920\u5c07\u6578\u64da\u4fdd\u5b58\u5728\u78c1\u789f\u4e2d\uff0c\u9632\u6b62\u6578\u64da\u4e1f\u5931\u3002<\/li>\n<li><strong>\u7121\u7e2b\u64f4\u5c55\uff1a<\/strong>Redis\u652f\u6301\u5206\u7247\u548c\u96c6\u7fa4\u6a21\u5f0f\uff0c\u80fd\u5920\u8f15\u9b06\u5730\u64f4\u5c55\u4ee5\u61c9\u5c0d\u4e0d\u65b7\u589e\u9577\u7684\u6578\u64da\u9700\u6c42\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%b0%87%e6%a5%ad%e5%8b%99%e5%ad%97%e5%85%b8%e6%94%be%e5%88%b0redis%e4%b8%ad%e7%9a%84%e5%84%aa%e5%8b%a2-ePArJDaFyh\">\u5c07\u696d\u52d9\u5b57\u5178\u653e\u5230Redis\u4e2d\u7684\u512a\u52e2<\/h2>\n<p>\u5c07\u696d\u52d9\u5b57\u5178\u5b58\u5132\u5728Redis\u4e2d\uff0c\u80fd\u5920\u5e36\u4f86\u4ee5\u4e0b\u5e7e\u500b\u512a\u52e2\uff1a<\/p>\n<ul>\n<li><strong>\u5feb\u901f\u67e5\u8a62\uff1a<\/strong>\u7531\u65bcRedis\u7684\u9ad8\u6548\u6578\u64da\u5b58\u53d6\u7279\u6027\uff0c\u696d\u52d9\u5b57\u5178\u7684\u67e5\u8a62\u901f\u5ea6\u5c07\u5927\u5e45\u63d0\u5347\uff0c\u80fd\u5920\u6eff\u8db3\u9ad8\u4e26\u767c\u7684\u696d\u52d9\u9700\u6c42\u3002<\/li>\n<li><strong>\u9748\u6d3b\u7684\u6578\u64da\u7d50\u69cb\uff1a<\/strong>\u4f7f\u7528Redis\u7684\u54c8\u5e0c\u7d50\u69cb\uff0c\u53ef\u4ee5\u5c07\u696d\u52d9\u5b57\u5178\u4e2d\u7684\u6bcf\u500b\u689d\u76ee\u4f5c\u70ba\u4e00\u500b\u54c8\u5e0c\uff0c\u65b9\u4fbf\u9032\u884c\u589e\u522a\u6539\u67e5\u64cd\u4f5c\u3002<\/li>\n<li><strong>\u6613\u65bc\u64f4\u5c55\uff1a<\/strong>\u96a8\u8457\u696d\u52d9\u7684\u589e\u9577\uff0cRedis\u7684\u96c6\u7fa4\u6a21\u5f0f\u80fd\u5920\u8f15\u9b06\u5730\u64f4\u5c55\uff0c\u652f\u6301\u66f4\u591a\u7684\u6578\u64da\u5b58\u5132\u548c\u67e5\u8a62\u9700\u6c42\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%af%a6%e7%8f%be%e6%a5%ad%e5%8b%99%e5%ad%97%e5%85%b8%e7%9a%84redis%e7%a4%ba%e4%be%8b-ePArJDaFyh\">\u5be6\u73fe\u696d\u52d9\u5b57\u5178\u7684Redis\u793a\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u5c07\u696d\u52d9\u5b57\u5178\u5b58\u5132\u5230Redis\u4e2d\uff1a<\/p>\n<pre><code>\n# \u9023\u63a5\u5230Redis\nimport redis\n\nr = redis.Redis(host='localhost', port=6379, db=0)\n\n# \u5b9a\u7fa9\u696d\u52d9\u5b57\u5178\nbusiness_dictionary = {\n    \"user\": {\"description\": \"\u7528\u6236\", \"type\": \"string\"},\n    \"order\": {\"description\": \"\u8a02\u55ae\", \"type\": \"string\"},\n    \"product\": {\"description\": \"\u7522\u54c1\", \"type\": \"string\"}\n}\n\n# \u5c07\u696d\u52d9\u5b57\u5178\u5b58\u5132\u5230Redis\nfor key, value in business_dictionary.items():\n    r.hset(\"business_dictionary\", key, str(value))\n\n# \u67e5\u8a62\u696d\u52d9\u5b57\u5178\nresult = r.hget(\"business_dictionary\", \"user\")\nprint(result)\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u9996\u5148\u9023\u63a5\u5230Redis\uff0c\u7136\u5f8c\u5b9a\u7fa9\u4e86\u4e00\u500b\u7c21\u55ae\u7684\u696d\u52d9\u5b57\u5178\uff0c\u6700\u5f8c\u5c07\u5176\u5b58\u5132\u5230Redis\u4e2d\u3002\u901a\u904e\u4f7f\u7528\u54c8\u5e0c\u7d50\u69cb\uff0c\u6211\u5011\u53ef\u4ee5\u8f15\u9b06\u5730\u67e5\u8a62\u548c\u7ba1\u7406\u696d\u52d9\u5b57\u5178\u4e2d\u7684\u6578\u64da\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-ePArJDaFyh\">\u7d50\u8ad6<\/h2>\n<p>\u5c07\u696d\u52d9\u5b57\u5178\u653e\u5230Redis\u4e2d\uff0c\u4e0d\u50c5\u80fd\u5920\u63d0\u9ad8\u6578\u64da\u67e5\u8a62\u7684\u6548\u7387\uff0c\u9084\u80fd\u5920\u5be6\u73fe\u9748\u6d3b\u7684\u6578\u64da\u7ba1\u7406\u548c\u7121\u7e2b\u7684\u64f4\u5c55\u3002\u96a8\u8457\u4f01\u696d\u5c0d\u6578\u64da\u9700\u6c42\u7684\u65e5\u76ca\u589e\u9577\uff0cRedis\u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6548\u7684\u6578\u64da\u5b58\u5132\u89e3\u6c7a\u65b9\u6848\uff0c\u5c07\u5728\u672a\u4f86\u7684\u696d\u52d9\u767c\u5c55\u4e2d\u626e\u6f14\u8d8a\u4f86\u8d8a\u91cd\u8981\u7684\u89d2\u8272\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u53ef\u9760\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u60a8\u7684Redis\u90e8\u7f72\uff0cServer.HK\u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u5e6b\u52a9\u60a8\u8f15\u9b06\u5be6\u73fe\u696d\u52d9\u7684\u7121\u7e2b\u64f4\u5c55\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u5982\u4f55\u5c07\u696d\u52d9\u5b57\u5178\u653e\u5165Redis\uff0c\u5be6\u73fe\u7121\u7e2b\u64f4\u5c55\uff0c\u63d0\u5347\u7cfb\u7d71\u6027\u80fd\u8207\u67e5\u8a62\u6548\u7387\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-193881","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/193881","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=193881"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/193881\/revisions"}],"predecessor-version":[{"id":193882,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/193881\/revisions\/193882"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=193881"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=193881"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=193881"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}