{"id":134693,"date":"2024-10-31T02:17:18","date_gmt":"2024-10-30T18:17:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/134693\/"},"modified":"2024-10-31T02:17:18","modified_gmt":"2024-10-30T18:17:18","slug":"redis%e9%87%8d%e6%96%b0%e5%ae%9a%e7%be%a9%e5%ba%8f%e5%88%97%e5%8c%96%e7%aa%81%e7%a0%b4%e5%82%b3%e7%b5%b1%e9%99%90%e5%88%b6%ef%bc%88redis%e9%87%8d%e5%af%ab%e5%ba%8f%e5%88%97%e5%8c%96%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/134693\/","title":{"rendered":"Redis\u91cd\u65b0\u5b9a\u7fa9\u5e8f\u5217\u5316\u7a81\u7834\u50b3\u7d71\u9650\u5236\uff08redis\u91cd\u5beb\u5e8f\u5217\u5316\uff09"},"content":{"rendered":"<h1 id=\"redis%e9%87%8d%e6%96%b0%e5%ae%9a%e7%be%a9%e5%ba%8f%e5%88%97%e5%8c%96%e7%aa%81%e7%a0%b4%e5%82%b3%e7%b5%b1%e9%99%90%e5%88%b6%ef%bc%88redis%e9%87%8d%e5%af%ab%e5%ba%8f%e5%88%97%e5%8c%96%ef%bc%89-ENobvjVOwS\">Redis\u91cd\u65b0\u5b9a\u7fa9\u5e8f\u5217\u5316\u7a81\u7834\u50b3\u7d71\u9650\u5236\uff08redis\u91cd\u5beb\u5e8f\u5217\u5316\uff09<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u4e16\u754c\u4e2d\uff0c\u6027\u80fd\u548c\u6548\u7387\u662f\u6bcf\u500b\u958b\u767c\u8005\u548c\u7cfb\u7d71\u67b6\u69cb\u5e2b\u6240\u8ffd\u6c42\u7684\u76ee\u6a19\u3002Redis\u4f5c\u70ba\u4e00\u500b\u9ad8\u6548\u7684\u9375\u503c\u5b58\u5132\u7cfb\u7d71\uff0c\u5df2\u7d93\u5728\u8a31\u591a\u61c9\u7528\u4e2d\u5f97\u5230\u4e86\u5ee3\u6cdb\u7684\u61c9\u7528\u3002\u96a8\u8457\u6280\u8853\u7684\u9032\u6b65\uff0cRedis\u7684\u5e8f\u5217\u5316\u6a5f\u5236\u4e5f\u5728\u4e0d\u65b7\u6f14\u9032\uff0c\u7279\u5225\u662f\u6700\u8fd1\u7684\u201c\u91cd\u5beb\u5e8f\u5217\u5316\u201d\u529f\u80fd\uff0c\u70ba\u958b\u767c\u8005\u63d0\u4f9b\u4e86\u66f4\u5927\u7684\u9748\u6d3b\u6027\u548c\u6027\u80fd\u512a\u5316\u7684\u53ef\u80fd\u6027\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e5%ba%8f%e5%88%97%e5%8c%96%ef%bc%9f-ENobvjVOwS\">\u4ec0\u9ebc\u662f\u5e8f\u5217\u5316\uff1f<\/h2>\n<p>\u5e8f\u5217\u5316\u662f\u5c07\u6578\u64da\u7d50\u69cb\u6216\u5c0d\u8c61\u8f49\u63db\u70ba\u53ef\u5b58\u5132\u6216\u50b3\u8f38\u7684\u683c\u5f0f\u7684\u904e\u7a0b\u3002\u9019\u4e00\u904e\u7a0b\u5728\u5206\u4f48\u5f0f\u7cfb\u7d71\u4e2d\u5c24\u70ba\u91cd\u8981\uff0c\u56e0\u70ba\u5b83\u5141\u8a31\u6578\u64da\u5728\u4e0d\u540c\u7684\u7cfb\u7d71\u4e4b\u9593\u9032\u884c\u50b3\u905e\u3002\u50b3\u7d71\u7684\u5e8f\u5217\u5316\u65b9\u6cd5\u5982JSON\u6216XML\u96d6\u7136\u6613\u65bc\u4f7f\u7528\uff0c\u4f46\u5728\u6027\u80fd\u4e0a\u5f80\u5f80\u5b58\u5728\u74f6\u9838\uff0c\u7279\u5225\u662f\u5728\u8655\u7406\u5927\u91cf\u6578\u64da\u6642\u3002<\/p>\n<h2 id=\"redis%e7%9a%84%e5%ba%8f%e5%88%97%e5%8c%96%e6%a9%9f%e5%88%b6-ENobvjVOwS\">Redis\u7684\u5e8f\u5217\u5316\u6a5f\u5236<\/h2>\n<p>Redis\u652f\u6301\u591a\u7a2e\u5e8f\u5217\u5316\u683c\u5f0f\uff0c\u5305\u62ecJSON\u3001MessagePack\u548cProtocol Buffers\u7b49\u3002\u9019\u4e9b\u683c\u5f0f\u5404\u6709\u512a\u7f3a\u9ede\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u958b\u767c\u8005\u53ef\u80fd\u6703\u767c\u73fe\u5b83\u5011\u7684\u6027\u80fd\u4e0d\u8db3\u4ee5\u6eff\u8db3\u9700\u6c42\u3002\u9019\u5c31\u662fRedis\u91cd\u5beb\u5e8f\u5217\u5316\u7684\u51fa\u73fe\u80cc\u666f\u3002<\/p>\n<h2 id=\"redis%e9%87%8d%e5%af%ab%e5%ba%8f%e5%88%97%e5%8c%96%e7%9a%84%e5%84%aa%e5%8b%a2-ENobvjVOwS\">Redis\u91cd\u5beb\u5e8f\u5217\u5316\u7684\u512a\u52e2<\/h2>\n<ul>\n<li><strong>\u6027\u80fd\u63d0\u5347\uff1a<\/strong>\u91cd\u5beb\u5e8f\u5217\u5316\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u6578\u64da\u7684\u8b80\u53d6\u548c\u5beb\u5165\u901f\u5ea6\uff0c\u7279\u5225\u662f\u5728\u9ad8\u4e26\u767c\u7684\u74b0\u5883\u4e2d\u3002<\/li>\n<li><strong>\u9748\u6d3b\u6027\uff1a<\/strong>\u958b\u767c\u8005\u53ef\u4ee5\u6839\u64da\u5177\u9ad4\u9700\u6c42\u9078\u64c7\u6700\u5408\u9069\u7684\u5e8f\u5217\u5316\u683c\u5f0f\uff0c\u5f9e\u800c\u512a\u5316\u6027\u80fd\u3002<\/li>\n<li><strong>\u6e1b\u5c11\u5167\u5b58\u4f7f\u7528\uff1a<\/strong>\u901a\u904e\u66f4\u9ad8\u6548\u7684\u5e8f\u5217\u5316\u7b97\u6cd5\uff0c\u53ef\u4ee5\u6e1b\u5c11\u6578\u64da\u5728\u5167\u5b58\u4e2d\u7684\u4f54\u7528\uff0c\u5f9e\u800c\u63d0\u9ad8\u6574\u9ad4\u7cfb\u7d71\u7684\u6548\u7387\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%af%a6%e7%8f%beredis%e9%87%8d%e5%af%ab%e5%ba%8f%e5%88%97%e5%8c%96-ENobvjVOwS\">\u5982\u4f55\u5be6\u73feRedis\u91cd\u5beb\u5e8f\u5217\u5316<\/h2>\n<p>\u5be6\u73feRedis\u91cd\u5beb\u5e8f\u5217\u5316\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\u4e2d\u7684Redis\u5eab\u4f86\u5be6\u73fe\u81ea\u5b9a\u7fa9\u5e8f\u5217\u5316\uff1a<\/p>\n<pre><code>import redis\nimport pickle\n\n# \u9023\u63a5\u5230Redis\nr = redis.Redis(host='localhost', port=6379, db=0)\n\n# \u81ea\u5b9a\u7fa9\u5e8f\u5217\u5316\u51fd\u6578\ndef serialize(data):\n    return pickle.dumps(data)\n\n# \u81ea\u5b9a\u7fa9\u53cd\u5e8f\u5217\u5316\u51fd\u6578\ndef deserialize(data):\n    return pickle.loads(data)\n\n# \u5b58\u5132\u6578\u64da\ndata = {'name': 'Server.HK', 'type': 'VPS Hosting'}\nr.set('my_data', serialize(data))\n\n# \u7372\u53d6\u6578\u64da\nretrieved_data = deserialize(r.get('my_data'))\nprint(retrieved_data)\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u4f7f\u7528\u4e86Python\u7684pickle\u5eab\u4f86\u9032\u884c\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u3002\u9019\u7a2e\u65b9\u6cd5\u4e0d\u50c5\u7c21\u55ae\uff0c\u800c\u4e14\u80fd\u5920\u6709\u6548\u5730\u8655\u7406\u8907\u96dc\u7684\u6578\u64da\u7d50\u69cb\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-ENobvjVOwS\">\u7d50\u8ad6<\/h2>\n<p>Redis\u7684\u91cd\u5beb\u5e8f\u5217\u5316\u529f\u80fd\u70ba\u958b\u767c\u8005\u63d0\u4f9b\u4e86\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\uff0c\u80fd\u5920\u7a81\u7834\u50b3\u7d71\u5e8f\u5217\u5316\u7684\u9650\u5236\uff0c\u5be6\u73fe\u66f4\u9ad8\u6548\u7684\u6578\u64da\u8655\u7406\u3002\u96a8\u8457\u6280\u8853\u7684\u9032\u6b65\uff0c\u9019\u4e00\u529f\u80fd\u5c07\u5728\u672a\u4f86\u7684\u61c9\u7528\u4e2d\u767c\u63ee\u8d8a\u4f86\u8d8a\u91cd\u8981\u7684\u4f5c\u7528\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6027\u80fd\u6578\u64da\u5b58\u5132\u548c\u8655\u7406\u7684\u61c9\u7528\u4f86\u8aaa\uff0cRedis\u7121\u7591\u662f\u4e00\u500b\u503c\u5f97\u8003\u616e\u7684\u9078\u64c7\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\u9069\u5408\u5404\u7a2e\u9700\u6c42\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a> \u9084\u662f <a href=\"https:\/\/server.hk\">\u4e91\u4f3a\u670d\u5668<\/a>\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u7a69\u5b9a\u53ef\u9760\u7684\u670d\u52d9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Redis\u91cd\u65b0\u5b9a\u7fa9\u5e8f\u5217\u5316\uff0c\u7a81\u7834\u50b3\u7d71\u9650\u5236\uff0c\u63d0\u5347\u6578\u64da\u8655\u7406\u6548\u7387\uff0c\u5be6\u73fe\u66f4\u9748\u6d3b\u7684\u6578\u64da\u5b58\u5132\u8207\u8a2a\u554f\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-134693","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/134693","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=134693"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/134693\/revisions"}],"predecessor-version":[{"id":134694,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/134693\/revisions\/134694"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=134693"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=134693"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=134693"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}