{"id":129687,"date":"2024-10-26T23:35:19","date_gmt":"2024-10-26T15:35:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/129687\/"},"modified":"2024-10-26T23:35:20","modified_gmt":"2024-10-26T15:35:20","slug":"redis%e7%82%ba%e8%a7%a3%e6%b1%ba%e5%b0%8d%e8%b1%a1%e5%ad%98%e5%84%b2%e4%b9%8b%e9%81%93%ef%bc%88%e5%b0%8d%e8%b1%a1%e5%ad%98%e5%85%a5redis%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/129687\/","title":{"rendered":"Redis\u70ba\u89e3\u6c7a\u5c0d\u8c61\u5b58\u5132\u4e4b\u9053\uff08\u5c0d\u8c61\u5b58\u5165redis\uff09"},"content":{"rendered":"<h1 id=\"redis%e7%82%ba%e8%a7%a3%e6%b1%ba%e5%b0%8d%e8%b1%a1%e5%ad%98%e5%84%b2%e4%b9%8b%e9%81%93%ef%bc%88%e5%b0%8d%e8%b1%a1%e5%ad%98%e5%85%a5redis%ef%bc%89-bVhfMJvDdQ\">Redis\u70ba\u89e3\u6c7a\u5c0d\u8c61\u5b58\u5132\u4e4b\u9053\uff08\u5c0d\u8c61\u5b58\u5165Redis\uff09<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u4e16\u754c\u4e2d\uff0c\u5c0d\u8c61\u5b58\u5132\u6210\u70ba\u4e86\u8a31\u591a\u61c9\u7528\u7a0b\u5e8f\u7684\u6838\u5fc3\u9700\u6c42\u3002\u96a8\u8457\u6578\u64da\u91cf\u7684\u6fc0\u589e\uff0c\u5982\u4f55\u9ad8\u6548\u5730\u5b58\u5132\u548c\u6aa2\u7d22\u9019\u4e9b\u6578\u64da\u6210\u70ba\u4e86\u958b\u767c\u8005\u9762\u81e8\u7684\u4e00\u5927\u6311\u6230\u3002Redis\uff0c\u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6548\u7684\u5167\u5b58\u6578\u64da\u7d50\u69cb\u5b58\u5132\u7cfb\u7d71\uff0c\u63d0\u4f9b\u4e86\u4e00\u7a2e\u89e3\u6c7a\u65b9\u6848\u4f86\u8655\u7406\u5c0d\u8c61\u5b58\u5132\u7684\u9700\u6c42\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afredis%ef%bc%9f-bVhfMJvDdQ\">\u4ec0\u9ebc\u662fRedis\uff1f<\/h2>\n<p>Redis\uff08Remote Dictionary Server\uff09\u662f\u4e00\u500b\u958b\u6e90\u7684\u9ad8\u6027\u80fd\u9375\u503c\u6578\u64da\u5eab\uff0c\u652f\u6301\u591a\u7a2e\u6578\u64da\u7d50\u69cb\uff0c\u5982\u5b57\u7b26\u4e32\u3001\u54c8\u5e0c\u3001\u5217\u8868\u3001\u96c6\u5408\u548c\u6709\u5e8f\u96c6\u5408\u7b49\u3002\u7531\u65bc\u5176\u9ad8\u6548\u7684\u6027\u80fd\u548c\u9748\u6d3b\u7684\u6578\u64da\u7d50\u69cb\uff0cRedis\u88ab\u5ee3\u6cdb\u61c9\u7528\u65bc\u7de9\u5b58\u3001\u6d88\u606f\u968a\u5217\u548c\u5be6\u6642\u6578\u64da\u5206\u6790\u7b49\u5834\u666f\u3002<\/p>\n<h2 id=\"%e5%b0%8d%e8%b1%a1%e5%ad%98%e5%84%b2%e7%9a%84%e9%9c%80%e6%b1%82-bVhfMJvDdQ\">\u5c0d\u8c61\u5b58\u5132\u7684\u9700\u6c42<\/h2>\n<p>\u5c0d\u8c61\u5b58\u5132\u662f\u4e00\u7a2e\u5c07\u6578\u64da\u4f5c\u70ba\u5c0d\u8c61\u9032\u884c\u5b58\u5132\u7684\u65b9\u5f0f\uff0c\u9019\u4e9b\u5c0d\u8c61\u901a\u5e38\u5305\u542b\u6578\u64da\u672c\u8eab\u3001\u5143\u6578\u64da\u548c\u552f\u4e00\u6a19\u8b58\u7b26\u3002\u9019\u7a2e\u5b58\u5132\u65b9\u5f0f\u7279\u5225\u9069\u5408\u65bc\u975e\u7d50\u69cb\u5316\u6578\u64da\uff0c\u5982\u5716\u7247\u3001\u8996\u983b\u548c\u6587\u6a94\u7b49\u3002\u96a8\u8457\u96f2\u8a08\u7b97\u548c\u5927\u6578\u64da\u6280\u8853\u7684\u767c\u5c55\uff0c\u5c0d\u8c61\u5b58\u5132\u7684\u9700\u6c42\u65e5\u76ca\u589e\u52a0\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%81%b8%e6%93%87redis%e4%bd%9c%e7%82%ba%e5%b0%8d%e8%b1%a1%e5%ad%98%e5%84%b2%e8%a7%a3%e6%b1%ba%e6%96%b9%e6%a1%88%ef%bc%9f-bVhfMJvDdQ\">\u70ba\u4ec0\u9ebc\u9078\u64c7Redis\u4f5c\u70ba\u5c0d\u8c61\u5b58\u5132\u89e3\u6c7a\u65b9\u6848\uff1f<\/h2>\n<p>\u9078\u64c7Redis\u4f5c\u70ba\u5c0d\u8c61\u5b58\u5132\u7684\u89e3\u6c7a\u65b9\u6848\u6709\u5e7e\u500b\u539f\u56e0\uff1a<\/p>\n<ul>\n<li><strong>\u9ad8\u6027\u80fd\uff1a<\/strong>Redis\u7684\u5167\u5b58\u5b58\u5132\u7279\u6027\u4f7f\u5176\u5728\u8b80\u53d6\u548c\u5beb\u5165\u64cd\u4f5c\u4e0a\u90fd\u975e\u5e38\u8fc5\u901f\uff0c\u80fd\u5920\u652f\u6301\u9ad8\u4e26\u767c\u7684\u8acb\u6c42\u3002<\/li>\n<li><strong>\u9748\u6d3b\u7684\u6578\u64da\u7d50\u69cb\uff1a<\/strong>Redis\u652f\u6301\u591a\u7a2e\u6578\u64da\u7d50\u69cb\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u6839\u64da\u9700\u6c42\u9078\u64c7\u6700\u5408\u9069\u7684\u5b58\u5132\u65b9\u5f0f\u3002<\/li>\n<li><strong>\u6301\u4e45\u5316\u9078\u9805\uff1a<\/strong>\u96d6\u7136Redis\u4e3b\u8981\u662f\u5167\u5b58\u6578\u64da\u5eab\uff0c\u4f46\u5b83\u4e5f\u63d0\u4f9b\u4e86\u6301\u4e45\u5316\u9078\u9805\uff0c\u80fd\u5920\u5c07\u6578\u64da\u4fdd\u5b58\u5230\u78c1\u789f\u4e2d\uff0c\u9632\u6b62\u6578\u64da\u4e1f\u5931\u3002<\/li>\n<li><strong>\u7c21\u55ae\u6613\u7528\uff1a<\/strong>Redis\u7684API\u8a2d\u8a08\u7c21\u55ae\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u8f15\u9b06\u4e0a\u624b\uff0c\u5feb\u901f\u5be6\u73fe\u5c0d\u8c61\u5b58\u5132\u529f\u80fd\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%b0%87%e5%b0%8d%e8%b1%a1%e5%ad%98%e5%85%a5redis-bVhfMJvDdQ\">\u5982\u4f55\u5c07\u5c0d\u8c61\u5b58\u5165Redis<\/h2>\n<p>\u5c07\u5c0d\u8c61\u5b58\u5165Redis\u7684\u904e\u7a0b\u76f8\u5c0d\u7c21\u55ae\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u57fa\u672c\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528Python\u5c07\u5c0d\u8c61\u5b58\u5165Redis\uff1a<\/p>\n<pre><code>import redis\nimport json\n\n# \u9023\u63a5\u5230Redis\nr = redis.Redis(host='localhost', port=6379, db=0)\n\n# \u5b9a\u7fa9\u4e00\u500b\u5c0d\u8c61\nobj = {\n    'id': 1,\n    'name': 'Server.HK',\n    'type': 'VPS Hosting'\n}\n\n# \u5c07\u5c0d\u8c61\u8f49\u63db\u70baJSON\u683c\u5f0f\nobj_json = json.dumps(obj)\n\n# \u5c07\u5c0d\u8c61\u5b58\u5165Redis\nr.set('object:1', obj_json)\n\n# \u5f9eRedis\u4e2d\u6aa2\u7d22\u5c0d\u8c61\nretrieved_obj_json = r.get('object:1')\nretrieved_obj = json.loads(retrieved_obj_json)\n\nprint(retrieved_obj)\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u9996\u5148\u9023\u63a5\u5230Redis\u670d\u52d9\u5668\uff0c\u7136\u5f8c\u5b9a\u7fa9\u4e00\u500b\u5c0d\u8c61\uff0c\u5c07\u5176\u8f49\u63db\u70baJSON\u683c\u5f0f\uff0c\u4e26\u4f7f\u7528`set`\u65b9\u6cd5\u5c07\u5176\u5b58\u5165Redis\u3002\u96a8\u5f8c\uff0c\u6211\u5011\u4f7f\u7528`get`\u65b9\u6cd5\u6aa2\u7d22\u8a72\u5c0d\u8c61\uff0c\u4e26\u5c07\u5176\u8f49\u63db\u56dePython\u5b57\u5178\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-bVhfMJvDdQ\">\u7d50\u8ad6<\/h2>\n<p>Redis\u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6548\u7684\u5167\u5b58\u6578\u64da\u5eab\uff0c\u70ba\u5c0d\u8c61\u5b58\u5132\u63d0\u4f9b\u4e86\u4e00\u7a2e\u9748\u6d3b\u4e14\u9ad8\u6027\u80fd\u7684\u89e3\u6c7a\u65b9\u6848\u3002\u7121\u8ad6\u662f\u7528\u65bc\u7de9\u5b58\u9084\u662f\u6301\u4e45\u5316\u5b58\u5132\uff0cRedis\u90fd\u80fd\u5920\u6eff\u8db3\u73fe\u4ee3\u61c9\u7528\u7a0b\u5e8f\u5c0d\u6578\u64da\u5b58\u5132\u7684\u9700\u6c42\u3002\u96a8\u8457\u6280\u8853\u7684\u9032\u6b65\uff0cRedis\u7684\u61c9\u7528\u5834\u666f\u5c07\u6703\u66f4\u52a0\u5ee3\u6cdb\uff0c\u6210\u70ba\u958b\u767c\u8005\u5728\u5c0d\u8c61\u5b58\u5132\u65b9\u9762\u7684\u91cd\u8981\u5de5\u5177\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u670d\u52d9\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u5982\u4f55\u5229\u7528Redis\u9ad8\u6548\u89e3\u6c7a\u5c0d\u8c61\u5b58\u5132\u554f\u984c\uff0c\u5be6\u73fe\u5c0d\u8c61\u5feb\u901f\u5b58\u5165\u8207\u6aa2\u7d22\uff0c\u63d0\u5347\u6578\u64da\u8655\u7406\u6027\u80fd\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-129687","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/129687","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=129687"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/129687\/revisions"}],"predecessor-version":[{"id":129688,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/129687\/revisions\/129688"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=129687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=129687"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=129687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}