{"id":148699,"date":"2024-11-01T14:20:22","date_gmt":"2024-11-01T06:20:22","guid":{"rendered":"https:\/\/server.hk\/cnblog\/148699\/"},"modified":"2024-11-01T14:20:23","modified_gmt":"2024-11-01T06:20:23","slug":"%e9%98%bf%e9%87%8c%e9%9b%b2redis%ef%bc%9a%e7%b0%a1%e5%96%ae%e6%98%93%e7%94%a8%e7%9a%84%e5%bc%b7%e5%a4%a7nosql%e8%a7%a3%e6%b1%ba%e6%96%b9%e6%a1%88%ef%bc%88%e9%98%bf%e9%87%8c%e9%9b%b2redis%e7%94%a8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/148699\/","title":{"rendered":"\u963f\u91cc\u96f2Redis\uff1a\u7c21\u55ae\u6613\u7528\u7684\u5f37\u5927NoSQL\u89e3\u6c7a\u65b9\u6848\uff08\u963f\u91cc\u96f2redis\u7528\u6cd5\uff09"},"content":{"rendered":"<h1 id=\"%e9%98%bf%e9%87%8c%e9%9b%b2redis%ef%bc%9a%e7%b0%a1%e5%96%ae%e6%98%93%e7%94%a8%e7%9a%84%e5%bc%b7%e5%a4%a7nosql%e8%a7%a3%e6%b1%ba%e6%96%b9%e6%a1%88-iJSUjrnsai\">\u963f\u91cc\u96f2Redis\uff1a\u7c21\u55ae\u6613\u7528\u7684\u5f37\u5927NoSQL\u89e3\u6c7a\u65b9\u6848<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u6642\u4ee3\uff0c\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u5b58\u5132\u89e3\u6c7a\u65b9\u6848\u5c0d\u65bc\u4f01\u696d\u7684\u6210\u529f\u81f3\u95dc\u91cd\u8981\u3002\u963f\u91cc\u96f2Redis\u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6548\u7684NoSQL\u6578\u64da\u5eab\uff0c\u56e0\u5176\u7c21\u55ae\u6613\u7528\u548c\u5f37\u5927\u7684\u6027\u80fd\u800c\u53d7\u5230\u5ee3\u6cdb\u95dc\u6ce8\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e\u963f\u91cc\u96f2Redis\u7684\u7279\u9ede\u3001\u7528\u6cd5\u53ca\u5176\u5728\u5be6\u969b\u61c9\u7528\u4e2d\u7684\u512a\u52e2\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afredis%ef%bc%9f-iJSUjrnsai\">\u4ec0\u9ebc\u662fRedis\uff1f<\/h2>\n<p>Redis\uff08Remote Dictionary Server\uff09\u662f\u4e00\u7a2e\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\u4f5c\u70ba\u4e00\u7a2eNoSQL\u89e3\u6c7a\u65b9\u6848\uff0cRedis\u7279\u5225\u9069\u5408\u9700\u8981\u5feb\u901f\u8b80\u53d6\u548c\u5beb\u5165\u64cd\u4f5c\u7684\u61c9\u7528\u5834\u666f\uff0c\u5982\u5373\u6642\u6d88\u606f\u3001\u904a\u6232\u6392\u884c\u699c\u548c\u6578\u64da\u7de9\u5b58\u7b49\u3002<\/p>\n<h2 id=\"%e9%98%bf%e9%87%8c%e9%9b%b2redis%e7%9a%84%e7%89%b9%e9%bb%9e-iJSUjrnsai\">\u963f\u91cc\u96f2Redis\u7684\u7279\u9ede<\/h2>\n<ul>\n<li><strong>\u9ad8\u6027\u80fd\uff1a<\/strong>\u963f\u91cc\u96f2Redis\u63d0\u4f9b\u6beb\u79d2\u7d1a\u7684\u97ff\u61c9\u6642\u9593\uff0c\u80fd\u5920\u8655\u7406\u6bcf\u79d2\u6578\u5341\u842c\u6b21\u7684\u8acb\u6c42\uff0c\u9069\u5408\u9ad8\u4e26\u767c\u7684\u61c9\u7528\u5834\u666f\u3002<\/li>\n<li><strong>\u53ef\u64f4\u5c55\u6027\uff1a<\/strong>\u652f\u6301\u6c34\u5e73\u64f4\u5c55\uff0c\u80fd\u5920\u6839\u64da\u696d\u52d9\u9700\u6c42\u9748\u6d3b\u8abf\u6574\u8cc7\u6e90\u914d\u7f6e\u3002<\/li>\n<li><strong>\u9ad8\u53ef\u7528\u6027\uff1a<\/strong>\u901a\u904e\u4e3b\u5f9e\u8907\u88fd\u548c\u81ea\u52d5\u6545\u969c\u8f49\u79fb\uff0c\u78ba\u4fdd\u6578\u64da\u7684\u6301\u4e45\u6027\u548c\u53ef\u7528\u6027\u3002<\/li>\n<li><strong>\u591a\u7a2e\u6578\u64da\u7d50\u69cb\u652f\u6301\uff1a<\/strong>\u9664\u4e86\u57fa\u672c\u7684\u9375\u503c\u5c0d\uff0c\u9084\u652f\u6301\u8907\u96dc\u7684\u6578\u64da\u7d50\u69cb\uff0c\u6eff\u8db3\u4e0d\u540c\u7684\u696d\u52d9\u9700\u6c42\u3002<\/li>\n<\/ul>\n<h2 id=\"%e9%98%bf%e9%87%8c%e9%9b%b2redis%e7%9a%84%e5%9f%ba%e6%9c%ac%e7%94%a8%e6%b3%95-iJSUjrnsai\">\u963f\u91cc\u96f2Redis\u7684\u57fa\u672c\u7528\u6cd5<\/h2>\n<p>\u4f7f\u7528\u963f\u91cc\u96f2Redis\u975e\u5e38\u7c21\u55ae\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e9b\u57fa\u672c\u7684\u64cd\u4f5c\u793a\u4f8b\uff1a<\/p>\n<h3 id=\"1-%e9%80%a3%e6%8e%a5%e5%88%b0redis-iJSUjrnsai\">1. \u9023\u63a5\u5230Redis<\/h3>\n<pre><code>import redis\n\n# \u9023\u63a5\u5230\u963f\u91cc\u96f2Redis\nr = redis.Redis(host='your_redis_host', port=your_redis_port, password='your_redis_password')\n<\/code><\/pre>\n<h3 id=\"2-%e5%9f%ba%e6%9c%ac%e6%93%8d%e4%bd%9c-iJSUjrnsai\">2. \u57fa\u672c\u64cd\u4f5c<\/h3>\n<ul>\n<li><strong>\u8a2d\u7f6e\u9375\u503c\uff1a<\/strong><\/li>\n<pre><code>r.set('key', 'value')<\/code><\/pre>\n<li><strong>\u7372\u53d6\u9375\u503c\uff1a<\/strong><\/li>\n<pre><code>value = r.get('key')<\/code><\/pre>\n<li><strong>\u522a\u9664\u9375\uff1a<\/strong><\/li>\n<pre><code>r.delete('key')<\/code><\/pre>\n<\/ul>\n<h3 id=\"3-%e4%bd%bf%e7%94%a8%e6%95%b8%e6%93%9a%e7%b5%90%e6%a7%8b-iJSUjrnsai\">3. \u4f7f\u7528\u6578\u64da\u7d50\u69cb<\/h3>\n<p>Redis\u652f\u6301\u591a\u7a2e\u6578\u64da\u7d50\u69cb\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e9b\u793a\u4f8b\uff1a<\/p>\n<ul>\n<li><strong>\u5217\u8868\u64cd\u4f5c\uff1a<\/strong><\/li>\n<pre><code>r.lpush('mylist', 'value1')\nr.lpush('mylist', 'value2')\nvalues = r.lrange('mylist', 0, -1)<\/code><\/pre>\n<li><strong>\u54c8\u5e0c\u64cd\u4f5c\uff1a<\/strong><\/li>\n<pre><code>r.hset('myhash', 'field1', 'value1')\nvalue = r.hget('myhash', 'field1')<\/code><\/pre>\n<\/ul>\n<h2 id=\"%e9%98%bf%e9%87%8c%e9%9b%b2redis%e7%9a%84%e6%87%89%e7%94%a8%e5%a0%b4%e6%99%af-iJSUjrnsai\">\u963f\u91cc\u96f2Redis\u7684\u61c9\u7528\u5834\u666f<\/h2>\n<p>\u963f\u91cc\u96f2Redis\u9069\u7528\u65bc\u591a\u7a2e\u5834\u666f\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u65bc\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u7de9\u5b58\uff1a<\/strong>\u901a\u904e\u5c07\u983b\u7e41\u8a2a\u554f\u7684\u6578\u64da\u7de9\u5b58\u5728Redis\u4e2d\uff0c\u986f\u8457\u63d0\u9ad8\u61c9\u7528\u7684\u97ff\u61c9\u901f\u5ea6\u3002<\/li>\n<li><strong>\u5373\u6642\u6578\u64da\u8655\u7406\uff1a<\/strong>\u9069\u5408\u9700\u8981\u5feb\u901f\u8b80\u53d6\u548c\u5beb\u5165\u7684\u5373\u6642\u61c9\u7528\uff0c\u5982\u793e\u4ea4\u5a92\u9ad4\u548c\u904a\u6232\u3002<\/li>\n<li><strong>\u6392\u884c\u699c\u548c\u8a08\u6578\u5668\uff1a<\/strong>\u5229\u7528Redis\u7684\u6709\u5e8f\u96c6\u5408\u7279\u6027\uff0c\u8f15\u9b06\u5be6\u73fe\u6392\u884c\u699c\u529f\u80fd\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-iJSUjrnsai\">\u7e3d\u7d50<\/h2>\n<p>\u963f\u91cc\u96f2Redis\u4f5c\u70ba\u4e00\u7a2e\u7c21\u55ae\u6613\u7528\u7684NoSQL\u89e3\u6c7a\u65b9\u6848\uff0c\u63d0\u4f9b\u4e86\u9ad8\u6027\u80fd\u3001\u9ad8\u53ef\u7528\u6027\u548c\u9748\u6d3b\u7684\u6578\u64da\u7d50\u69cb\u652f\u6301\uff0c\u9069\u5408\u5404\u7a2e\u61c9\u7528\u5834\u666f\u3002\u7121\u8ad6\u662f\u6578\u64da\u7de9\u5b58\u3001\u5373\u6642\u6578\u64da\u8655\u7406\u9084\u662f\u6392\u884c\u699c\u529f\u80fd\uff0cRedis\u90fd\u80fd\u5920\u6eff\u8db3\u9700\u6c42\u3002\u5c0d\u65bc\u9700\u8981\u7a69\u5b9a\u548c\u9ad8\u6548\u6578\u64da\u5b58\u5132\u7684\u4f01\u696d\u4f86\u8aaa\uff0c\u9078\u64c7\u5408\u9069\u7684\u96f2\u670d\u52d9\u5e73\u53f0\u81f3\u95dc\u91cd\u8981\u3002\u82e5\u60a8\u5c0d\u65bc<code><a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a><\/code>\u6216<code><a href=\"https:\/\/server.hk\">\u96f2\u4f3a\u670d\u5668<\/a><\/code>\u6709\u8208\u8da3\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u963f\u91cc\u96f2Redis\uff0c\u7c21\u55ae\u6613\u7528\u7684\u5f37\u5927NoSQL\u89e3\u6c7a\u65b9\u6848\uff0c\u52a9\u60a8\u9ad8\u6548\u7ba1\u7406\u6578\u64da\uff0c\u63d0\u5347\u61c9\u7528\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-148699","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/148699","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=148699"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/148699\/revisions"}],"predecessor-version":[{"id":148700,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/148699\/revisions\/148700"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=148699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=148699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=148699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}