{"id":97948,"date":"2024-10-20T22:30:18","date_gmt":"2024-10-20T14:30:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/97948\/"},"modified":"2024-10-20T22:30:19","modified_gmt":"2024-10-20T14:30:19","slug":"redis%e6%93%8d%e4%bd%9c%e7%b0%a1%e6%98%8e%e6%8c%87%e5%8d%97%e5%bf%ab%e9%80%9f%e5%af%a6%e7%8f%be%e7%99%bb%e9%8c%84%e6%93%8d%e4%bd%9c%ef%bc%88redis%e7%99%bb%e9%8c%84%e6%93%8d%e4%bd%9c%e6%ad%a5%e9%a9%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/97948\/","title":{"rendered":"Redis\u64cd\u4f5c\u7c21\u660e\u6307\u5357\u5feb\u901f\u5be6\u73fe\u767b\u9304\u64cd\u4f5c\uff08redis\u767b\u9304\u64cd\u4f5c\u6b65\u9a5f\uff09"},"content":{"rendered":"<h1 id=\"redis%e6%93%8d%e4%bd%9c%e7%b0%a1%e6%98%8e%e6%8c%87%e5%8d%97%e5%bf%ab%e9%80%9f%e5%af%a6%e7%8f%be%e7%99%bb%e9%8c%84%e6%93%8d%e4%bd%9c%ef%bc%88redis%e7%99%bb%e9%8c%84%e6%93%8d%e4%bd%9c%e6%ad%a5%e9%a9%9f-TRNxbFwESw\">Redis\u64cd\u4f5c\u7c21\u660e\u6307\u5357\u5feb\u901f\u5be6\u73fe\u767b\u9304\u64cd\u4f5c\uff08redis\u767b\u9304\u64cd\u4f5c\u6b65\u9a5f\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\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728Redis\u4e2d\u5be6\u73fe\u767b\u9304\u64cd\u4f5c\uff0c\u4e26\u63d0\u4f9b\u7c21\u660e\u7684\u6b65\u9a5f\u548c\u793a\u4f8b\u4ee3\u78bc\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u5feb\u901f\u4e0a\u624b\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afredis%ef%bc%9f-TRNxbFwESw\">\u4ec0\u9ebc\u662fRedis\uff1f<\/h2>\n<p>Redis\uff08REmote DIctionary Server\uff09\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\u7b49\u3002\u7531\u65bc\u5176\u9ad8\u6027\u80fd\u548c\u9748\u6d3b\u6027\uff0cRedis\u88ab\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u61c9\u7528\u7a0b\u5e8f\u4e2d\uff0c\u7279\u5225\u662f\u5728\u9700\u8981\u5feb\u901f\u8b80\u53d6\u548c\u5beb\u5165\u7684\u5834\u666f\u3002<\/p>\n<h2 id=\"%e7%99%bb%e9%8c%84%e6%93%8d%e4%bd%9c%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-TRNxbFwESw\">\u767b\u9304\u64cd\u4f5c\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>\u5728\u8a31\u591a\u61c9\u7528\u4e2d\uff0c\u767b\u9304\u64cd\u4f5c\u901a\u5e38\u6d89\u53ca\u7528\u6236\u540d\u548c\u5bc6\u78bc\u7684\u9a57\u8b49\u3002\u4f7f\u7528Redis\u4f86\u5b58\u5132\u7528\u6236\u7684\u767b\u9304\u4fe1\u606f\uff0c\u53ef\u4ee5\u63d0\u9ad8\u67e5\u8a62\u901f\u5ea6\u548c\u7cfb\u7d71\u7684\u6574\u9ad4\u6027\u80fd\u3002\u4ee5\u4e0b\u662f\u5be6\u73fe\u767b\u9304\u64cd\u4f5c\u7684\u57fa\u672c\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"%e6%ad%a5%e9%a9%9f%e4%b8%80%ef%bc%9a%e5%ae%89%e8%a3%9dredis-TRNxbFwESw\">\u6b65\u9a5f\u4e00\uff1a\u5b89\u88ddRedis<\/h3>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u5728\u60a8\u7684\u4f3a\u670d\u5668\u4e0a\u5b89\u88ddRedis\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5728Ubuntu\u4e0a\u5b89\u88dd\uff1a<\/p>\n<pre><code>sudo apt update\nsudo apt install redis-server<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f%e4%ba%8c%ef%bc%9a%e5%95%9f%e5%8b%95redis%e6%9c%8d%e5%8b%99-TRNxbFwESw\">\u6b65\u9a5f\u4e8c\uff1a\u555f\u52d5Redis\u670d\u52d9<\/h3>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u555f\u52d5Redis\u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl start redis.service<\/code><\/pre>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5Redis\u662f\u5426\u6b63\u5728\u904b\u884c\uff1a<\/p>\n<pre><code>sudo systemctl status redis.service<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f%e4%b8%89%ef%bc%9a%e9%80%a3%e6%8e%a5%e5%88%b0redis-TRNxbFwESw\">\u6b65\u9a5f\u4e09\uff1a\u9023\u63a5\u5230Redis<\/h3>\n<p>\u4f7f\u7528Redis CLI\u5de5\u5177\u9023\u63a5\u5230Redis\u670d\u52d9\uff1a<\/p>\n<pre><code>redis-cli<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f%e5%9b%9b%ef%bc%9a%e8%a8%ad%e7%bd%ae%e7%94%a8%e6%88%b6%e5%90%8d%e5%92%8c%e5%af%86%e7%a2%bc-TRNxbFwESw\">\u6b65\u9a5f\u56db\uff1a\u8a2d\u7f6e\u7528\u6236\u540d\u548c\u5bc6\u78bc<\/h3>\n<p>\u5728Redis\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u54c8\u5e0c\u4f86\u5b58\u5132\u7528\u6236\u7684\u767b\u9304\u4fe1\u606f\u3002\u4ee5\u4e0b\u662f\u8a2d\u7f6e\u7528\u6236\u540d\u548c\u5bc6\u78bc\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>HSET user:1000 username \"user1\" password \"password123\"<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f%e4%ba%94%ef%bc%9a%e5%af%a6%e7%8f%be%e7%99%bb%e9%8c%84%e9%a9%97%e8%ad%89-TRNxbFwESw\">\u6b65\u9a5f\u4e94\uff1a\u5be6\u73fe\u767b\u9304\u9a57\u8b49<\/h3>\n<p>\u7576\u7528\u6236\u63d0\u4ea4\u767b\u9304\u4fe1\u606f\u6642\uff0c\u60a8\u9700\u8981\u5f9eRedis\u4e2d\u6aa2\u7d22\u76f8\u61c9\u7684\u7528\u6236\u4fe1\u606f\u4e26\u9032\u884c\u9a57\u8b49\u3002\u4ee5\u4e0b\u662f\u9a57\u8b49\u7528\u6236\u540d\u548c\u5bc6\u78bc\u7684\u793a\u4f8b\u4ee3\u78bc\uff1a<\/p>\n<pre><code>local username = \"user1\"\nlocal password = \"password123\"\n\nlocal stored_password = redis.call(\"HGET\", \"user:1000\", \"password\")\n\nif stored_password == password then\n    return \"\u767b\u9304\u6210\u529f\"\nelse\n    return \"\u767b\u9304\u5931\u6557\"\nend<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f%e5%85%ad%ef%bc%9a%e8%99%95%e7%90%86%e7%99%bb%e9%8c%84%e7%b5%90%e6%9e%9c-TRNxbFwESw\">\u6b65\u9a5f\u516d\uff1a\u8655\u7406\u767b\u9304\u7d50\u679c<\/h3>\n<p>\u6839\u64da\u9a57\u8b49\u7d50\u679c\uff0c\u60a8\u53ef\u4ee5\u8fd4\u56de\u76f8\u61c9\u7684\u767b\u9304\u72c0\u614b\u7d66\u7528\u6236\u3002\u9019\u53ef\u4ee5\u901a\u904eAPI\u6216\u524d\u7aef\u754c\u9762\u4f86\u5be6\u73fe\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-TRNxbFwESw\">\u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u4ee5\u4e0a\u6b65\u9a5f\uff0c\u60a8\u53ef\u4ee5\u5feb\u901f\u5be6\u73feRedis\u4e2d\u7684\u767b\u9304\u64cd\u4f5c\u3002Redis\u7684\u9ad8\u6548\u6027\u80fd\u4f7f\u5176\u6210\u70ba\u8655\u7406\u7528\u6236\u767b\u9304\u4fe1\u606f\u7684\u7406\u60f3\u9078\u64c7\u3002\u82e5\u60a8\u9700\u8981\u9032\u4e00\u6b65\u7684\u652f\u6301\u6216\u5c0b\u627e\u5408\u9069\u7684\u4f3a\u670d\u5668\u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8003\u616e\u6211\u5011\u7684<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u670d\u52d9\uff0c\u70ba\u60a8\u7684\u61c9\u7528\u63d0\u4f9b\u7a69\u5b9a\u7684\u57fa\u790e\u8a2d\u65bd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Redis\u64cd\u4f5c\u7c21\u660e\u6307\u5357\uff0c\u5feb\u901f\u638c\u63e1\u767b\u9304\u64cd\u4f5c\u6b65\u9a5f\uff0c\u8f15\u9b06\u5be6\u73fe\u9ad8\u6548\u6578\u64da\u7ba1\u7406\u8207\u5b58\u53d6\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-97948","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/97948","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=97948"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/97948\/revisions"}],"predecessor-version":[{"id":97949,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/97948\/revisions\/97949"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=97948"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=97948"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=97948"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}