{"id":154097,"date":"2024-11-02T12:56:18","date_gmt":"2024-11-02T04:56:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/154097\/"},"modified":"2024-11-02T12:56:19","modified_gmt":"2024-11-02T04:56:19","slug":"%e9%9b%bb%e8%85%a6%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8redis%e7%b0%a1%e5%96%ae%e9%80%a3%e6%8e%a5%ef%bc%88%e9%9b%bb%e8%85%a6%e9%80%a3%e6%8e%a5redis%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/154097\/","title":{"rendered":"\u96fb\u8166\u5982\u4f55\u4f7f\u7528Redis\u7c21\u55ae\u9023\u63a5\uff08\u96fb\u8166\u9023\u63a5redis\uff09"},"content":{"rendered":"<h1 id=\"%e9%9b%bb%e8%85%a6%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8redis%e7%b0%a1%e5%96%ae%e9%80%a3%e6%8e%a5%ef%bc%88%e9%9b%bb%e8%85%a6%e9%80%a3%e6%8e%a5redis%ef%bc%89-piKFWVjEpH\">\u96fb\u8166\u5982\u4f55\u4f7f\u7528Redis\u7c21\u55ae\u9023\u63a5\uff08\u96fb\u8166\u9023\u63a5redis\uff09<\/h1>\n<p>Redis\u662f\u4e00\u500b\u9ad8\u6548\u80fd\u7684\u9375\u503c\u5b58\u5132\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u6578\u64da\u7de9\u5b58\u3001\u6d88\u606f\u968a\u5217\u548c\u5be6\u6642\u6578\u64da\u8655\u7406\u7b49\u5834\u666f\u3002\u7531\u65bc\u5176\u5feb\u901f\u7684\u8b80\u5beb\u901f\u5ea6\u548c\u9748\u6d3b\u7684\u6578\u64da\u7d50\u69cb\uff0cRedis\u6210\u70ba\u8a31\u591a\u958b\u767c\u8005\u7684\u9996\u9078\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728\u96fb\u8166\u4e0a\u7c21\u55ae\u9023\u63a5Redis\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u57fa\u672c\u7684\u64cd\u4f5c\u793a\u4f8b\u3002<\/p>\n<h2 id=\"1-%e5%ae%89%e8%a3%9dredis-piKFWVjEpH\">1. \u5b89\u88ddRedis<\/h2>\n<p>\u5728\u958b\u59cb\u4f7f\u7528Redis\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u5728\u672c\u5730\u96fb\u8166\u4e0a\u5b89\u88ddRedis\u3002\u4ee5\u4e0b\u662f\u5b89\u88dd\u6b65\u9a5f\uff1a<\/p>\n<ul>\n<li>\u8a2a\u554fRedis\u7684\u5b98\u65b9\u7db2\u7ad9\uff08<a href=\"https:\/\/redis.io\/download\" rel=\"nofollow noopener\" target=\"_blank\">https:\/\/redis.io\/download<\/a>\uff09\u4e0b\u8f09\u6700\u65b0\u7248\u672c\u7684Redis\u3002<\/li>\n<li>\u6839\u64da\u64cd\u4f5c\u7cfb\u7d71\u7684\u4e0d\u540c\uff0c\u9078\u64c7\u76f8\u61c9\u7684\u5b89\u88dd\u5305\u3002\u5c0d\u65bcWindows\u7528\u6236\uff0c\u53ef\u4ee5\u4f7f\u7528\u7b2c\u4e09\u65b9\u7684Redis\u7248\u672c\uff0c\u5982Memurai\u6216Redis for Windows\u3002<\/li>\n<li>\u89e3\u58d3\u7e2e\u4e0b\u8f09\u7684\u6587\u4ef6\uff0c\u4e26\u6839\u64da\u8aaa\u660e\u9032\u884c\u5b89\u88dd\u3002<\/li>\n<\/ul>\n<h2 id=\"2-%e5%95%9f%e5%8b%95redis%e6%9c%8d%e5%8b%99-piKFWVjEpH\">2. \u555f\u52d5Redis\u670d\u52d9<\/h2>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u9700\u8981\u555f\u52d5Redis\u670d\u52d9\u3002\u901a\u5e38\u53ef\u4ee5\u901a\u904e\u547d\u4ee4\u884c\u4f86\u555f\u52d5Redis\uff1a<\/p>\n<pre><code>redis-server<\/code><\/pre>\n<p>\u9019\u689d\u547d\u4ee4\u5c07\u555f\u52d5Redis\u670d\u52d9\uff0c\u4e26\u5728\u9ed8\u8a8d\u7aef\u53e36379\u4e0a\u904b\u884c\u3002\u60a8\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u770b\u5230Redis\u7684\u555f\u52d5\u65e5\u8a8c\uff0c\u78ba\u8a8d\u670d\u52d9\u662f\u5426\u6b63\u5e38\u904b\u884c\u3002<\/p>\n<h2 id=\"3-%e9%80%a3%e6%8e%a5redis-piKFWVjEpH\">3. \u9023\u63a5Redis<\/h2>\n<p>Redis\u63d0\u4f9b\u4e86\u4e00\u500b\u547d\u4ee4\u884c\u5ba2\u6236\u7aef\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b83\u4f86\u9023\u63a5\u548c\u64cd\u4f5cRedis\u6578\u64da\u5eab\u3002\u555f\u52d5\u547d\u4ee4\u884c\u5ba2\u6236\u7aef\u7684\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<pre><code>redis-cli<\/code><\/pre>\n<p>\u57f7\u884c\u6b64\u547d\u4ee4\u5f8c\uff0c\u60a8\u5c07\u9032\u5165Redis\u7684\u547d\u4ee4\u884c\u754c\u9762\uff0c\u4e26\u53ef\u4ee5\u958b\u59cb\u8f38\u5165\u547d\u4ee4\u4f86\u64cd\u4f5cRedis\u3002<\/p>\n<h3 id=\"3-1-%e5%9f%ba%e6%9c%ac%e5%91%bd%e4%bb%a4%e7%a4%ba%e4%be%8b-piKFWVjEpH\">3.1 \u57fa\u672c\u547d\u4ee4\u793a\u4f8b<\/h3>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u57fa\u672c\u7684Redis\u547d\u4ee4\u793a\u4f8b\uff1a<\/p>\n<ul>\n<li><strong>\u8a2d\u7f6e\u9375\u503c\u5c0d\uff1a<\/strong><\/li>\n<pre><code>SET mykey \"Hello, Redis!\"<\/code><\/pre>\n<li><strong>\u7372\u53d6\u9375\u503c\uff1a<\/strong><\/li>\n<pre><code>GET mykey<\/code><\/pre>\n<li><strong>\u522a\u9664\u9375\uff1a<\/strong><\/li>\n<pre><code>DEL mykey<\/code><\/pre>\n<\/ul>\n<p>\u9019\u4e9b\u547d\u4ee4\u5c07\u5e6b\u52a9\u60a8\u5feb\u901f\u4e0a\u624bRedis\u7684\u57fa\u672c\u64cd\u4f5c\u3002<\/p>\n<h2 id=\"4-%e4%bd%bf%e7%94%a8redis%e7%9a%84%e5%ae%a2%e6%88%b6%e7%ab%af%e5%ba%ab-piKFWVjEpH\">4. \u4f7f\u7528Redis\u7684\u5ba2\u6236\u7aef\u5eab<\/h2>\n<p>\u9664\u4e86\u4f7f\u7528\u547d\u4ee4\u884c\u5ba2\u6236\u7aef\uff0c\u60a8\u9084\u53ef\u4ee5\u5728\u5404\u7a2e\u7de8\u7a0b\u8a9e\u8a00\u4e2d\u4f7f\u7528Redis\u7684\u5ba2\u6236\u7aef\u5eab\u4f86\u9032\u884c\u9023\u63a5\u548c\u64cd\u4f5c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u8a9e\u8a00\u7684Redis\u5ba2\u6236\u7aef\u5eab\uff1a<\/p>\n<ul>\n<li><strong>Python\uff1a<\/strong>\u4f7f\u7528redis-py\u5eab<\/li>\n<pre><code>pip install redis<\/code><\/pre>\n<pre><code>import redis\nr = redis.Redis(host='localhost', port=6379, db=0)\nr.set('mykey', 'Hello, Redis!')\nprint(r.get('mykey'))<\/code><\/pre>\n<li><strong>Node.js\uff1a<\/strong>\u4f7f\u7528redis\u5eab<\/li>\n<pre><code>npm install redis<\/code><\/pre>\n<pre><code>const redis = require('redis');\nconst client = redis.createClient();\nclient.set('mykey', 'Hello, Redis!', redis.print);\nclient.get('mykey', (err, reply) =&gt; {\n    console.log(reply);\n});<\/code><\/pre>\n<\/ul>\n<p>\u9019\u4e9b\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u5728\u4e0d\u540c\u7684\u7de8\u7a0b\u8a9e\u8a00\u4e2d\u9023\u63a5Redis\u4e26\u57f7\u884c\u57fa\u672c\u64cd\u4f5c\u3002<\/p>\n<h2 id=\"5-%e7%b8%bd%e7%b5%90-piKFWVjEpH\">5. \u7e3d\u7d50<\/h2>\n<p>Redis\u662f\u4e00\u500b\u5f37\u5927\u7684\u6578\u64da\u5b58\u5132\u89e3\u6c7a\u65b9\u6848\uff0c\u80fd\u5920\u5e6b\u52a9\u958b\u767c\u8005\u9ad8\u6548\u5730\u7ba1\u7406\u6578\u64da\u3002\u901a\u904e\u672c\u6587\u7684\u4ecb\u7d39\uff0c\u60a8\u61c9\u8a72\u80fd\u5920\u5728\u672c\u5730\u96fb\u8166\u4e0a\u5b89\u88ddRedis\u4e26\u9032\u884c\u57fa\u672c\u7684\u9023\u63a5\u548c\u64cd\u4f5c\u3002\u5982\u679c\u60a8\u9700\u8981\u66f4\u9ad8\u6548\u7684\u6578\u64da\u8655\u7406\u548c\u5b58\u5132\u65b9\u6848\uff0c\u53ef\u4ee5\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u90e8\u7f72Redis\u670d\u52d9\uff0c\u9019\u6a23\u53ef\u4ee5\u7372\u5f97\u66f4\u597d\u7684\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728\u96fb\u8166\u4e0a\u7c21\u55ae\u9023\u63a5Redis\uff0c\u5feb\u901f\u638c\u63e1Redis\u7684\u57fa\u672c\u4f7f\u7528\u65b9\u6cd5\u8207\u9023\u63a5\u6280\u5de7\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-154097","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/154097","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=154097"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/154097\/revisions"}],"predecessor-version":[{"id":154098,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/154097\/revisions\/154098"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=154097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=154097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=154097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}