{"id":2817,"date":"2016-08-07T15:20:17","date_gmt":"2016-08-07T07:20:17","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=2817"},"modified":"2016-08-07T15:20:17","modified_gmt":"2016-08-07T07:20:17","slug":"redis%e6%93%8d%e4%bd%9c%e5%91%bd%e4%bb%a4%e5%b0%8f%e7%bb%93","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/2817.html","title":{"rendered":"Redis\u64cd\u4f5c\u547d\u4ee4\u5c0f\u7ed3"},"content":{"rendered":"<p>=Start=<\/p>\n<h5>\u7f18\u7531\uff1a<\/h5>\n<p>\u6700\u521d\u5b66\u8fc7\u4e00\u6bb5\u65f6\u95f4\u7684Redis\u7684\u4f7f\u7528\uff0c\u4f46\u662f\u540e\u6765\u957f\u65f6\u95f4\u6ca1\u6709\u63a5\u89e6\uff0c\u5c31\u53c8\u5fd8\u4e86\uff0c\u5f80\u590d\u8fd9\u4e48\u5f04\u4e86\u51e0\u6b21\uff0c\u611f\u89c9\u6bd4\u8f83\u6d6a\u8d39\u65f6\u95f4\uff0c\u6240\u4ee5\u4eca\u5929\u51b3\u5b9a\u6574\u7406\u4e00\u4e0bRedis\u7684\u5e38\u89c1\u64cd\u4f5c\u547d\u4ee4\uff0c\u8bb0\u5f55\u5230blog\u4e0a\u6765\uff0c\u65b9\u4fbf\u4ee5\u540e\u67e5\u9605\u3002<\/p>\n<h5>\u6b63\u6587\uff1a<\/h5>\n<p>Redis\u7684\u5b89\u88c5\u4ec0\u4e48\u7684\u5c31\u4e0d\u8bf4\u4e86\uff0c\u6bd4\u8f83\u7b80\u5355\uff08\u4e0d\u8fc7\u8981\u6ce8\u610f\u5b89\u5168\u5c31\u662f\u4e86\uff09\uff0c\u6709\u9700\u8981\u7684\u53ef\u4ee5\u53bb\u770b\u770b\u300c<a href=\"https:\/\/linux.cn\/article-6719-1.html\" target=\"_blank\">\u5982\u4f55\u5728 CentOS 7 \u4e0a\u5b89\u88c5 Redis \u670d\u52a1\u5668<\/a>\u300d\u8fd9\u7bc7\u6587\u7ae0\uff0c\u5185\u5bb9\u57fa\u672c\u90fd\u6709\u3002\u4e0b\u9762\u8bf4\u4e00\u4e0bRedis\u5e38\u89c1\u7684\u64cd\u4f5c\u547d\u4ee4\uff1a<\/p>\n<h6>0.\u8fde\u63a5<\/h6>\n<pre class=\"lang:default decode:true \">$ redis-cli -h localhost -p 6397\n&gt; auth 'redis-pass'<\/pre>\n<h6>1.\u67e5\u770b\u5927\u4f53\u60c5\u51b5<\/h6>\n<pre class=\"lang:default decode:true \">info\nCONFIG GET *\nCONFIG GET requirepass\nCLIENT LIST\nMONITOR\nSLOWLOG GET 25<\/pre>\n<h6>2.\u67e5\u770b(\u5e76\u5207\u6362)\u6709\u54ea\u4e9b\u6570\u636e\u5e93<\/h6>\n<pre class=\"lang:default decode:true \">info keyspace\nCONFIG GET databases\nselect 0\nselect 1<\/pre>\n<h6>3.\u67e5\u770b\u6709\u54ea\u4e9bKEYS<\/h6>\n<pre class=\"lang:default decode:true \">keys * #Redis 2.8 \u4e4b\u524d\u7248\u672c\uff08\u90e8\u5206\u516c\u53f8\u5185\u90e8\u4e00\u822c\u4f1a\u7981\u7528`keys`\u8fd9\u4e2a\u547d\u4ee4\uff09\nscan 0 #Redis 2.8 \u4e4b\u540e\u7248\u672c<\/pre>\n<ul>\n<li><a href=\"http:\/\/stackoverflow.com\/a\/23877883\">http:\/\/stackoverflow.com\/a\/23877883<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/22255589\/get-all-keys-in-redis-database-with-python\">http:\/\/stackoverflow.com\/questions\/22255589\/get-all-keys-in-redis-database-with-python<\/a> #\u7528Python\u64cd\u4f5cRedis<\/li>\n<li><a href=\"http:\/\/redis.io\/commands\/type\">http:\/\/redis.io\/commands\/type<\/a> #\u67e5\u770bkey\u7684\u7c7b\u578b<\/li>\n<\/ul>\n<h6>4.\u5982\u4f55\u83b7\u53d6\u6240\u6709\u7684 VALUES<\/h6>\n<ul>\n<li><a href=\"http:\/\/redis.io\/commands\/scan\">http:\/\/redis.io\/commands\/scan<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/a\/19312607\">http:\/\/stackoverflow.com\/a\/19312607<\/a> #\u6700\u597d\u5c06 keys() \u66ff\u6362\u6210 scan_iter() \u51fd\u6570<\/li>\n<\/ul>\n<h6>5.\u5bf9KEY\u8fdb\u884c\u589e\u5220\u6539\u67e5<\/h6>\n<pre class=\"lang:default decode:true \">#\u6807\u91cf(Scalar)\nget &lt;key&gt;\nset &lt;key&gt; &lt;value&gt;\nsetnx &lt;key&gt; &lt;value&gt; # Set key value only if key does not exist\n\n#\u5217\u8868(List)\nlrange &lt;key&gt; &lt;start&gt; &lt;stop&gt;\nlrange mylist 0 -1      # Get all of a list\nlindex mylist 5         # Get by index\nllen mylist         # Get length\n\nlpush mylist \"value\"\nlpush mylist 5\nrpush mylist \"value\"\n\nlpushx mylist 6         # Only push in mylist exists\n\n#\u54c8\u5e0c\u503c(Hash)\nhexists myhash field1       # Check if hash key exists\n\nhget myhash field1\nhdel myhash field2\nhset myhash field1 \"value\"\nhsetnx myhash field1 \"value\"\n\nhgetall myhash\nhkeys myhash\nhlen myhash<\/pre>\n<p>&nbsp;<\/p>\n<h5>\u53c2\u8003\u94fe\u63a5\uff1a<\/h5>\n<ul>\n<li><a href=\"http:\/\/redis.io\/commands\">http:\/\/redis.io\/commands<\/a><br \/>\n<a href=\"https:\/\/github.com\/andymccurdy\/redis-py\">https:\/\/github.com\/andymccurdy\/redis-py<\/a><br \/>\n<a href=\"http:\/\/lzone.de\/cheat-sheet\/Redis\">http:\/\/lzone.de\/cheat-sheet\/Redis<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/10703019\/redis-fetch-all-value-of-list-without-iteration-and-without-popping\">http:\/\/stackoverflow.com\/questions\/10703019\/redis-fetch-all-value-of-list-without-iteration-and-without-popping<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/6401194\/how-do-i-search-strings-in-redis\">http:\/\/stackoverflow.com\/questions\/6401194\/how-do-i-search-strings-in-redis<\/a> #\u5728Redis\u4e2d\u8fdb\u884c\u6587\u672c\u68c0\u7d22<\/li>\n<\/ul>\n<p>=END=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u7f18\u7531\uff1a \u6700\u521d\u5b66\u8fc7\u4e00\u6bb5\u65f6\u95f4\u7684Redis\u7684\u4f7f\u7528\uff0c\u4f46\u662f\u540e\u6765\u957f\u65f6\u95f4\u6ca1\u6709\u63a5\u89e6\uff0c\u5c31\u53c8\u5fd8\u4e86\uff0c\u5f80\u590d\u8fd9\u4e48\u5f04\u4e86\u51e0\u6b21 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,23,12],"tags":[503],"class_list":["post-2817","post","type-post","status-publish","format-standard","hentry","category-database","category-knowledgebase-2","category-tools","tag-redis"],"views":12020,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2817","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=2817"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2817\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=2817"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=2817"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=2817"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}