{"id":167595,"date":"2024-11-06T02:14:26","date_gmt":"2024-11-05T18:14:26","guid":{"rendered":"https:\/\/server.hk\/cnblog\/167595\/"},"modified":"2024-11-06T02:14:27","modified_gmt":"2024-11-05T18:14:27","slug":"%e5%88%a9%e7%94%a8redis%e9%80%a3%e6%8e%a5%e6%95%b8%e6%93%9a%e5%ba%ab%e5%bf%ab%e6%8d%b7%e6%8c%87%e4%bb%a4%ef%bc%88redis%e9%80%a3%e6%8e%a5%e6%95%b8%e6%93%9a%e5%ba%ab%e5%91%bd%e4%bb%a4%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/167595\/","title":{"rendered":"\u5229\u7528Redis\u9023\u63a5\u6578\u64da\u5eab\u5feb\u6377\u6307\u4ee4\uff08redis\u9023\u63a5\u6578\u64da\u5eab\u547d\u4ee4\uff09"},"content":{"rendered":"<h1 id=\"%e5%88%a9%e7%94%a8redis%e9%80%a3%e6%8e%a5%e6%95%b8%e6%93%9a%e5%ba%ab%e5%bf%ab%e6%8d%b7%e6%8c%87%e4%bb%a4%ef%bc%88redis%e9%80%a3%e6%8e%a5%e6%95%b8%e6%93%9a%e5%ba%ab%e5%91%bd%e4%bb%a4%ef%bc%89-XiuPCoBydN\">\u5229\u7528Redis\u9023\u63a5\u6578\u64da\u5eab\u5feb\u6377\u6307\u4ee4\uff08redis\u9023\u63a5\u6578\u64da\u5eab\u547d\u4ee4\uff09<\/h1>\n<p>Redis\u662f\u4e00\u500b\u9ad8\u6548\u7684\u9375\u503c\u6578\u64da\u5eab\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u7de9\u5b58\u3001\u6d88\u606f\u968a\u5217\u548c\u6578\u64da\u5b58\u5132\u7b49\u5834\u666f\u3002\u7531\u65bc\u5176\u9ad8\u6027\u80fd\u548c\u9748\u6d3b\u6027\uff0c\u8a31\u591a\u958b\u767c\u8005\u9078\u64c7\u5c07Redis\u4f5c\u70ba\u5176\u61c9\u7528\u7a0b\u5e8f\u7684\u6578\u64da\u5b58\u5132\u89e3\u6c7a\u65b9\u6848\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5229\u7528Redis\u9023\u63a5\u6578\u64da\u5eab\u7684\u5feb\u6377\u6307\u4ee4\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u9ad8\u6548\u5730\u4f7f\u7528Redis\u3002<\/p>\n<h2 id=\"redis%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-XiuPCoBydN\">Redis\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>\u5728\u6df1\u5165\u4e86\u89e3Redis\u7684\u9023\u63a5\u6307\u4ee4\u4e4b\u524d\uff0c\u6211\u5011\u9700\u8981\u5148\u4e86\u89e3Redis\u7684\u4e00\u4e9b\u57fa\u672c\u6982\u5ff5\u3002Redis\u662f\u4e00\u500b\u958b\u6e90\u7684\u5167\u5b58\u6578\u64da\u7d50\u69cb\u5b58\u5132\u7cfb\u7d71\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\u3002\u5b83\u7684\u4e3b\u8981\u7279\u9ede\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u9ad8\u6027\u80fd\uff1aRedis\u80fd\u5920\u6bcf\u79d2\u8655\u7406\u6578\u5341\u842c\u6b21\u7684\u8b80\u5beb\u64cd\u4f5c\u3002<\/li>\n<li>\u6301\u4e45\u5316\uff1a\u652f\u6301\u5c07\u6578\u64da\u6301\u4e45\u5316\u5230\u78c1\u789f\uff0c\u907f\u514d\u6578\u64da\u4e1f\u5931\u3002<\/li>\n<li>\u591a\u7a2e\u6578\u64da\u7d50\u69cb\uff1a\u652f\u6301\u591a\u7a2e\u6578\u64da\u985e\u578b\uff0c\u9748\u6d3b\u61c9\u7528\u65bc\u4e0d\u540c\u5834\u666f\u3002<\/li>\n<\/ul>\n<h2 id=\"%e9%80%a3%e6%8e%a5redis%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e5%9f%ba%e6%9c%ac%e5%91%bd%e4%bb%a4-XiuPCoBydN\">\u9023\u63a5Redis\u6578\u64da\u5eab\u7684\u57fa\u672c\u547d\u4ee4<\/h2>\n<p>\u8981\u4f7f\u7528Redis\uff0c\u9996\u5148\u9700\u8981\u9023\u63a5\u5230Redis\u670d\u52d9\u5668\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u57fa\u672c\u7684\u9023\u63a5\u547d\u4ee4\uff1a<\/p>\n<h3 id=\"1-%e4%bd%bf%e7%94%a8redis-cli%e9%80%a3%e6%8e%a5-XiuPCoBydN\">1. \u4f7f\u7528redis-cli\u9023\u63a5<\/h3>\n<pre><code>redis-cli -h  -p  -a <\/code><\/pre>\n<p>\u5728\u9019\u500b\u547d\u4ee4\u4e2d\uff0c\u662fRedis\u670d\u52d9\u5668\u7684\u5730\u5740\uff0c\u662fRedis\u670d\u52d9\u5668\u7684\u7aef\u53e3\uff08\u9ed8\u8a8d\u70ba6379\uff09\uff0c\u662f\u9023\u63a5Redis\u6240\u9700\u7684\u5bc6\u78bc\uff08\u5982\u679c\u8a2d\u7f6e\u4e86\u7684\u8a71\uff09\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>redis-cli -h 127.0.0.1 -p 6379 -a mypassword<\/code><\/pre>\n<h3 id=\"2-%e4%bd%bf%e7%94%a8python%e9%80%a3%e6%8e%a5redis-XiuPCoBydN\">2. \u4f7f\u7528Python\u9023\u63a5Redis<\/h3>\n<p>\u5982\u679c\u60a8\u4f7f\u7528Python\u958b\u767c\u61c9\u7528\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u4f7f\u7528redis-py\u5eab\u4f86\u9023\u63a5Redis\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u5b89\u88ddredis-py\uff1a<\/p>\n<pre><code>pip install redis<\/code><\/pre>\n<p>\u7136\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u78bc\u9023\u63a5Redis\uff1a<\/p>\n<pre><code>import redis\n\nr = redis.Redis(host='localhost', port=6379, password='mypassword')\n<\/code><\/pre>\n<h3 id=\"3-%e4%bd%bf%e7%94%a8node-js%e9%80%a3%e6%8e%a5redis-XiuPCoBydN\">3. \u4f7f\u7528Node.js\u9023\u63a5Redis<\/h3>\n<p>\u5c0d\u65bcNode.js\u958b\u767c\u8005\uff0c\u53ef\u4ee5\u4f7f\u7528node-redis\u5eab\u4f86\u9023\u63a5Redis\u3002\u9996\u5148\uff0c\u5b89\u88ddnode-redis\uff1a<\/p>\n<pre><code>npm install redis<\/code><\/pre>\n<p>\u7136\u5f8c\uff0c\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u78bc\u9023\u63a5Redis\uff1a<\/p>\n<pre><code>const redis = require('redis');\nconst client = redis.createClient({\n    host: 'localhost',\n    port: 6379,\n    password: 'mypassword'\n});\n<\/code><\/pre>\n<h2 id=\"%e5%b8%b8%e7%94%a8%e7%9a%84redis%e5%91%bd%e4%bb%a4-XiuPCoBydN\">\u5e38\u7528\u7684Redis\u547d\u4ee4<\/h2>\n<p>\u9023\u63a5\u5230Redis\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5404\u7a2e\u547d\u4ee4\u4f86\u64cd\u4f5c\u6578\u64da\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684Redis\u547d\u4ee4\uff1a<\/p>\n<ul>\n<li><code>SET key value<\/code>\uff1a\u8a2d\u7f6e\u6307\u5b9a\u9375\u7684\u503c\u3002<\/li>\n<li><code>GET key<\/code>\uff1a\u7372\u53d6\u6307\u5b9a\u9375\u7684\u503c\u3002<\/li>\n<li><code>DEL key<\/code>\uff1a\u522a\u9664\u6307\u5b9a\u9375\u3002<\/li>\n<li><code>EXISTS key<\/code>\uff1a\u6aa2\u67e5\u6307\u5b9a\u9375\u662f\u5426\u5b58\u5728\u3002<\/li>\n<li><code>KEYS pattern<\/code>\uff1a\u67e5\u627e\u6240\u6709\u7b26\u5408\u7d66\u5b9a\u6a21\u5f0f\u7684\u9375\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-XiuPCoBydN\">\u7e3d\u7d50<\/h2>\n<p>Redis\u4f5c\u70ba\u4e00\u500b\u9ad8\u6548\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\uff0c\u63d0\u4f9b\u4e86\u591a\u7a2e\u9023\u63a5\u65b9\u5f0f\u548c\u547d\u4ee4\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u5feb\u901f\u4e0a\u624b\u3002\u5728\u4f7f\u7528Redis\u6642\uff0c\u4e86\u89e3\u57fa\u672c\u7684\u9023\u63a5\u6307\u4ee4\u548c\u5e38\u7528\u547d\u4ee4\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u7121\u8ad6\u60a8\u662f\u4f7f\u7528Python\u9084\u662fNode.js\uff0cRedis\u90fd\u80fd\u5920\u8f15\u9b06\u96c6\u6210\u5230\u60a8\u7684\u61c9\u7528\u7a0b\u5e8f\u4e2d\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\u4f86\u904b\u884c\u60a8\u7684Redis\u670d\u52d9\uff0cServer.HK\u63d0\u4f9b\u4e86\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u7684\u7528\u6236\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u985e\u578b\u7684 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a>\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22Redis\u9023\u63a5\u6578\u64da\u5eab\u7684\u5feb\u6377\u6307\u4ee4\uff0c\u638c\u63e1\u9ad8\u6548\u7684\u6578\u64da\u64cd\u4f5c\u547d\u4ee4\uff0c\u63d0\u5347\u958b\u767c\u6548\u7387\u8207\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-167595","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/167595","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=167595"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/167595\/revisions"}],"predecessor-version":[{"id":167596,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/167595\/revisions\/167596"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=167595"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=167595"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=167595"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}