{"id":18199,"date":"2024-11-18T11:10:36","date_gmt":"2024-11-18T03:10:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/18199\/"},"modified":"2024-11-18T11:10:36","modified_gmt":"2024-11-18T03:10:36","slug":"linux%e6%80%8e%e4%b9%88%e8%bf%9e%e6%8e%a5redis","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/18199\/","title":{"rendered":"linux\u600e\u4e48\u8fde\u63a5redis"},"content":{"rendered":"<blockquote><p>\n  \u8fde\u63a5 redis \u7684\u65b9\u6cd5\uff1a\u4f7f\u7528\u547d\u4ee4\u884c\u5ba2\u6237\u7aef redis-cli\uff0c\u901a\u8fc7\u547d\u4ee4\u884c\u4ea4\u4e92\u5f0f\u64cd\u4f5c redis\u3002\u901a\u8fc7 python \u5e93 redis-py\uff0c\u63d0\u4f9b pythonic \u63a5\u53e3\u6765\u8bbf\u95ee redis\u3002\u4e0d\u540c\u7f16\u7a0b\u8bed\u8a00\uff08\u5982 java\u3001node.js\u3001go\uff09\u5404\u81ea\u6709\u4e13\u95e8\u7684 redis \u5e93\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/04\/2024060413271658434.jpg\" class=\"aligncenter\" title=\"linux\u600e\u4e48\u8fde\u63a5redis\u63d2\u56fe\" alt=\"linux\u600e\u4e48\u8fde\u63a5redis\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 Linux \u8fde\u63a5 Redis<\/strong><\/p>\n<p><strong>\u8fde\u63a5 Redis \u7684\u65b9\u6cd5<\/strong><\/p>\n<p>\u8fde\u63a5 Redis \u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li> <strong>\u547d\u4ee4\u884c\u5ba2\u6237\u7aef\uff08-cli\uff09\uff1a<\/strong>\u4e00\u79cd\u4ea4\u4e92\u5f0f\u547d\u4ee4\u884c\u754c\u9762\uff0c\u7528\u4e8e\u4e0e Redis \u8fdb\u884c\u4ea4\u4e92\u3002<\/li>\n<li> <strong>Python \u5e93\uff08redis-py\uff09\uff1a<\/strong>\u4e00\u79cd Python \u5e93\uff0c\u63d0\u4f9b\u5bf9 Redis \u547d\u4ee4\u7684 Pythonic \u63a5\u53e3\u3002<\/li>\n<li> <strong>\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u5e93\uff1a<\/strong>\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\uff08\u5982 Java\u3001Node.js \u548c Go\uff09\u90fd\u6709\u81ea\u5df1\u7684 Redis \u5e93\u3002<\/li>\n<\/ul>\n<p><strong>\u4f7f\u7528 redis-cli \u8fde\u63a5 Redis<\/strong><\/p>\n<ol>\n<li>\u5b89\u88c5 redis-cli\uff1a\u4f7f\u7528 sudo apt install redis-cli\uff08\u5bf9\u4e8e Ubuntu\uff09\u6216 sudo yum install redis-cli\uff08\u5bf9\u4e8e CentOS\uff09\u3002<\/li>\n<li>\u8fde\u63a5 Redis\uff1a\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c redis-cli \u547d\u4ee4\u3002<\/li>\n<li>\u8f93\u5165\u547d\u4ee4\uff1a\u952e\u5165 Redis \u547d\u4ee4\u4ee5\u4e0e Redis \u8fdb\u884c\u4ea4\u4e92\uff0c\u4f8b\u5982 SET key value \u6765\u8bbe\u7f6e\u952e\u503c\u3002<\/li>\n<\/ol>\n<p><strong>\u4f7f\u7528 Python \u5e93\u8fde\u63a5 Redis<\/strong><\/p>\n<ol>\n<li>\u5b89\u88c5 redis-py\uff1a\u4f7f\u7528 pip install redis\u3002<\/li>\n<li>\u5bfc\u5165\u5e93\uff1a\u5728 Python \u811a\u672c\u4e2d\u5bfc\u5165 redis \u5e93\u3002<\/li>\n<li>\n<p>\u521b\u5efa Redis \u5ba2\u6237\u7aef\uff1a\u5b9e\u4f8b\u5316\u4e00\u4e2a redis.StrictRedis \u5bf9\u8c61\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>import redis\n\nr = redis.StrictRedis(host='localhost', port=6379, db=0)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\u4f7f\u7528 Redis \u547d\u4ee4\uff1a\u4f7f\u7528 r \u5bf9\u8c61\u8c03\u7528 Redis \u547d\u4ee4\uff0c\u4f8b\u5982 r.set(&#8216;key&#8217;, &#8216;value&#8217;) \u6765\u8bbe\u7f6e\u952e\u503c\u3002<\/li>\n<\/ol>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u8fde\u63a5\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fde\u63a5 redis \u7684\u65b9\u6cd5\uff1a\u4f7f\u7528\u547d\u4ee4\u884c\u5ba2\u6237\u7aef redis-cli\uff0c\u901a\u8fc7\u547d\u4ee4\u884c\u4ea4\u4e92\u5f0f\u64cd\u4f5c redis\u3002\u901a\u8fc7 python \u5e93 redis-py\uff0c\u63d0\u4f9b pythonic \u63a5\u53e3\u6765\u8bbf\u95ee redis\u3002\u4e0d\u540c\u7f16\u7a0b\u8bed\u8a00\uff08\u5982 java\u3001node.js\u3001go\uff09\u5404\u81ea\u6709\u4e13\u95e8\u7684 redis \u5e93\u3002 \u5982\u4f55\u4f7f\u7528 Linux \u8fde\u63a5 Redis \u8fde\u63a5 Redis \u7684\u65b9\u6cd5 \u8fde\u63a5 Redis \u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a \u547d\u4ee4\u884c\u5ba2\u6237\u7aef\uff08-cli\uff09\uff1a\u4e00\u79cd\u4ea4\u4e92\u5f0f\u547d\u4ee4\u884c\u754c\u9762\uff0c\u7528\u4e8e\u4e0e Redis \u8fdb\u884c\u4ea4\u4e92\u3002 Python \u5e93\uff08redis-py\uff09\uff1a\u4e00\u79cd Python \u5e93\uff0c\u63d0\u4f9b\u5bf9 Redis \u547d\u4ee4\u7684 Pythonic \u63a5\u53e3\u3002 \u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u5e93\uff1a\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\uff08\u5982 Java\u3001Node.js \u548c Go\uff09\u90fd\u6709\u81ea\u5df1\u7684 Redis \u5e93\u3002 \u4f7f\u7528 redis-cli \u8fde\u63a5 Redis \u5b89\u88c5 redis-cli\uff1a\u4f7f\u7528 sudo apt install redis-cli\uff08\u5bf9\u4e8e Ubuntu\uff09\u6216 sudo yum install [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-18199","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18199","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=18199"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18199\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=18199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=18199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=18199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}