{"id":97607,"date":"2024-06-12T22:59:12","date_gmt":"2024-06-12T14:59:12","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=97607"},"modified":"2024-06-12T22:59:12","modified_gmt":"2024-06-12T14:59:12","slug":"redis-easy-entry","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/redis-easy-entry.html","title":{"rendered":"Redis\u5165\u95e8\u6307\u5357"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nRedis\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u4f7f\u7528ANSI C\u8bed\u8a00\u7f16\u5199\u3001\u652f\u6301\u7f51\u7edc\u3001\u53ef\u57fa\u4e8e\u5185\u5b58\u4ea6\u53ef\u6301\u4e45\u5316\u7684\u65e5\u5fd7\u578b\u3001Key-Value\u6570\u636e\u5e93\uff0c\u5e76\u63d0\u4f9b\u591a\u79cd\u8bed\u8a00\u7684API\u3002\u4ece2010\u5e743\u670815\u65e5\u8d77\uff0cRedis\u7684\u5f00\u53d1\u5de5\u4f5c\u7531VMware\u4e3b\u6301\u3002\u4ece2013\u5e745\u6708\u5f00\u59cb\uff0cRedis\u7684\u5f00\u53d1\u7531Pivotal\u8d5e\u52a9\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u4e00\u3001\u5b89\u88c5Redis<\/strong><\/div>\n

Redis\u914d\u7f6e\u6587\u4ef6\uff1a\/etc\/redis.conf<\/p>\n

Redis\u4e3b\u7a0b\u5e8f\uff1a\/usr\/bin\/redis-server<\/p>\n

\u5ba2\u6237\u7aef\u5de5\u5177\uff1a\/usr\/bin\/redis-cli<\/p>\n

\u9ed8\u8ba4\u76d1\u542c\u7aef\u53e3\uff1a6379<\/p>\n

\u6570\u636e\u76ee\u5f55\uff1a\/var\/lib\/redis<\/p>\n

\u670d\u52a1\u811a\u672c\uff1a\/usr\/lib\/systemd\/system\/redis.service<\/p>\n

\r\nyum install redis                  # \u57fa\u4e8eCentOS7\u7684epel\u6e90\r\n<\/pre>\n
\u4e8c\u3001\u8fde\u63a5Redis<\/strong><\/div>\n

Redis\u7684\u5ba2\u6237\u7aef\u547d\u4ee4\u5de5\u5177\u4e3aredis-cli\uff0c\u9ed8\u8ba4\u8fde\u63a5\u672c\u5730\u7684Redis\u670d\u52a1\u3002<\/p>\n

\u5982\u679c\u9700\u8981\u8fdc\u7a0b\u8fde\u63a5\u5219\u4f7f\u7528redis-cli -h HOST -p PORT -a PASSWD<\/p>\n

\r\n[root@cache1 ~]# redis-cli \r\n127.0.0.1:6379> ping                            # \u4f7f\u7528ping\u547d\u4ee4\u6d4b\u8bd5\u4e0e\u670d\u52a1\u7684\u8fde\u63a5\u6027\r\nPONG                                            # \u670d\u52a1\u7aef\u56de\u590dpong\u5219\u8bf4\u660e\u7f51\u7edc\u8fde\u63a5\u6ca1\u6709\u95ee\u9898\r\n<\/pre>\n
\u4e09\u3001Redis\u6570\u636e\u7c7b\u578b<\/strong><\/div>\n

String\uff08\u5b57\u7b26\u4e32\uff09<\/span><\/p>\n

string\u662fredis\u6700\u57fa\u672c\u7684\u7c7b\u578b\uff0c\u4f60\u53ef\u4ee5\u7406\u89e3\u6210\u4e0eMemcached\u4e00\u6a21\u4e00\u6837\u7684\u7c7b\u578b\uff0c\u4e00\u4e2akey\u5bf9\u5e94\u4e00\u4e2avalue\u3002<\/p>\n

string\u7c7b\u578b\u662f\u4e8c\u8fdb\u5236\u5b89\u5168\u7684\u3002\u610f\u601d\u662fredis\u7684string\u53ef\u4ee5\u5305\u542b\u4efb\u4f55\u6570\u636e\u3002\u6bd4\u5982jpg\u56fe\u7247\u6216\u8005\u5e8f\u5217\u5316\u7684\u5bf9\u8c61 \u3002<\/p>\n

string\u7c7b\u578b\u662fRedis\u6700\u57fa\u672c\u7684\u6570\u636e\u7c7b\u578b\uff0c\u4e00\u4e2a\u952e\u6700\u5927\u80fd\u5b58\u50a8512MB\u3002<\/p>\n

Hash\uff08\u54c8\u5e0c\uff09<\/span><\/p>\n

Redis hash \u662f\u4e00\u4e2a\u952e\u503c(key=>value)\u5bf9\u96c6\u5408\u3002<\/p>\n

Redis hash\u662f\u4e00\u4e2astring\u7c7b\u578b\u7684field\u548cvalue\u7684\u6620\u5c04\u8868\uff0chash\u7279\u522b\u9002\u5408\u7528\u4e8e\u5b58\u50a8\u5bf9\u8c61\u3002<\/p>\n

List\uff08\u5217\u8868\uff09<\/span><\/p>\n

Redis \u5217\u8868\u662f\u7b80\u5355\u7684\u5b57\u7b26\u4e32\u5217\u8868\uff0c\u6309\u7167\u63d2\u5165\u987a\u5e8f\u6392\u5e8f\u3002\u4f60\u53ef\u4ee5\u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20\u5230\u5217\u8868\u7684\u5934\u90e8\uff08\u5de6\u8fb9\uff09\u6216\u8005\u5c3e\u90e8\uff08\u53f3\u8fb9\uff09\u3002<\/p>\n

Set\uff08\u96c6\u5408\uff09<\/span><\/p>\n

Redis\u7684Set\u662fstring\u7c7b\u578b\u7684\u65e0\u5e8f\u96c6\u5408\u3002<\/p>\n

\u96c6\u5408\u662f\u901a\u8fc7\u54c8\u5e0c\u8868\u5b9e\u73b0\u7684\uff0c\u6240\u4ee5\u6dfb\u52a0\uff0c\u5220\u9664\uff0c\u67e5\u627e\u7684\u590d\u6742\u5ea6\u90fd\u662fO(1)\u3002<\/p>\n

zset(sorted set\uff1a\u6709\u5e8f\u96c6\u5408)<\/span><\/p>\n

Redis zset \u548c set \u4e00\u6837\u4e5f\u662fstring\u7c7b\u578b\u5143\u7d20\u7684\u96c6\u5408,\u4e14\u4e0d\u5141\u8bb8\u91cd\u590d\u7684\u6210\u5458\u3002<\/p>\n

\u4e0d\u540c\u7684\u662f\u6bcf\u4e2a\u5143\u7d20\u90fd\u4f1a\u5173\u8054\u4e00\u4e2adouble\u7c7b\u578b\u7684\u5206\u6570\u3002redis\u6b63\u662f\u901a\u8fc7\u5206\u6570\u6765\u4e3a\u96c6\u5408\u4e2d\u7684\u6210\u5458\u8fdb\u884c\u4ece\u5c0f\u5230\u5927\u7684\u6392\u5e8f\u3002<\/p>\n

zset\u7684\u6210\u5458\u662f\u552f\u4e00\u7684,\u4f46\u5206\u6570(score)\u5374\u53ef\u4ee5\u91cd\u590d\u3002<\/p>\n

\u56db\u3001\u83b7\u53d6\u5e2e\u52a9<\/strong><\/div>\n
\r\nhelp @  + \u53cc\u51fbtab                        # \u53cc\u51fbtab\u4f1a\u51fa\u73b0\u5404\u79cd\u5b50\u547d\u4ee4\u7684\u5e2e\u52a9\r\n\r\nhelp @string                            # \u5b57\u7b26\u4e32\u76f8\u5173\u7684\u914d\u7f6e\r\nhelp @list                              # \u5217\u8868\u76f8\u5173\u7684\u914d\u7f6e\uff1b\u5217\u8868\u7c7b\u4f3c\u4e8e\u6570\u7ec4\r\nhelp @set\r\nhelp @hash\r\n......\r\n<\/pre>\n
\u4e94\u3001List\u76f8\u5173\u7684\u547d\u4ee4<\/strong><\/div>\n

\u5176\u4ed6\u51e0\u4e2a\u6570\u636e\u7c7b\u578b\u6bd4\u8f83\u7b80\u5355\uff0c\u901a\u8fc7\u5e2e\u52a9\u5c31\u80fd\u83b7\u5f97\u547d\u4ee4\u7684\u4f7f\u7528\u65b9\u6cd5\u3002\u6700\u7b80\u5355\u7684\u529e\u6cd5\u5c31\u662f\u767e\u5ea6\u3002\u7531\u4e8eList\u76f8\u5173\u7684\u547d\u4ee4\u4ec5\u4ec5\u770b\u5e2e\u52a9\u7684\u8bdd\u5f88\u96be\u7406\u89e3\u4e00\u4e9b\u64cd\u4f5c\uff0c\u6240\u4ee5\u62ff\u51fa\u6765\u5355\u72ec\u8bb2\u8bb2\u6700\u5e38\u7528\u7684\u51e0\u4e2a\u547d\u4ee4
\n\"\"<\/p>\n

\u793a\u4f8b\uff1a<\/p>\n

\r\n127.0.0.1:6379> LPUSH stu aubin                 # LPUSH\uff0c\u5411\u5217\u8868\u5de6\u4fa7\u6dfb\u52a0\u5143\u7d20\uff0c\u5217\u8868\u4e0d\u5b58\u5728\u81ea\u52a8\u521b\u5efa\r\n(integer) 1\r\n127.0.0.1:6379> RPUSH stu 22                    # RPUSH\uff0c\u5411\u5217\u8868\u53f3\u4fa7\u6dfb\u52a0\u5143\u7d20\uff0c\u5217\u8868\u4e0d\u5b58\u5728\u5219\u81ea\u52a8\u521b\u5efa\r\n(integer) 2\r\n127.0.0.1:6379> RPUSHX  stu nan                 # RPUSHX\uff0c\u5982\u679c\u5217\u8868\u5b58\u5728\u5219\u53f3\u4fa7\u6dfb\u52a0\u5143\u7d20\r\n(integer) 3\r\n127.0.0.1:6379> LPUSHX  stu linux               # LPUSHX\uff0c\u5982\u679c\u5217\u8868\u5b58\u5728\u5219\u5de6\u4fa7\u6dfb\u52a0\u5143\u7d20\r\n(integer) 4\r\n127.0.0.1:6379> LRANGE stu 0 10                 # LRANGE\uff0c\u663e\u793a\u540d\u4e3astu\u7684\u5217\u8868\u76840-10\u4e2a\u503c\r\n1) \"aubin\"\r\n2) \"22\"\r\n3) \"nan\"\r\n4) \"linux\"\r\n\r\nLPOP stu                                # \u5de6\u5f39\uff0c\u5220\u9664\u540d\u4e3astu\u5217\u8868\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\r\nRPOP stu                                # \u53f3\u5f39\uff0c\u5220\u9664\u540d\u4e3astu\u5217\u8868\u4e2d\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\r\nLREM stu  3  aubin                      # \u4ece\u5934\u5230\u5c3e\u5220\u96643\u4e2a\u503c\u4e3aaubin\u7684\u5143\u7d20\r\nLREM stu  -3  aubin                     # \u4ece\u5c3e\u5230\u5934\u5220\u96643\u4e2a\u503c\u4e3aaubin\u7684\u5143\u7d20\r\nLREM stu  0  aubin                      # \u5220\u9664\u6240\u6709\u503c\u4e3aaubin\u7684\u5143\u7d20\r\n<\/pre>\n
\n

\u539f\u6587\u6765\u81ea\uff1ahttp:\/\/www.cnblogs.com\/aubin\/p\/7846114.html<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1ahttps:\/\/lrxjmw.cn\/redis-easy-entry.html<\/a>\u7f16\u8f91\uff1a\u4f55\u4e91\u8273\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u5bfc\u8bfb Redis\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u4f7f\u7528ANSI C\u8bed\u8a00\u7f16\u5199\u3001\u652f\u6301\u7f51\u7edc\u3001\u53ef\u57fa\u4e8e\u5185\u5b58\u4ea6\u53ef\u6301\u4e45\u5316\u7684\u65e5\u5fd7\u578b\u3001Key-Valu […]<\/p>\n","protected":false},"author":1479,"featured_media":97746,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-97607","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/97607","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=97607"}],"version-history":[{"count":9,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/97607\/revisions"}],"predecessor-version":[{"id":291969,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/97607\/revisions\/291969"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/97746"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=97607"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=97607"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=97607"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}