\u603b\u7ed3\uff08Summary\uff09<\/li>\n<\/ul>\n<\/div>\n\u7b80\u4ecb<\/h1>\n\u80cc\u666f<\/h2>\n
\u6211\u4eec\u73b0\u5728\u7684\u9879\u76ee\u67b6\u6784\u4e2d\uff0c\u57fa\u672c\u4e0a\u662fWeb\u670d\u52a1\u5668(Tomcat)\u548c\u6570\u636e\u5e93\u72ec\u7acb\u90e8\u7f72\uff0c\u72ec\u5360\u670d\u52a1\u5668\u8d44\u6e90\uff0c\u968f\u7740\u7528\u6237\u6570\u7684\u589e\u957f\uff0c\u5e76\u53d1\u8bfb\u5199\u6570\u636e\u5e93\uff0c\u4f1a\u52a0\u5927\u6570\u636e\u5e93\u8bbf\u95ee\u538b\u529b\uff0c\u5bfc\u81f4\u6027\u80fd\u7684\u4e0b\u964d\uff0c\u4e25\u91cd\u65f6\u76f4\u63a5\u5bfc\u81f4\u7cfb\u7edf\u5b95\u673a\uff0c\u4f8b\u5982\uff1a<\/p>\n
<\/p>\n
\u6b64\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u5728Tomcat\u540c\u670d\u52a1\u5668\u4e0a\u4e2d\u589e\u52a0\u672c\u5730\u7f13\u5b58\uff0c\u5e76\u5728\u5916\u90e8\u589e\u52a0\u5206\u5e03\u5f0f\u7f13\u5b58\uff0c\u7f13\u5b58\u70ed\u95e8\u6570\u636e\u3002\u4e5f\u5c31\u662f\u901a\u8fc7\u7f13\u5b58\u80fd\u628a\u7edd\u5927\u591a\u6570\u8bf7\u6c42\u5728\u8bfb\u5199\u6570\u636e\u5e93\u524d\u62e6\u622a\u6389\uff0c\u5927\u5927\u964d\u4f4e\u6570\u636e\u5e93\u538b\u529b\u3002\u4f8b\u5982\uff1a
<\/p>\n
\u57fa\u4e8e\u8fd9\u6837\u7684\u4e00\u79cd\u67b6\u6784\u8bbe\u8ba1\uff0c\u4e8e\u662f\u7c7b\u4f3credis\u7684\u4e00\u4e9b\u5206\u5e03\u5f0f\u6570\u636e\u5e93\u5c31\u8bde\u751f\u4e86\u3002<\/p>\n
Redis \u6982\u8ff0<\/h2>\n
Redis\uff08Remote Dictionary Server )\u5373\u8fdc\u7a0b\u5b57\u5178\u670d\u52a1,\u662f C \u8bed\u8a00\u5f00\u53d1\u7684\u4e00\u4e2a\u5f00\u6e90\u7684key\/value\u5b58\u50a8\u7cfb\u7edf\uff08\u5b98\u7f51\uff1ahttp:\/\/redis.io\uff09\uff0c\u662f\u4e00\u4e2a\u5206\u5e03\u5f0f\u7f13\u5b58\u6570\u636e\u5e93\u3002\u7531\u4e8e\u5b83\u662f\u57fa\u4e8e\u5185\u5b58\u7684\u6240\u4ee5\u5b83\u8981\u6bd4\u57fa\u4e8e\u78c1\u76d8\u8bfb\u5199\u7684\u6570\u636e\u5e93\u6548\u7387\u66f4\u5feb\u3002\u5728DB-Engines.com\u7684\u6570\u636e\u5e93\u6392\u884c\u4e2d\uff0c Redis\u4e0a\u5347\u6392\u884c\u7b2c\u4e03\uff0c\u5982\u56fe\u6240\u793a\uff1a<\/p>\n
<\/p>\n
\u7248\u672c\u53ca\u53c2\u8003\u8bf4\u660e<\/h2>\n
Redis\u7684\u6b21\u7248\u672c\u53f7\uff08\u7b2c\u4e00\u4e2a\u5c0f\u6570\u70b9\u540e\u7684\u6570\u5b57\uff09\u4e3a\u5076\u6570\u7684\u7248\u672c\u662f\u7a33\u5b9a\u7248\u672c\uff082.4\u30012.6\u7b49\uff09\uff0c\u5947\u6570\u4e3a\u975e\u7a33\u5b9a\u7248\u672c\uff082.5\u30012.7\uff09\uff0c\u4e00\u822c\u63a8\u8350\u5728\u751f\u4ea7\u73af\u5883\u4f7f\u7528\u7a33\u5b9a\u7248\u672c\u3002\u6700\u65b0\u7248\u672c6.2.2\uff0c\u65b0\u589e\u4e86stream\u7684\u5904\u7406\u65b9\u5f0f\uff0c\u6027\u80fd\u66f4\u9ad8\u3002Redis\u5b98\u65b9\u662f\u4e0d\u652f\u6301windows\u5e73\u53f0\u7684\uff0cwindows\u7248\u672c\u662f\u7531\u5fae\u8f6f\u81ea\u5df1\u5efa\u7acb\u7684\u5206\u652f\uff0c\u57fa\u4e8e\u5b98\u65b9\u7684Redis\u6e90\u7801\u4e0a\u8fdb\u884c\u7f16\u8bd1\u3001\u53d1\u5e03\u3001\u7ef4\u62a4\u7684\uff0c\u6240\u4ee5windows\u5e73\u53f0\u7684Redis\u7248\u672c\u8981\u7565\u4f4e\u4e8e\u5b98\u65b9\u7248\u672c\u3002<\/p>\n
Redis \u76f8\u5173\u53c2\u8003\u7f51\u5740\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n
Bootnb \u76f8\u5173\uff1ahttps:\/\/www.runoob.com\/redis\/redis-tutorial.html\nRedis \u5b98\u7f51\uff1ahttps:\/\/redis.io\/\n\u6e90\u7801\u5730\u5740\uff1ahttps:\/\/github.com\/redis\/redis\nRedis \u5728\u7ebf\u6d4b\u8bd5\uff1ahttp:\/\/try.redis.io\/\nRedis \u547d\u4ee4\u53c2\u8003\uff1ahttp:\/\/doc.redisfans.com\/\n<\/code><\/pre>\nRedis\u521d\u59cb\u64cd\u4f5c<\/h1>\n\u542f\u52a8redis\u670d\u52a1<\/h2>\n
Docker \u73af\u5883\u4e0b\u7684\u542f\u52a8(docker\u73af\u5883\u542f\u52a8\u591a\u4e2a\u9700\u8981\u8fd0\u884c\u591a\u4e2a\u5bb9\u5668)\uff1a<\/p>\n
docker start redis01 #\u5e95\u5c42\u4e5f\u662f\u901a\u8fc7redis-server\u542f\u52a8\uff0cstart\u5355\u8bcd\u540e\u7684redis01\u4e3a\u5bb9\u5668\u540d\n<\/code><\/pre>\n\ndocker \u4e2d\u67e5\u770bredis \u670d\u52a1<\/p>\n<\/blockquote>\n
docker ps\n<\/code><\/pre>\n\n\u67e5\u770b\u542f\u52a8\u7684redis\u8fdb\u7a0b\u4fe1\u606f<\/p>\n<\/blockquote>\n
ps -ef|grep redis\nroot 3511 1 0 16:29 ? 00:00:01 redis-server *:6379\nroot 3515 1 0 16:29 ? 00:00:01 redis-server 127.0.0.1:6380\n<\/code><\/pre>\n\u8fdb\u5165redis\u5bb9\u5668<\/h2>\n
docker exec -it redis01 bash #redis01 \u4e3a\u5bb9\u5668\u540d<\/p>\n
\u767b\u9646redis\u670d\u52a1<\/h2>\n\n\u767b\u9646\u672c\u5730redis<\/p>\n<\/blockquote>\n
redis-cli\n\u6216\u8005\nredis-cli -p 6379\n\u6216\u8005\nredis-cli -p 6379 -a password #-a\u540e\u9762\u4e3apassword,\u6b64\u64cd\u4f5c\u9700\u8981\u5f00\u542fredis.conf\u6587\u4ef6\u4e2d\u7684 requirepass\u9009\u9879\n\n<\/code><\/pre>\n\n\u767b\u9646\u8fdc\u7a0bredis<\/p>\n<\/blockquote>\n
redis-cli -h ip -p 6379 -a password\n<\/code><\/pre>\n\u67e5\u770bredis\u4fe1\u606f<\/h2>\n
\u9996\u5148\u767b\u9646redis\uff0c\u7136\u540e\u8f93\u5165info\u6307\u4ee4\uff0c\u4f8b\u5982<\/p>\n
127.0.0.1:6379> info\t\t#\u67e5\u770b\u5f53\u524dredis\u8282\u70b9\u7684\u8be6\u7ec6\u914d\u7f6e\u4fe1\u606f\n<\/code><\/pre>\n\u6e05\u7a7aredis\u5c4f\u5e55<\/h2>\n
\u6e05\u9664redis\u5c4f\u5e55\u5185\u5bb9<\/p>\n
127.0.0.1:6379><\/span> clear<\/span>\n<\/code><\/pre>\n\u9000\u51faredis\u670d\u52a1<\/h2>\n
\u9000\u51faredis\u670d\u52a1\uff0c\u4f8b\u5982<\/p>\n
127.0.0.1:6379> exit\n<\/code><\/pre>\n\u5173\u95edredis\u670d\u52a1<\/h2>\n
\u5173\u95edredis\u670d\u52a1\uff0c\u4f8b\u5982\uff1a<\/p>\n
127.0.0.1:6379> shutdown\n<\/code><\/pre>\n\u7cfb\u7edf\u5e2e\u52a9<\/h2>\n
\u53ef\u4ee5\u57fa\u4e8ehelp\u6307\u4ee4\u67e5\u770b\u76f8\u5173\u6307\u4ee4\u5e2e\u52a9,\u4f8b\u5982<\/p>\n
127.0.0.1:6379><\/span> help<\/span>\nredis-cli 2.8.19\nType: \"help @<group>\"<\/span> to get a list of commands in<\/span> <<\/span>group><\/span>\n \"help <command>\"<\/span> for<\/span> help<\/span> on <<\/span>command><\/span>\n \"help <tab>\"<\/span> to get a list of possible help<\/span> topics\n \"quit\"<\/span> to exit<\/span>\n<\/code><\/pre>\n127.0.0.1:6379><\/span> help<\/span> type<\/span>\n\n TYPE key\n summary: Determine the type<\/span> stored at key\n since: 1.0.0\n group: generic\n<\/code><\/pre>\nRedis\u6570\u636e\u5b58\u50a8\u64cd\u4f5c<\/h1>\n\u7b80\u6613\u6570\u636e\u5b58\u53d6<\/h2>\n\n\u57fa\u4e8e\u67e5\u770bredis\u4e2d\u7684key<\/p>\n<\/blockquote>\n
127.0.0.1:6379><\/span> keys *\n(<\/span>empty list or set)<\/span>\n<\/code><\/pre>\n\n\u57fa\u4e8ekey\/value\u5f62\u5f0f\u5b58\u50a8\u6570\u636e<\/p>\n<\/blockquote>\n
127.0.0.1:6379><\/span> set<\/span> test1 123\nOK\n127.0.0.1:6379><\/span> set<\/span> test2 ab\nOK\n127.0.0.1:6379><\/span> keys *\n1)<\/span> \"test1\"<\/span>\n2)<\/span> \"test2\"<\/span>\n<\/code><\/pre>\n\n\u57fa\u4e8ekey\u83b7\u53d6redis\u4e2d\u5b58\u50a8\u7684\u6570\u636e<\/p>\n<\/blockquote>\n
127.0.0.1:6379><\/span> get test1\n\"123\"<\/span>\n127.0.0.1:6379><\/span> get test2\n\"ab\"<\/span>\n127.0.0.1:6379><\/span> get test3\n(<\/span>nil)<\/span>\n127.0.0.1:6379><\/span>\n<\/code><\/pre>\n\n\u6e05\u9664redis\u4e2d\u7684\u6570\u636e<\/p>\n<\/blockquote>\n
\u5220\u9664\u6307\u5b9akey\u5bf9\u5e94\u7684\u6570\u636e<\/p>\n
127.0.0.1:6379><\/span> del test1 #test1\u4e3akey\u7684\u540d\u5b57<\/span>\nOK\n<\/code><\/pre>\n\u6e05\u9664\u5f53\u524d\u6570\u636e\u5e93\u6570\u636e<\/p>\n
127.0.0.1:6379><\/span> flushdb\nOK\n<\/code><\/pre>\n\u6e05\u9664\u6240\u6709\u6570\u636e\u5e93\u6570\u636e<\/p>\n
127.0.0.1:6379><\/span> flushall\nOK\n<\/code><\/pre>\nKey\u6709\u6548\u65f6\u95f4\u8bbe\u8ba1<\/h2>\n
\u5b9e\u9645\u5de5\u4f5c\u4e2d\u6211\u4eec\u7ecf\u5e38\u8981\u63a7\u5236redis\u4e2dkey\u7684\u6709\u6548\u65f6\u957f\uff0c\u4f8b\u5982\u79d2\u6740\u64cd\u4f5c\u7684\u8ba1\u65f6\uff0c\u7f13\u5b58\u6570\u636e\u7684\u6709\u6548\u65f6\u957f\u7b49\u3002<\/p>\n
\nExpire (\u8bbe\u7f6e\u751f\u6548\u65f6\u957f-\u5355\u4f4d\u79d2)<\/p>\n<\/blockquote>\n
\u8bed\u6cd5\uff1aEXPIRE key seconds<\/p>\n
\n127.0.0.1:6379> set bomb tnt\nOK\n127.0.0.1:6379> expire bomb 10\n(integer) 1\n127.0.0.1:6379> ttl bomb\n(integer) 5\n127.0.0.1:6379> ttl bomb\n(integer) 3\n127.0.0.1:6379> ttl bomb\n(integer) 3\n127.0.0.1:6379> ttl bomb\n(integer) 2\n127.0.0.1:6379> ttl bomb\n(integer) 1\n127.0.0.1:6379> ttl bomb\n(integer) -2\n127.0.0.1:6379> ttl bomb\n(integer) -2\n127.0.0.1:6379>\n<\/code><\/pre>\n\u5176\u4e2d,TTL\u67e5\u770bkey\u7684\u5269\u4f59\u65f6\u95f4\uff0c\u5f53\u8fd4\u56de\u503c\u4e3a-2\u65f6\uff0c\u8868\u793a\u952e\u88ab\u5220\u9664\u3002
\u5f53 key \u4e0d\u5b58\u5728\u65f6\uff0c\u8fd4\u56de -2 \u3002 \u5f53 key \u5b58\u5728\u4f46\u6ca1\u6709\u8bbe\u7f6e\u5269\u4f59\u751f\u5b58\u65f6\u95f4\u65f6\uff0c\u8fd4\u56de -1 \u3002<\/p>\n
\nPersist (\u53d6\u6d88\u65f6\u957f\u8bbe\u7f6e)<\/p>\n<\/blockquote>\n
\u901a\u8fc7persist\u8ba9\u5bf9\u7279\u5b9akey\u8bbe\u7f6e\u7684\u751f\u6548\u65f6\u957f\u5931\u6548\u3002<\/p>\n
\u8bed\u6cd5\uff1aPERSIST key<\/p>\n
127.0.0.1:6379> set bomb tnt\nOK\n127.0.0.1:6379> expire bomb 60\n(integer) 1\n127.0.0.1:6379> ttl bomb\n(integer) 49\n127.0.0.1:6379> persist bomb\n(integer) 1\n127.0.0.1:6379> ttl bomb\n(integer) -1\n127.0.0.1:6379>\n<\/code><\/pre>\n\u5176\u4e2d,\u8bbe\u7f6e\u65b0\u7684\u6570\u636e\u65f6\u9700\u8981\u91cd\u65b0\u8bbe\u7f6e\u8be5key\u7684\u751f\u5b58\u65f6\u95f4\uff0c\u91cd\u65b0\u8bbe\u7f6e\u503c\u4e5f\u4f1a\u6e05\u9664\u751f\u5b58\u65f6\u95f4\u3002<\/p>\n
\npexpire \uff08\u5355\u4f4d\u6beb\u79d2\uff09<\/p>\n<\/blockquote>\n
pexpire \u8ba9key\u7684\u751f\u6548\u65f6\u957f\u4ee5\u6beb\u79d2\u4f5c\u4e3a\u8ba1\u91cf\u5355\u4f4d\uff0c\u8fd9\u6837\u53ef\u4ee5\u505a\u5230\u66f4\u7cbe\u786e\u7684\u65f6\u95f4\u63a7\u5236\u3002\u4f8b\u5982,\u53ef\u5e94\u7528\u4e8e\u79d2\u6740\u573a\u666f\u3002<\/p>\n
\u8bed\u6cd5\uff1aPEXPIRE key milliseconds<\/p>\n
127.0.0.1:6379> set bomb tnt\nOK\n127.0.0.1:6379> pexpire bomb 10000\n(integer) 1\n127.0.0.1:6379> ttl bomb\n(integer) 6\n127.0.0.1:6379> ttl bomb\n(integer) 3\n127.0.0.1:6379> ttl bomb\n(integer) -2\n127.0.0.1:6379>\n<\/code><\/pre>\n\u603b\u7ed3\uff08Summary\uff09<\/h1>\n
\u672c\u7ae0\u8282\u4e3b\u8981\u662f\u8bb2\u89e3\u4e86\u4e00\u4e0bredis\u7684\u4e00\u4e9b\u5165\u95e8\u64cd\u4f5c\uff0c\u4e3b\u8981\u662f\u4e00\u4e9b\u9700\u8981\u8bb0\u4f4f\u7684\u4e00\u4e9b\u6307\u4ee4\uff0c\u5f3a\u5316\u7ec3\u4e60\u5373\u53ef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"01-Redis\u7f13\u5b58\u5165\u95e8\u7b80\u4ecb\u80cc\u666f\u6211\u4eec\u73b0\u5728\u7684\u9879\u76ee\u67b6\u6784\u4e2d\uff0c\u57fa\u672c\u4e0a\u662fWeb\u670d\u52a1\u5668(Tomcat)\u548c\u6570\u636e\u5e93\u72ec\u7acb\u90e8\u7f72\uff0c\u72ec\u5360\u670d\u52a1\u5668\u8d44\u6e90\uff0c\u968f\u7740\u7528\u6237\u6570\u7684...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/657"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=657"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/657\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=657"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=657"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}