
{"id":2991,"date":"2021-01-28T15:08:55","date_gmt":"2021-01-28T07:08:55","guid":{"rendered":"http:\/\/127.0.0.2\/?p=2991"},"modified":"2021-01-30T15:36:14","modified_gmt":"2021-01-30T07:36:14","slug":"2020java%e5%be%ae%e6%9c%8d%e5%8a%a1%e6%9e%b6%e6%9e%84%e5%9b%9b%e4%b9%8bredis%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.9713job.com\/?p=2991","title":{"rendered":"2020java\u5fae\u670d\u52a1\u67b6\u6784\u56db\u4e4bRedis\u6559\u7a0b"},"content":{"rendered":"<h2>2020java\u5fae\u670d\u52a1\u67b6\u6784\u56db\u4e4bRedis\u6559\u7a0b<\/h2>\n<h3>\u4e00\u3001Redis\u4ecb\u7ecd<\/h3>\n<p><strong>1.NoSQL\u4ecb\u7ecd<\/strong><\/p>\n<p>Redis\u5c31\u662f\u4e00\u6b3eNoSQL<br \/>\nNoSQL-&gt;\u975e\u5173\u7cfb\u578b\u6570\u636e\u5e93&#8211;&gt;Not Only SQL<br \/>\nkey-value:Redis<br \/>\n\u6587\u6863\u578b\uff1aElasticSearch,Solr,Mongdb<br \/>\n\u9762\u5411\u5217\uff1aHbase\uff0cCassandra<br \/>\n\u56fe\u5f62\u5316\uff1aNeo4j<br \/>\n\u9664\u4e86\u5173\u7cfb\u578b\u6570\u636e\u5e93\u90fd\u662f\u975e\u5173\u7cfb\u578b\u6570\u636e\u5e93<br \/>\nnoSQL\u53ea\u662f\u4e00\u79cd\u6982\u5ff5\uff0c\u6cdb\u6307\u975e\u5173\u7cfb\u578b\u6570\u636e\u5e93\uff0c\u548c\u5173\u7cfb\u578b\u6570\u636e\u5e93\u505a\u4e00\u4e2a\u533a\u5206<\/p>\n<p><strong>2.Redis\u4ecb\u7ecd<\/strong><\/p>\n<p>\u6709\u4e00\u4f4d\u610f\u5927\u5229\u4eba\uff0c\u5728\u5f00\u53d1\u4e00\u6b3eLLOOGG\u7684\u7edf\u8ba1\u9875\u9762\uff0c\u56e0\u4e3aMySQL\u7684\u6027\u80fd\u4e0d\u597d\uff0c\u81ea\u5df1\u7814\u53d1\u4e86\u4e00\u6b3e\u975e\u5173\u7cfb\u578b\u6570\u636e\u5e93\uff0c\u5e76\u547d\u540d\u4e3aRedis\u3002Salvatore\u3002<!--more--><br \/>\nRedis (Remote Dictionary Server)\u5373\u8fdc\u7a0b\u5b57\u5178\u670d\u52a1\uff0cRedis\u662f\u7531C\u8bed\u8a00\u53bb\u7f16\u5199\uff0cRedis\u662f\u4e00\u6b3e\u57fa\u4e8eKey-Value\u7684NoSQL\uff0c\u800c\u4e14Redis\u662f\u57fa\u4e8e\u5185\u5b58\u5b58\u50a8\u6570\u636e\u7684\uff0cRedis\u8fd8\u63d0\u4f9b\u4e86\u591a\u79cd\u6301\u4e45\u5316\u673a\u5236\uff0c\u6027\u80fd\u53ef\u4ee5\u8fbe\u5230110000\/s\u8bfb\u53d6\u6570\u636e\u4ee5\u53ca81000\/s\u5199\u5165\u6570\u636e\uff0cRedis\u8fd8\u63d0\u4f9b\u4e86\u4e3b\u4ece\uff0c\u54e8\u5175\u4ee5\u53ca\u96c6\u7fa4\u7684\u642d\u5efa\u65b9\u5f0f\uff0c\u53ef\u4ee5\u66f4\u65b9\u4fbf\u7684\u6a2a\u5411\u6269\u5c55\u4ee5\u53ca\u5782\u76f4\u6269\u5c55\u3002<\/p>\n<h3>\u4e8c\u3001Redis\u5b89\u88c5<\/h3>\n<p><strong>1.\u5b89\u88c5Redis<\/strong><\/p>\n<pre>version: '3.1'\r\nservices:\r\n  redis:\r\n    restart: always\r\n    image: daocloud.io\/library\/redis:5.0.7\r\n    container_name: redis\r\n    environment:\r\n      - TZ=Asia\/Shanghai\r\n    ports:\r\n      - 6379:6379\r\n<\/pre>\n<p><strong>2.\u4f7f\u7528redis-cli\u8fde\u63a5Redis<\/strong><\/p>\n<p>\u8fdb\u5165Redis\u5bb9\u5668\u5185\u90e8\uff1adocker exec -it \u6807\u8bc6 bash<br \/>\n\u8fde\u63a5Redis\uff1aredis-cli<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/28\/1.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>3.\u4f7f\u7528\u56fe\u5f62\u5316\u754c\u9762\u8fde\u63a5Redis<\/strong><\/p>\n<p>Redis\u56fe\u5f62\u5316\u7ba1\u7406\uff1a<a href=\"https:\/\/github.com\/lework\/RedisDesktopManager-Windows\/releases\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/github.com\/lework\/RedisDesktopManager-Windows\/releases<\/a><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/28\/2.png\" alt=\"\" width=\"680\" \/><\/p>\n<h3><span style=\"color: #ff0000;\">\u4e09\u3001redis\u5e38\u7528\u547d\u4ee4\u3010\u91cd\u70b9\u3011<\/span><\/h3>\n<p><strong>1.redis\u5b58\u50a8\u6570\u636e\u7684\u7ed3\u6784<\/strong><\/p>\n<p>\u5e38\u7528\u7684\u4e94\u79cd\u6570\u636e\u7ed3\u6784\uff1a<br \/>\n1.key-string: \u4e00\u4e2akey\u5bf9\u5e94\u4e00\u4e2a\u503c<br \/>\n2.key-hash\uff1a\u4e00\u4e2akey\u5bf9\u5e94\u4e00\u4e2amap<br \/>\n3.key-list\uff1a\u4e00\u4e2akey\u5bf9\u5e94\u4e00\u4e2a\u5217\u8868<br \/>\n4.key-set\uff1a\u4e00\u4e2akey\u5bf9\u5e94\u4e00\u4e2a\u96c6\u5408<br \/>\n5.key-zset\uff1a\u4e00\u4e2akey\u5bf9\u5e94\u4e00\u4e2a\u6709\u5e8f\u7684\u96c6\u5408<\/p>\n<p>\u53e6\u5916\u4e09\u79cd\u6570\u636e\u7ed3\u6784\uff1a<br \/>\nHyperLogLog\uff1a\u8ba1\u7b97\u8fd1\u4f3c\u503c<br \/>\nGEO\uff1a\u5730\u7406\u4f4d\u7f6e<br \/>\nBIT\uff1a\u4e00\u822c\u5b58\u50a8\u7684\u4e5f\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5b58\u50a8\u7684\u662f\u4e00\u4e2abyte[]<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/28\/3.png\" alt=\"\" width=\"680\" \/><\/p>\n<p>1.key-string: \u6700\u5e38\u7528\u7684\uff0c\u4e00\u822c\u7528\u4e8e\u5b58\u50a8\u4e00\u4e2a\u503c<br \/>\n2.key-hash\uff1a\u5b58\u50a8\u4e00\u4e2a\u5bf9\u8c61\u6570\u636e\u7684<br \/>\n3.key-list\uff1a\u4f7f\u7528list\u7ed3\u6784\u5b9e\u73b0\u6808\u548c\u961f\u5217\u7ed3\u6784<br \/>\n4.key-set\uff1a\u4ea4\u96c6\uff0c\u5dee\u96c6\u548c\u5e76\u96c6\u7684\u64cd\u4f5c<br \/>\n5.key-zset\uff1a\u6392\u884c\u699c\uff0c\u79ef\u5206\u5b58\u50a8\u7b49\u64cd\u4f5c<\/p>\n<p><strong>2.\u5e38\u7528\u547d\u4ee4<\/strong><\/p>\n<p><strong>2.1 string\u5e38\u7528\u547d\u4ee4<\/strong><\/p>\n<p>1.\u6dfb\u52a0\u503c\uff1aset key value<br \/>\n2.\u53d6\u503c\uff1aget key<br \/>\n3.\u6279\u91cf\u64cd\u4f5c\uff1a<br \/>\nmset key value key value<br \/>\nmget key key<br \/>\n4.\u81ea\u589e\u547d\u4ee4(\u81ea\u589e1)\uff1aincr key<br \/>\n5.\u81ea\u51cf\u547d\u4ee4(\u81ea\u51cf1)\uff1adecr key<br \/>\n6.\u81ea\u589e\u6216\u81ea\u51cf\u6307\u5b9a\u6570\u91cf\uff1a<br \/>\nincrby key increment<br \/>\ndecrby key increment<br \/>\n7.\u8bbe\u7f6e\u503c\u7684\u540c\u65f6\uff0c\u6307\u5b9a\u751f\u5b58\u65f6\u95f4(\u6bcf\u6b21\u5411redis\u4e2d\u6dfb\u52a0\u6570\u636e\u65f6\uff0c\u5c3d\u91cf\u90fd\u8bbe\u7f6e\u751f\u5b58\u65f6\u95f4)<br \/>\nsetex key second value<br \/>\n8.\u8bbe\u7f6e\u503c\uff0c\u5982\u679c\u5f53\u524dkey\u4e0d\u5b58\u5728\u7684\u8bdd\uff0c\u5b58\u50a8\u503c\uff0c\u5426\u5219\u4ec0\u4e48\u4e8b\u4e0d\u505a<br \/>\nsetnx key value<br \/>\n9.\u5728key\u5bf9\u5e94\u7684value\u540e\uff0c\u8ffd\u52a0\u5185\u5bb9<br \/>\nappend key value<br \/>\n10.\u67e5\u770bvalue\u5b57\u7b26\u4e32\u7684\u957f\u5ea6<br \/>\nstrlen key<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/28\/4.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>redis\u6587\u6863\u6559\u7a0b\uff1a<a href=\"http:\/\/redisdoc.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/redisdoc.com\/<\/a><\/strong><\/p>\n<p><strong>2.2 hash\u5e38\u7528\u547d\u4ee4<\/strong><\/p>\n<p>1.\u5b58\u50a8\u6570\u636e\uff1ahset key field value<br \/>\n2.\u83b7\u53d6\u6570\u636e\uff1ahget key field<br \/>\n3.\u6279\u91cf\u64cd\u4f5c\uff1a<br \/>\nhmset key field value field value<br \/>\nhmget key field field<br \/>\n4.\u81ea\u589e\u6570\u636e(\u6307\u5b9a\u81ea\u589e\u7684\u503c)\uff1ahincrby key field increment<br \/>\n5.\u8bbe\u7f6e\u503c\uff0c\u5982\u679ckey-field\u4e0d\u5b58\u5728\u5219\u5b58\u50a8\uff0c\u5426\u5219\u4ec0\u4e48\u4e8b\u90fd\u4e0d\u505a<br \/>\nhsetnx key field value<br \/>\n6.\u68c0\u67e5field\u662f\u5426\u5b58\u5728\uff1ahexists key field<br \/>\n7.\u5220\u9664key\u5bf9\u5e94\u7684field\uff0c\u53ef\u4ee5\u5220\u9664\u591a\u4e2a<br \/>\nhdel key field field<br \/>\n8.\u83b7\u53d6\u5f53\u524dhash\u7ed3\u6784\u4e2d\u7684\u5168\u90e8field\u548cvalue<br \/>\nhgetall key<br \/>\n9.\u83b7\u53d6\u5f53\u524dhash\u7ed3\u6784\u4e2d\u7684\u5168\u90e8field\uff1ahkeys key<br \/>\n10.\u83b7\u53d6\u5f53\u524dhash\u7ed3\u6784\u4e2d\u7684\u5168\u90e8value\uff1ahvals key<br \/>\n11.\u83b7\u53d6\u5f53\u524dhash\u7ed3\u6784\u4e2dfield\u7684\u6570\u91cf\uff1ahlen key<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/28\/5.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>2.3 list\u5e38\u7528\u547d\u4ee4<\/strong><\/p>\n<p>1.\u5b58\u50a8\u6570\u636e(\u6279\u91cf)\uff1a<br \/>\n\u5de6\u4fa7\u63d2\u5165\uff1alpush key value<br \/>\n\u53f3\u4fa7\u63d2\u5165\uff1arpush key value<\/p>\n<p>2.\u5b58\u50a8\u6570\u636e(\u5355\u4e2a)<br \/>\nlpushx key value \/ rpush key value<\/p>\n<p>3.\u4fee\u6539\u6570\u636e(\u8986\u76d6\u6307\u5b9a\u4f4d\u7f6e\u7684\u6570\u636e)<br \/>\nlset key index value<\/p>\n<p>4.\u5f39\u6808\u65b9\u5f0f\u83b7\u53d6\u6570\u636e(\u5f39\u51fa\u540e\u5220\u9664\u6570\u636e)<br \/>\nlpop key \/ rpop key<\/p>\n<p>5.\u83b7\u53d6\u6307\u5b9a\u7d22\u5f15\u8303\u56f4\u7684\u6570\u636e(start \u4ece 0\u5f00\u59cb\uff0cstop\u8f93\u5165-1\u4ee3\u8868\u6700\u540e\u4e00\u4e2a\uff0c-2\u4ee3\u8868\u5012\u6570\u7b2c\u4e8c\u4e2a)<br \/>\nlrange key start stop<\/p>\n<p>6.\u83b7\u53d6\u6307\u5b9a\u7d22\u5f15\u4f4d\u7f6e\u7684\u4f4d\u7f6e<br \/>\nlindex key index<\/p>\n<p>7.\u83b7\u53d6\u6574\u4e2a\u5217\u8868\u7684\u957f\u5ea6<br \/>\nllen key<\/p>\n<p>8.\u5220\u9664\u5217\u8868\u4e2d\u7684\u6570\u636e\uff0c\u5220\u9664\u5f53\u524d\u8868\u4e2d\u7684count\u4e2avalue\u503c\uff0ccount&gt;0\u4ece\u5de6\u4fa7\u5411\u53f3\u4fa7\u5220\u9664\uff0c&lt;0\u4ece\u53f3\u5411\u5de6\u5220\u9664\uff0c==0\u5220\u9664\u5217\u8868\u4e2d\u5168\u90e8\u7684value<br \/>\nlrem key count value<\/p>\n<p>9.\u4fdd\u7559\u5217\u8868\u4e2d\u7684\u6570\u636e(\u4fdd\u7559\u4f60\u6307\u5b9a\u7d22\u5f15\u8303\u56f4\u5185\u7684\u6570\u636e\uff0c\u8d85\u8fc7\u6574\u4e2a\u7d22\u5f15\u8303\u56f4\u88ab\u79fb\u9664\u6389)<br \/>\nltrim key start stop<\/p>\n<p>10.\u5c06\u4e00\u4e2a\u5217\u8868\u4e2d\u6700\u540e\u4e00\u4e2a\u503c\uff0c\u63d2\u5165\u5230\u53e6\u5916\u4e00\u4e2a\u5217\u8868\u7684\u5934\u90e8\u4f4d\u7f6e<br \/>\nrpoplpush list1 list2<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/28\/6.png\" alt=\"\" width=\"680\" \/><br \/>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/28\/7.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>2.4 set\u5e38\u7528\u547d\u4ee4<\/strong><\/p>\n<p>1.\u5b58\u50a8\u6570\u636e\uff1asadd key member<\/p>\n<p>2.\u83b7\u53d6\u6570\u636e\uff1asmembers key<\/p>\n<p>3.\u968f\u673a\u83b7\u53d6\u4e00\u4e2a\u6570\u636e\uff1aspop key count<\/p>\n<p>4.\u4ea4\u96c6\uff0c\u53d6\u591a\u4e2aset\u96c6\u5408\u4ea4\u96c6\uff1asinter set1 set2<\/p>\n<p>5.\u5e76\u96c6\uff0c\u83b7\u53d6\u5168\u90e8\u96c6\u5408\u4e2d \u7684\u6570\u636e\uff1asunion set1 set2<\/p>\n<p>6.\u5dee\u96c6\uff0c\u83b7\u53d6\u591a\u4e2a\u96c6\u5408\u4e2d\u4e0d\u4e00\u6837\u7684\u6570\u636e\uff1asdiff set1 set2<\/p>\n<p>7.\u5220\u9664\u6570\u636e\uff1asrem key member<\/p>\n<p>8.\u67e5\u770b\u5f53\u524d\u7684set\u96c6\u5408\u4e2d\u662f\u5426\u5305\u542b\u8fd9\u4e2a\u503c\uff1asismember key member<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/28\/8.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>2.5 zset\u7684\u5e38\u7528\u547d\u4ee4<\/strong><\/p>\n<p>1.\u6dfb\u52a0\u6570\u636e(score\u5fc5\u987b\u662f\u6570\u503c\uff0cmember\u4e0d\u80fd\u91cd\u590d)<br \/>\nzadd key score memeber score member<\/p>\n<p>2.\u4fee\u6539member\u7684\u5206\u6570(\u5982\u679cmember\u5b58\u5728\u5219\u6b63\u5e38\u589e\u52a0\uff0c\u5426\u5219\u6dfb\u52a0\u6570\u636ezadd)<br \/>\nzincrby key increment member<\/p>\n<p>3.\u67e5\u770b\u6307\u5b9a\u7684member\u7684\u5206\u6570<br \/>\nzscore key member<\/p>\n<p>4.\u83b7\u53d6zset\u4e2d\u6570\u636e\u7684\u6570\u91cf<br \/>\nzcard key<\/p>\n<p>5.\u6839\u636escore\u7684\u8303\u56f4\u67e5\u8be2member\u6570\u91cf<br \/>\nzcount key min max<\/p>\n<p>6.\u5220\u9664zset\u4e2d\u7684\u6210\u5458<br \/>\nzrem key member<\/p>\n<p>#7.\u6839\u636e\u5206\u6570\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\uff0c\u83b7\u53d6\u6307\u5b9a\u8303\u56f4\u5185\u7684\u6570\u636e(withscores\u5982\u679c\u6dfb\u52a0\u8fd9\u4e2a\u53c2\u6570\uff0c\u90a3\u4e48\u4f1a\u8fd4\u56demember\u5bf9\u5e94\u7684\u5206\u6570)<br \/>\nzrange key start stop [withscores]<\/p>\n<p>#8\u3001\u6839\u636e\u5206\u6570\u4ece\u5927\u5230\u5c0f\u6392\u5e8f\u3002\u83b7\u53d6\u6307\u5b9a\u8303\u56f4\u5185\u7684\u6570\u636e(withscores\u5982\u679c\u6dfb\u52a0\u8fd9\u4e2a\u53c2\u6570\uff0c\u90a3\u4e48\u4f1a\u8fd4\u56demember\u5bf9\u5e94\u7684\u5206\u6570)<br \/>\nzrevrange key start stop [withscores]<\/p>\n<p>#9\u3001\u6839\u636e\u5206\u6570\u7684\u8303\u56f4\u53bb\u83b7\u53d6member(withscores\u4ee3\u8868\u540c\u65f6\u8fd4\u53e5score\uff0c\u6dfb\u52a0limit\uff0c\u5c31\u548cMySQL\u4e2d\u4e00\u6837\u3001\u5982\u679c\u4e0d\u5e0c\u671b\u7b49\u4e8emin\u6216\u8005max\u7684\u503c\u88ab\u67e5\u8be2\u51fa\u6765\u53ef\u4ee5\u89c1\u7528\u2018(\u5206\u6570\u2019\u76f8\u5f53\u4e8e&lt;\u4f46\u662f\u4e0d\u7b49\u4e8e\u7684\u65b9\u5f0f\uff0c\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u4f7f\u7528+inf\u548c-inf\u6765\u8868\u793a)<br \/>\nzrangebyscore key min max [withscores] [limit offset count]<\/p>\n<p>#10.\u6839\u636e\u5206\u6570\u7684\u8303\u56f4\u53bb\u83b7\u53d6member(withscores\u4ee3\u8868\u540c\u65f6\u8fd4\u56descore\uff0c\u6dfb\u52a0limit\uff0c\u5c31\u548cMySQL\u4e2d\u4e00\u6837)<br \/>\nzrangebyscore key max min[withscores][limit offset count]<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/28\/9.png\" alt=\"\" width=\"680\" \/><br \/>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/28\/10.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>2.6 key\u5e38\u7528\u6307\u4ee4<\/strong><\/p>\n<p>1.\u67e5\u770bredis\u4e2d\u7684\u5168\u90e8key(pattern:*,xxx*,*xxx)<br \/>\nkeys pattern<\/p>\n<p>2.\u67e5\u770b\u67d0\u4e00\u4e2akey\u662f\u5426\u5b58\u5728(1\uff1akey\u5b58\u5728\u30020\uff1akey\u4e0d\u5b58\u5728)<br \/>\nexists key<\/p>\n<p>3.\u5220\u9664key\uff1adel key<\/p>\n<p>4.\u8bbe\u7f6ekey\u7684\u751f\u5b58\u65f6\u95f4\uff0c\u5355\u4f4d\u4e3a\u79d2\/\u6beb\u79d2<br \/>\nexpire key second \/ pexpire key milliseconds<\/p>\n<p>5.\u8bbe\u7f6ekey\u7684\u751f\u5b58\u65f6\u95f4\uff0c\u5355\u4f4d\u4e3a\u79d2\/\u6beb\u79d2\uff0c\u8bbe\u7f6e\u80fd\u6d3b\u5230\u4ec0\u4e48\u65f6\u95f4<br \/>\nexpire key timestamp \/ pexpire key milliseconds<\/p>\n<p>6.\u67e5\u770bkey\u7684\u5269\u4f59\u65f6\u95f4\uff0c\u5355\u4f4d\u4e3a\u79d2\/\u6beb\u79d2<br \/>\n\u8fd4\u56de\u503c\uff1a<br \/>\n-2\uff1a\u5f53\u524dkey\u4e0d\u5b58\u5728<br \/>\n-1\uff1a\u5f53\u524dkey\u6ca1\u6709\u8bbe\u7f6e\u751f\u5b58\u65f6\u95f4\uff0c\u5177\u4f53\u5269\u4f59\u7684\u751f\u5b58\u65f6\u95f4<br \/>\nttl key \/ pttl key<\/p>\n<p>7.\u79fb\u9664key\u7684\u751f\u5b58\u65f6\u95f4<br \/>\n1\uff1a\u79fb\u9664\u6210\u529f\uff1b0\uff1akey\u4e0d\u5b58\u5728\u751f\u5b58\u65f6\u95f4\/key\u4e0d\u5b58\u5728<br \/>\npersist key<\/p>\n<p>8.\u9009\u62e9\u5e93\uff1aselect 0~15<\/p>\n<p>9.\u79fb\u52a8key\u5230\u53e6\u5916\u4e00\u4e2a\u5e93\u4e2d\uff1amove key db<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/28\/11.png\" alt=\"\" width=\"680\" \/><br \/>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/28\/12.png\" alt=\"\" width=\"680\" \/><br \/>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/28\/13.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>2.7 \u5e93\u7684\u5e38\u7528\u547d\u4ee4<\/strong><\/p>\n<p>1.\u6e05\u7a7a\u5f53\u524d\u6240\u5728\u7684\u6570\u636e\u5e93\uff1aflushdb<\/p>\n<p>2.\u6e05\u7a7a\u6240\u6709\u7684\u6570\u636e\u5e93\uff1aflushall<\/p>\n<p>3.\u67e5\u770b\u5f53\u524d\u6240\u5728\u7684\u5e93\u6709\u591a\u5c11\u4e2akey\uff1adbsize<\/p>\n<p>4.\u67e5\u770b\u6700\u540e\u4e00\u6b21\u64cd\u4f5c\u7684\u65f6\u95f4\uff1alastsave<\/p>\n<p>5.\u5b9e\u65f6\u76d1\u63a7Redis\u670d\u52a1\u63a5\u6536\u5230\u7684\u547d\u4ee4(\u9700\u65b0\u5efasession\u4f1a\u8bdd)\uff1amonitor<\/p>\n<h3><span style=\"color: #ff0000;\">\u56db\u3001java\u8fde\u63a5Redis\u3010\u91cd\u70b9\u3011<\/span><\/h3>\n<p><strong>1.jedis\u8fde\u63a5redis<\/strong><\/p>\n<p><strong>1.1\u5bfc\u5165\u4f9d\u8d56\uff1alombok\uff0cjunit\uff0cjedis<\/strong><\/p>\n<pre>  &lt;dependency&gt;\r\n    &lt;groupId&gt;org.projectlombok&lt;\/groupId&gt;\r\n    &lt;artifactId&gt;lombok&lt;\/artifactId&gt;\r\n    &lt;version&gt;1.18.4&lt;\/version&gt;\r\n  &lt;\/dependency&gt;\r\n  &lt;dependency&gt;\r\n    &lt;groupId&gt;junit&lt;\/groupId&gt;\r\n    &lt;artifactId&gt;junit&lt;\/artifactId&gt;\r\n    &lt;version&gt;4.12&lt;\/version&gt;\r\n    &lt;scope&gt;test&lt;\/scope&gt;\r\n  &lt;\/dependency&gt;\r\n  &lt;dependency&gt;\r\n    &lt;groupId&gt;redis.clients&lt;\/groupId&gt;\r\n    &lt;artifactId&gt;jedis&lt;\/artifactId&gt;\r\n    &lt;version&gt;2.9.0&lt;\/version&gt;\r\n  &lt;\/dependency&gt;<\/pre>\n<p><strong>1.2 \u6d4b\u8bd5<\/strong><\/p>\n<pre>public class Demo1 {\r\n    @Test\r\n    public void set(){\r\n        \/\/1.\u8fde\u63a5 Redis\r\n        Jedis jedis=new Jedis(\"192.168.2.123\",6379);\r\n        \/\/2.\u64cd\u4f5c Redis--redis\u547d\u4ee4\u662f\u4ec0\u4e48\uff0cJedis \u547d\u4ee4\u5c31\u662f\u4ec0\u4e48\r\n        jedis.set(\"name\",\"\u674e\u56db\");\r\n        \/\/3.\u91ca\u653e\u8d44\u6e90\r\n        jedis.close();\r\n    }\r\n    @Test\r\n    public void get(){\r\n        \/\/1.\u8fde\u63a5 Redis\r\n        Jedis jedis=new Jedis(\"192.168.2.123\",6379);\r\n        \/\/2.\u64cd\u4f5c Redis--redis\u547d\u4ee4\u662f\u4ec0\u4e48\uff0cJedis \u547d\u4ee4\u5c31\u662f\u4ec0\u4e48\r\n        String name = jedis.get(\"name\");\r\n        System.out.println(name);\r\n        \/\/3.\u91ca\u653e\u8d44\u6e90\r\n        jedis.close();\r\n    }\r\n}<\/pre>\n<p><strong>2. jedis\u5b58\u50a8\u4e00\u4e2a\u5bf9\u8c61\u5230redis\u4ee5byte[]\u7684\u5f62\u5f0f<\/strong><\/p>\n<p><strong>2.1 \u521b\u5efa\u4e00\u4e2a\u5b9e\u4f53\u7c7b\u5e76\u4e14\u5b9e\u73b0Serializable\u63a5\u53e3<\/strong><\/p>\n<p><strong>2.3 \u5bfc\u5165spring-content\u4f9d\u8d56<\/strong><\/p>\n<p><strong>2.4\u7f16\u5199\u6d4b\u8bd5\u7c7b<\/strong><\/p>\n<pre>public class Demo2 {\r\n    \/\/\u5b58\u50a8\u5bf9\u8c61\uff0c\u4ee5byte[] \u5f62\u5f0f\u5b58\u50a8\u5728redis\u4e2d\r\n    @Test\r\n    public void setByteArray(){\r\n        \/\/1.\u8fde\u63a5 Redis\r\n        Jedis jedis=new Jedis(\"192.168.2.123\",6379);\r\n        \/\/2.1 \u51c6\u5907key(Sring)--&gt;value(User)\r\n        String key=\"user\";\r\n        User user=new User(1,\"\u5f20\u4e09\",\"\u7537\",new Date(),5000.2);\r\n        byte[] byteKey = SerializationUtils.serialize(key);\r\n        byte[] byteValue = SerializationUtils.serialize(user);\r\n        jedis.set(byteKey,byteValue);\r\n        \/\/3.\u91ca\u653e\u8d44\u6e90\r\n        jedis.close();\r\n    }\r\n    @Test\r\n    public void getByteArray(){\r\n        \/\/1.\u8fde\u63a5 Redis\r\n        Jedis jedis=new Jedis(\"192.168.2.123\",6379);\r\n        \/\/2.1 \u51c6\u5907key\r\n        String key=\"user\";\r\n        byte[] byteKey = SerializationUtils.serialize(key);\r\n        byte[] bytesValue = jedis.get(byteKey);\r\n        User user = (User) SerializationUtils.deserialize(bytesValue);\r\n        System.out.println(\"user:\" + user);\r\n        \/\/3.\u91ca\u653e\u8d44\u6e90\r\n        jedis.close();\r\n    }\r\n}<\/pre>\n<p><strong>3. jedis\u5b58\u50a8\u4e00\u4e2a\u5bf9\u8c61\u5230redis\u4ee5String\u5f62\u5f0f<\/strong><\/p>\n<p><strong>3.1 \u5bfc\u5165\u4f9d\u8d56 fastjson<\/strong><\/p>\n<p><strong>3.2\u00a0 \u6d4b\u8bd5<\/strong><\/p>\n<pre>public class Demo3 {\r\n    \/\/\u5b58\u50a8\u5bf9\u8c61-\u4ee5String\u5f62\u5f0f\u5b58\u50a8\r\n    @Test\r\n    public void setString(){\r\n        \/\/1.\u8fde\u63a5 Redis\r\n        Jedis jedis=new Jedis(\"192.168.2.123\",6379);\r\n        \/\/2.1 \u51c6\u5907key(String)--&gt;value(User)\r\n        String stringKey=\"stringUser\";\r\n        User value=new User(2,\"admin2\",\"\u5973\",new Date(),6666.66);\r\n        \/\/2.2 \u4f7f\u7528 fastJson \u5c06 value \u8f6c\u5316\u4e3a json\u5b57\u7b26\u4e32\r\n        String stringValue = JSON.toJSONString(value);\r\n        \/\/2.3 \u5b58\u50a8\u5230 redis \u4e2d\r\n        jedis.set(stringKey,stringValue);\r\n        \/\/3.\u91ca\u653e\u8d44\u6e90\r\n        jedis.close();\r\n    }\r\n    \/\/\u83b7\u53d6\u5bf9\u8c61-\u4ee5String\u5f62\u5f0f\u83b7\u53d6\r\n    @Test\r\n    public void getString(){\r\n        \/\/1.\u8fde\u63a5 Redis\r\n        Jedis jedis=new Jedis(\"192.168.2.123\",6379);\r\n        \/\/2.1 \u51c6\u5907key(String)--&gt;value(User)\r\n        String stringKey=\"stringUser\";\r\n        \/\/2.2 \u53bbredis\u4e2d\u67e5\u8be2value\r\n        String value = jedis.get(stringKey);\r\n        \/\/2.3 \u5c06value\u53cd\u5e8f\u5217\u5316\u4e3aUser\r\n        User user = JSON.parseObject(value,User.class);\r\n        \/\/2.4 \u8f93\u51fa\r\n        System.out.println(\"user:\" + user);\r\n        \/\/3.\u91ca\u653e\u8d44\u6e90\r\n        jedis.close();\r\n    }\r\n}<\/pre>\n<p><strong>4. jedis \u8fde\u63a5\u6c60\u7684\u64cd\u4f5c<\/strong><\/p>\n<p><strong>\u4f7f\u7528\u8fde\u63a5\u6c60\u64cd\u4f5credis\uff0c\u907f\u514d\u9891\u7e41\u521b\u5efa\u548c\u9500\u6bc1\u8fde\u63a5\u5bf9\u8c61\u6d88\u8017\u8d44\u6e90<\/strong><\/p>\n<pre>public class Demo4 {\r\n    @Test\r\n    public void pool(){\r\n        \/\/1. \u521b\u5efa\u8fde\u63a5\u6c60\u914d\u7f6e\u4fe1\u606f\r\n        GenericObjectPoolConfig pc=new GenericObjectPoolConfig();\r\n        pc.setMaxTotal(100);\/\/\u8fde\u63a5\u6c60\u4e2d\u6700\u5927\u7684\u6d3b\u8dc3\u6570\r\n        pc.setMaxIdle(10);\/\/\u6700\u5927\u7a7a\u95f2\u6570\r\n        pc.setMinIdle(5);\/\/\u6700\u5c0f\u7a7a\u95f2\u6570\r\n        pc.setMaxWaitMillis(3000);\/\/\u5f53\u8fde\u63a5\u6c60\u7a7a\u4e86\u4ee5\u540e\uff0c\u591a\u4e45\u6ca1\u83b7\u5f97\u5230jedis\u5bf9\u8c61\uff0c\u5c31\u8d85\u65f6\r\n        \/\/2. \u521b\u5efa\u8fde\u63a5\u6c60\r\n        JedisPool jp=new JedisPool(\"192.168.2.123\",6379);\r\n        \/\/3. \u901a\u8fc7\u8fde\u63a5\u6c60\u83b7\u53d6 jedis \u5bf9\u8c61\r\n        Jedis jedis = jp.getResource();\r\n        \/\/4. \u64cd\u4f5c\r\n        String value = jedis.get(\"stringUser\");\r\n        System.out.println(\"User:\" + value);\r\n        jp.close();\r\n    }\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>5. Redis \u7ba1\u9053\u7684\u64cd\u4f5c<\/strong><\/p>\n<p>\u56e0\u4e3a\u5728\u64cd\u4f5cRedis\u7684\u65f6\u5019\uff0c\u6267\u884c\u4e00\u4e2a\u547d\u4ee4\u9700\u8981\u5148\u53d1\u9001\u8bf7\u6c42\u5230Redis\u670d\u52a1\u5668\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u9700\u8981\u7ecf\u5386\u7f51\u7edc\u7684\u5ef6\u8fdf\uff0cRedis\u8fd8\u9700\u8981\u7ed9\u5ba2\u6237\u7aef\u4e00\u4e2a\u54cd\u5e94\u3002<br \/>\n\u5982\u679c\u6211\u9700\u8981\u4e00\u6b21\u6027\u6267\u884c\u5f88\u591a\u4e2a\u547d\u4ee4\uff0c\u4e0a\u8ff0\u7684\u65b9\u5f0f\u6548\u7387\u5f88\u4f4e\uff0c\u53ef\u4ee5\u901a\u8fc7Redis\u7684\u7ba1\u9053\uff0c\u5148\u5c06\u547d\u4ee4\u653e\u5230\u5ba2\u6237\u7aef\u7684\u4e00\u4e2aPipeline\u4e2d\uff0c\u4e4b\u540e\u4e00\u6b21\u6027\u7684\u5c06\u5168\u90e8\u547d\u4ee4\u90fd\u53d1\u9001\u5230Redis\u670d\u52a1\uff0cRedis\u670d\u52a1\u4e00\u6b21\u6027\u7684\u5c06\u5168\u90e8\u7684\u8fd4\u56de\u7ed3\u679c\u54cd\u5e94\u7ed9\u5ba2\u6237\u7aef\u3002<\/p>\n<pre>public class Demo5 {\r\n    @Test\r\n    public void pipeline(){\r\n        \/\/1. \u521b\u5efa\u8fde\u63a5\u6c60\r\n        JedisPool pool=new JedisPool(\"192.168.2.123\",6379);\r\n        long l=System.currentTimeMillis();\r\n        \/\/2. \u83b7\u53d6\u4e00\u4e2a\u8fde\u63a5\u5bf9\u8c61\r\n        Jedis jedis = pool.getResource();\r\n        \/\/3. \u521b\u5efa\u7ba1\u9053\r\n        Pipeline pipelined = jedis.pipelined();\r\n        \/\/3.1 \u6267\u884cincr - 100000\u6b21\u653e\u5230\u7ba1\u9053\u4e2d\r\n        for(int i=0;i&lt;100000;i++){\r\n            pipelined.incr(\"qq\");\r\n        }\r\n        \/\/4. \u6267\u884c\u547d\u4ee4\r\n        pipelined.syncAndReturnAll();\r\n        \/\/5. \u91ca\u653e\u8d44\u6e90\r\n        jedis.close();\r\n        System.out.println(System.currentTimeMillis()-l);\r\n    }\r\n}<\/pre>\n<h3>\u4e94\u3001 Redis\u5176\u4ed6\u914d\u7f6e\u53ca\u96c6\u7fa4<\/h3>\n<p><strong>\u4fee\u6539yml\u6587\u4ef6\uff0c\u4ee5\u65b9\u4fbf\u540e\u671f\u4fee\u6539redis\u914d\u7f6e\u4fe1\u606f<\/strong><\/p>\n<pre>version: '3.1'\r\nservices:\r\n  redis:\r\n    restart: always\r\n    image: daocloud.io\/library\/redis:5.0.7\r\n    container_name: redis\r\n    environment:\r\n      - TZ=Asia\/Shanghai\r\n    ports:\r\n      - 6379:6379\r\n    <strong>volumes:<\/strong>\r\n<strong>      - .\/conf\/redis.conf:\/user\/local\/redis\/redis.conf<\/strong>\r\n<strong>    command:  [\"redis-server\",\"\/user\/local\/redis\/redis.conf\"]<\/strong>\r\n<\/pre>\n<p>\u6267\u884c\uff1adocker-compose down<br \/>\n\u6267\u884c\uff1adocker-compose up -d<\/p>\n<p><strong>5.1 Redis\u7684AUTH<\/strong><\/p>\n<p>\u4fee\u6539\u6587\u4ef6\uff1aredis.conf<\/p>\n<pre># Redis\u7684AUTH\u5bc6\u7801\r\nrequirepass redis\r\n<\/pre>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/29\/1.png\" alt=\"\" width=\"680\" \/><\/p>\n<p>\u7136\u540e\u5728idea\u4e2d\u4fee\u6539\u6d4b\u8bd5\u4ee3\u7801<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/29\/2.png\" alt=\"\" width=\"680\" \/><br \/>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/29\/3.png\" alt=\"\" width=\"680\" \/><\/p>\n<p>redis\u8bbe\u7f6e\u5bc6\u7801\uff1aconfig set requirepass password<\/p>\n<p>\u8f93\u5165\u5bc6\u7801\uff1aauth password<\/p>\n<p>idea\u5728\u8fde\u63a5\u6c60\u914d\u7f6e\u65b9\u6cd5\u6dfb\u52a0\u5bc6\u7801\u4ee5\u53ca\u8d85\u65f6\u65f6\u95f4<\/p>\n<pre>public class Demo6 {\r\n    @Test\r\n    public void auth(){\r\n        \/\/1. \u521b\u5efa\u8fde\u63a5\u6c60\u914d\u7f6e\u4fe1\u606f\r\n        GenericObjectPoolConfig pc=new GenericObjectPoolConfig();\r\n        pc.setMaxTotal(100);\/\/\u8fde\u63a5\u6c60\u4e2d\u6700\u5927\u7684\u6d3b\u8dc3\u6570\r\n        pc.setMaxIdle(10);\/\/\u6700\u5927\u7a7a\u95f2\u6570\r\n        pc.setMinIdle(5);\/\/\u6700\u5c0f\u7a7a\u95f2\u6570\r\n        pc.setMaxWaitMillis(3000);\/\/\u5f53\u8fde\u63a5\u6c60\u7a7a\u4e86\u4ee5\u540e\uff0c\u591a\u4e45\u6ca1\u83b7\u5f97\u5230jedis\u5bf9\u8c61\uff0c\u5c31\u8d85\u65f6\r\n        \/\/2. \u521b\u5efa\u8fde\u63a5\u6c60\r\n        JedisPool jp=new JedisPool(pc,\"192.168.2.123\",6379,3000,\"redis\");\r\n        Jedis jedis = jp.getResource();\r\n        jedis.set(\"name\", \"admin888\");\r\n        jedis.close();\r\n    }\r\n}<\/pre>\n<p><strong>5.2 Redis\u7684\u4e8b\u52a1<\/strong><\/p>\n<p>Redis\u7684\u4e8b\u52a1\uff1a\u4e00\u6b21\u4e8b\u52a1\u64cd\u4f5c\uff0c\u6539\u6210\u529f\u7684\u6210\u529f\uff0c\u8be5\u5931\u8d25\u7684\u5931\u8d25\u3002<br \/>\n\u5148\u5f00\u542f\u4e8b\u52a1\uff0c\u6267\u884c\u4e00\u4e9b\u5217\u7684\u547d\u4ee4\uff0c\u4f46\u662f\u5bc6\u7801\u4e0d\u4f1a\u7acb\u5373\u6267\u884c\uff0c\u4f1a\u88ab\u653e\u5728\u4e00\u4e2a\u961f\u5217\u4e2d\uff0c\u5982\u679c\u4f60\u6267\u884c\u4e8b\u52a1\uff0c\u90a3\u4e48\u8fd9\u4e2a\u961f\u5217\u4e2d\u7684\u547d\u4ee4\u5168\u90e8\u6267\u884c\uff0c\u5982\u679c\u53d6\u6d88\u4e86\u4e8b\u52a1\uff0c\u4e00\u4e2a\u961f\u5217\u4e2d\u7684\u547d\u4ee4\u5168\u90e8\u4f5c\u5e9f\u3002<br \/>\n1.\u5f00\u542f\u4e8b\u52a1\uff1amulti<br \/>\n2. \u8f93\u5165\u8981\u6267\u884c\u7684\u547d\u4ee4\uff1a\u88ab\u653e\u5165\u5230\u4e00\u4e2a\u961f\u5217\u4e2d<br \/>\n3. \u6267\u884c\u4e8b\u52a1\uff1aexec<br \/>\n4. \u53d6\u6d88\u4e8b\u52a1\uff1adiscard<br \/>\nRedis\u7684\u4e8b\u52a1\u60f3\u53d1\u6325\u529f\u80fd\uff0c\u9700\u8981\u914d\u7f6ewatch\u76d1\u542c\u673a\u5236<br \/>\n\u5728\u5f00\u542f\u4e8b\u52a1\u4e4b\u524d\uff0c\u5148\u901a\u8fc7watch\u547d\u4ee4\u53bb\u76d1\u542c\u4e00\u4e2a\u6216\u591a\u4e2akey\uff0c\u5728\u5f00\u542f\u4e8b\u52a1\u4e4b\u540e\uff0c\u5982\u679c\u6709\u5176\u4ed6\u5ba2\u6237\u7aef\u4fee\u6539\u4e86\u6211\u76d1\u542c\u7684key\uff0c\u4e8b\u52a1\u4f1a\u81ea\u52a8\u53d6\u6d88\u3002 I<br \/>\n\u5982\u679c\u6267\u884c\u4e86\u4e8b\u52a1\uff0c\u6216\u8005\u53d6\u6d88\u4e86\u4e8b\u52a1\uff0cwatch\u76d1\u542c\u81ea\u52a8\u6d88\u9664\uff0c\u4e00\u822c\u4e0d\u9700\u8981\u624b\u52a8\u6267\u884cunwatch\u3002<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/29\/4.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>5.3 Redis\u6301\u4e45\u5316<\/strong><\/p>\n<p>RDB\u662fRedis\u9ed8\u8ba4\u7684\u6301\u4e45\u5316\u673a\u5236\uff1a<\/p>\n<p>1.RDB\u6301\u4e45\u5316\u6587\u4ef6\uff0c\u901f\u5ea6\u6bd4\u8f83\u5feb\uff0c\u800c\u4e14\u5b58\u50a8\u7684\u662f\u4e00\u4e2a\u4e8c\u8fdb\u5236\u7684\u6587\u4ef6\uff0c\u4f20\u8f93\u8d77\u6765\u5f88\u65b9\u4fbf\u3002<\/p>\n<p>2.RDB\u6301\u4e45\u5316\u65f6\u673a\uff1a<\/p>\n<p>save 900 1 \uff1a900\u79d2\u4e4b\u5185\uff0c\u67091\u4e2akey\u6539\u53d8\u5c31\u6267\u884cRDB\u6301\u4e45\u5316<br \/>\nsave 300 10 \uff1a300\u79d2\u4e4b\u5185\uff0c\u670910\u4e2akey\u6539\u53d8\u5c31\u6267\u884cRDB\u6301\u4e45\u5316<br \/>\nsave 60 10000 \uff1a60\u79d2\u4e4b\u5185\uff0c\u6709\u4e00\u4e07\u4e2akey\u6539\u53d8\u5c31\u6267\u884cRDB\u6301\u4e45\u5316<\/p>\n<p>3.RDB\u65e0\u6cd5\u4fdd\u8bc1\u6570\u636e\u7684\u7edd\u5bf9\u5b89\u5168<\/p>\n<p>\u5728redis\u6587\u4ef6\u5939\u4e0b\u6253\u5f00redis.conf\u6587\u4ef6\uff0c\u641c\u7d22RDB\uff0c\u590d\u5236<\/p>\n<p>save 900 1<br \/>\nsave 300 10<br \/>\nsave 60 10000<\/p>\n<p>rdbcompression yes<\/p>\n<p>dbfilename dump.rdb<\/p>\n<p>\u7136\u540e\u5728Linux\u4fee\u6539redis.conf\u6587\u4ef6<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/29\/5.png\" alt=\"\" width=\"680\" \/><\/p>\n<p>\u4fee\u6539docker-compose.yml\u6587\u4ef6<\/p>\n<p>\u6dfb\u52a0\u6570\u636e\u5377\uff1a.\/data:\/data<\/p>\n<p>\u7136\u540e\u6267\u884c\uff1adocker-compose down \u3001docker-compose up -d<\/p>\n<p>\u7136\u540e\u5728\u914d\u7f6e\u6587\u4ef6\u67e5\u627e AOF\uff0c\u7136\u540e\u590d\u5236<\/p>\n<p>appendonly no<\/p>\n<p>appendfilename &#8220;appendonly.aof&#8221;<\/p>\n<p># appendfsync always<br \/>\nappendfsync everysec<br \/>\n# appendfsync no<\/p>\n<p>\u4fee\u6539\u914d\u7f6e\u6587\u4ef6 redis.conf<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/29\/6.png\" alt=\"\" width=\"680\" \/><\/p>\n<p>\u7136\u540e\u91cd\u542f\uff1adocker-compose restart<\/p>\n<p>AOF\u6301\u4e45\u5316\u673a\u5236\u9ed8\u8ba4\u662f\u5173\u95ed\u7684\uff0cRedis\u5b98\u65b9\u63a8\u8350\u540c\u65f6\u5f00\u542fRDB\u548cAOF\u6301\u4e45\u5316\uff0c\u66f4\u5b89\u5168\uff0c\u907f\u514d\u6570\u636e\u4e22\u5931\u3002<br \/>\n1.AOF\u6301\u4e45\u5316\u7684\u901f\u5ea6\uff0c\u76f8\u5bf9RDB\u8f83\u6162\u7684\uff0c\u5b58\u50a8\u7684\u662f\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\uff0c\u5230\u4e86\u540e\u671f\u6587\u4ef6\u4f1a\u6bd4\u8f83\u5927\uff0c\u4f20\u8f93\u56f0\u96be\u3002<br \/>\n2. AOF\u6301\u4e45\u5316\u65f6\u673a\u3002<br \/>\nappendfsync always\uff1a\u6bcf\u6267\u884c\u4e00\u4e2a\u5199\u64cd\u4f5c\uff0c\u7acb\u5373\u6301\u4e45\u5316\u5230AOF\u6587\u4ef6\u4e2d\uff0c\u6027\u80fd\u6bd4\u8f83\u4f4e\u3002<br \/>\nappendfsync everysec\uff1a\u6bcf\u79d2\u6267\u884c\u4e00\u6b21\u6301\u4e45\u5316\u3002<br \/>\nappendfsync no\uff1a\u4f1a\u6839\u636e\u4f60\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e0d\u540c\uff0c\u73af\u5883\u7684\u4e0d\u540c\uff0c\u5728\u4e00\u5b9a\u65f6\u95f4\u5185\u6267\u884c\u4e00\u6b21\u6301\u4e45\u5316\u3002<br \/>\n3. AOF\u76f8\u5bf9RDB\u66f4\u5b89\u5168\uff0c\u63a8\u8350\u540c\u65f6\u5f00\u542fAOF\u548cRDB.<\/p>\n<p>\u540c\u65f6\u5f00\u542fRDB\u548cAOF\u7684\u6ce8\u610f\u4e8b\u9879<br \/>\n\u5982\u679c\u540c\u65f6\u5f00\u542f\u4e86AOF\u548cRDB\u6301\u4e45\u5316\uff0c\u90a3\u4e48\u5728Redis\u5b95\u673a\u91cd\u542f\u4e4b\u540e\uff0c\u9700\u8981\u52a0\u8f7d\u4e00\u4e2a\u6301\u4e45\u5316\u6587\u4ef6\uff0c\u4f18\u5148\u9009\u62e9AOF\u6587\u4ef6\u3002<br \/>\n\u5982\u679c\u5148\u5f00\u542f\u4e86RDB\uff0c\u518d\u6b21\u5f00\u542fAOF\uff0c\u5982\u679cRDB\u6267\u884c\u4e86\u6301\u4e45\u5316\uff0c\u90a3\u4e48RDB\u6587\u4ef6\u4e2d\u7684\u5185\u5bb9\u4f1a\u88abAOF\u8986\u76d6\u6389\u3002<\/p>\n<p><strong>5.4 Redis\u7684\u4e3b\u4ece\u67b6\u6784<\/strong><\/p>\n<p>\u5355\u673a\u7248 Redis\u5b58\u5728\u8bfb\u5199\u74f6\u9888\u7684\u95ee\u9898<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/29\/7.png\" alt=\"\" width=\"680\" \/><\/p>\n<p>\u914d\u7f6e\u4fe1\u606f\uff1a<\/p>\n<p>\u5728opt\u76ee\u5f55\u4e0b\u65b0\u5efa docker_redis_master_slave\uff0c\u7136\u540e\u521b\u5efadocker-compose.yml\u6587\u4ef6<\/p>\n<p>\u4e3b\u8282\u70b9\u914d\u7f6e\uff1a<\/p>\n<pre>version: '3.1'\r\nservices:\r\n  redis1:\r\n    restart: always\r\n    image: daocloud.io\/library\/redis:5.0.7\r\n    container_name: redis1\r\n    environment:\r\n      - TZ=Asia\/Shanghai\r\n    ports:\r\n      - 7001:6379\r\n    valumes:\r\n      - .\/conf\/redis1.conf:\/usr\/local\/redis\/redis.conf\r\n    command:  [\"redis-server\",\"\/usr\/local\/redis\/redis.conf\"]\r\n  redis2:\r\n    restart: always\r\n    image: daocloud.io\/library\/redis:5.0.7\r\n    container_name: redis2\r\n    environment:\r\n      - TZ=Asia\/Shanghai\r\n    ports:\r\n      - 7002:6379\r\n    valumes:\r\n      - .\/conf\/redis2.conf:\/usr\/local\/redis\/redis.conf\r\n    links:\r\n      - redis1:master\r\n    command:  [\"redis-server\",\"\/usr\/local\/redis\/redis.conf\"]\r\n  redis3:\r\n    restart: always\r\n    image: daocloud.io\/library\/redis:5.0.7\r\n    container_name: redis3\r\n    environment:\r\n      - TZ=Asia\/Shanghai\r\n    ports:\r\n      - 7003:6379\r\n    valumes:\r\n      - .\/conf\/redis3.conf:\/usr\/local\/redis\/redis.conf\r\n    links:\r\n      - redis1:master\r\n    command:  [\"redis-server\",\"\/usr\/local\/redis\/redis.conf\"]\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>redis2\u548credis3\u4ece\u8282\u70b9\u914d\u7f6e<\/p>\n<p>\u5728\u914d\u7f6e\u6587\u4ef6\u641c\u7d22replicaof &lt;masterip&gt; &lt;masterport&gt;<\/p>\n<p>\u521b\u5efa conf\u6587\u4ef6\u5939\uff0c\u7136\u540e\u521b\u5efa touch redis1.conf \u3001 touch redis2.conf \u3001 touch redis3.conf<\/p>\n<p>\u7136\u540e\u7f16\u8f91\u521a\u521a\u521b\u5efa\u7684\u6587\u4ef6\uff0c\u5c06\u4e0b\u9762\u7684\u4ee3\u7801\u590d\u5236\u7c98\u8d34\uff0c\u7136\u540e\u4fdd\u5b58\u5373\u53ef\u3002<\/p>\n<p>replicaof master 6379<\/p>\n<p>\u7136\u540e\u8fd4\u56de\u4e0a\u4e00\u7ea7\u76ee\u5f55\uff0c\u542f\u52a8docker-compose up -d<\/p>\n<p>\u67e5\u770b\u65e5\u5fd7\uff1adocker-compose logs -f<\/p>\n<p>&nbsp;<\/p>\n<p><strong>5.5 Redis\u7684\u54e8\u5175<\/strong><\/p>\n<p>\u54e8\u5175\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u89e3\u51b3\u4e3b\u4ece\u67b6\u6784\u4e2d\u7684\u5355\u70b9\u6545\u969c\u95ee\u9898<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/30\/1.png\" alt=\"\" width=\"680\" \/><\/p>\n<p>\u51c6\u5907\u54e8\u5175\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5e76\u4e14\u5728\u5bb9\u5668\u5185\u90e8\u624b\u52a8\u542f\u52a8\u54e8\u5175\u5373\u53ef<\/p>\n<p>\u5728conf\u76ee\u5f55\u4e0b\u521b\u5efa sentinel1.conf\u00a0 sentinel2.conf sentinel3.conf<\/p>\n<p># \u54e8\u5175\u9700\u8981\u540e\u53f0\u542f\u52a8<br \/>\ndaemonize yes<br \/>\n# \u6307\u5b9a master \u8282\u70b9\u7684 ip\u548c\u7aef\u53e3(\u4e3b)<br \/>\n# sentinel monitor &lt;master-name&gt; &lt;ip&gt; &lt;redis-port&gt; &lt;quorum&gt;<br \/>\nsentinel monitor master localhost 6379 2<br \/>\n# \u6307\u5b9a master \u8282\u70b9\u7684 ip\u548c\u7aef\u53e3(\u4ece)<br \/>\nsentinel monitor master master 6379 2<br \/>\n# \u54e8\u5175\u6bcf\u9694\u591a\u4e45\u76d1\u542c\u4e00\u6b21redis\u67b6\u6784<br \/>\nsentinel down-after-milliseconds master 10000<\/p>\n<p>\u4fee\u6539 docker-compose.yml\uff0c\u4e3a\u4e86\u53ef\u4ee5\u5728\u5bb9\u5668\u5185\u90e8\u4f7f\u7528\u54e8\u5175\u7684\u914d\u7f6e<\/p>\n<p>\u4e3a\u6bcf\u4e2aredis\u6dfb\u52a0\u6570\u636e\u5377<\/p>\n<p>&#8211; .\/conf\/sentinel1.conf:\/data\/sentinel.conf<\/p>\n<p>\u6700\u540e\u6267\u884c docker-compose down\u3001docker-compose up -d<\/p>\n<p>\u7136\u540e\u8fdb\u5165\u5bb9\u5668\u5185\u90e8\uff1adocker exec -it redis1\u6807\u8bc6bash<\/p>\n<p>\u7136\u540e\u5c55\u793a ls\uff0c\u54e8\u5175\u53ef\u8fd0\u884c\u6587\u4ef6\u5728 cd \/usr\/local\/bin<\/p>\n<p>\u8fd4\u56de\u5230data\u76ee\u5f55\uff0c\u7136\u540e\u8fd0\u884c\uff1aredis-sentinel sentinel.conf\uff0c\u7136\u540eexit<\/p>\n<p>\u7136\u540edocker ps\uff0cdocker exec -it redis2\u6807\u8bc6 bash<\/p>\n<p>\u8fd0\u884c\uff1aredis-sentinel sentinel.conf\uff0c\u7136\u540eexit<\/p>\n<p>\u7136\u540edocker ps\uff0cdocker exec -it redis3\u6807\u8bc6 bash<\/p>\n<p>\u8fd0\u884c\uff1aredis-sentinel sentinel.conf\uff0c\u7136\u540eexit<\/p>\n<p>\u67e5\u770b\u662f\u5426\u662fmaster\uff1a\u8fdb\u5165\u5bb9\u5668\u5185\u90e8\uff0c\u7136\u540eredis-cli\uff0c\u4e4b\u540e\u6267\u884c info \u67e5\u770b\u662f\u5426\u662fmaster\uff0c\u7136\u540e\u67e5\u770b\u6709\u51e0\u4e2a\u54e8\u5175<\/p>\n<p>&nbsp;<\/p>\n<p><strong>5.6 Redis\u7684\u96c6\u7fa4<\/strong><\/p>\n<p>Redis\u96c6\u7fa4\u5728\u4fdd\u8bc1\u4e3b\u4ece\u52a0\u54e8\u5175\u7684\u57fa\u672c\u529f\u80fd\u4e4b\u5916\uff0c\u8fd8\u80fd\u591f\u63d0\u5347Redis\u5b58\u50a8\u6570\u636e\u7684\u80fd\u529b<\/p>\n<p>redis\u96c6\u7fa4\u67b6\u6784\u56fe<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/30\/2.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>docker-compose.yml<\/strong><\/p>\n<p>\u5148\u505c\u6b62docker\u6240\u6709\u8fdb\u7a0b\u7136\u540e\u5220\u9664docker\u6240\u6709\u5bb9\u5668<\/p>\n<p>\u5728 opt\u76ee\u5f55\u4e0b\u521b\u5efa docker_redis_cluster\uff0c\u7136\u540e\u8fdb\u5165\u8be5\u76ee\u5f55\u521b\u5efa docker-compose.yml\u6587\u4ef6<\/p>\n<pre>version: '3.1'\r\nservices:\r\n  redis1:\r\n    restart: always\r\n    image: daocloud.io\/library\/redis:5.0.7\r\n    container_name: redis1\r\n    environment:\r\n      - TZ=Asia\/Shanghai\r\n    ports:\r\n      - 7001:7001\r\n      - 17001:17001\r\n    volumes:\r\n      - .\/conf\/redis1.conf:\/usr\/local\/redis\/redis.conf\r\n    command:  [\"redis-server\",\"\/usr\/local\/redis\/redis.conf\"]\r\n  redis2:\r\n    restart: always\r\n    image: daocloud.io\/library\/redis:5.0.7\r\n    container_name: redis2\r\n    environment:\r\n      - TZ=Asia\/Shanghai\r\n    ports:\r\n      - 7002:7002\r\n      - 17002:17002\r\n    volumes:\r\n      - .\/conf\/redis2.conf:\/usr\/local\/redis\/redis.conf\r\n    command:  [\"redis-server\",\"\/usr\/local\/redis\/redis.conf\"]\r\n  redis3:\r\n    restart: always\r\n    image: daocloud.io\/library\/redis:5.0.7\r\n    container_name: redis3\r\n    environment:\r\n      - TZ=Asia\/Shanghai\r\n    ports:\r\n      - 7003:7003\r\n      - 17003:17003\r\n    volumes:\r\n      - .\/conf\/redis3.conf:\/usr\/local\/redis\/redis.conf\r\n    command:  [\"redis-server\",\"\/usr\/local\/redis\/redis.conf\"]\r\n  redis4:\r\n    restart: always\r\n    image: daocloud.io\/library\/redis:5.0.7\r\n    container_name: redis4\r\n    environment:\r\n      - TZ=Asia\/Shanghai\r\n    ports:\r\n      - 7004:7004\r\n      - 17004:17004\r\n    volumes:\r\n      - .\/conf\/redis4.conf:\/usr\/local\/redis\/redis.conf\r\n    command:  [\"redis-server\",\"\/usr\/local\/redis\/redis.conf\"]\r\n  redis5:\r\n    restart: always\r\n    image: daocloud.io\/library\/redis:5.0.7\r\n    container_name: redis5\r\n    environment:\r\n      - TZ=Asia\/Shanghai\r\n    ports:\r\n      - 7005:7005\r\n      - 17005:17005\r\n    volumes:\r\n      - .\/conf\/redis5.conf:\/usr\/local\/redis\/redis.conf\r\n    command:  [\"redis-server\",\"\/usr\/local\/redis\/redis.conf\"]\r\n  redis6:\r\n    restart: always\r\n    image: daocloud.io\/library\/redis:5.0.7\r\n    container_name: redis6\r\n    environment:\r\n      - TZ=Asia\/Shanghai\r\n    ports:\r\n      - 7006:7006\r\n      - 17006:17006\r\n    volumes:\r\n      - .\/conf\/redis6.conf:\/usr\/local\/redis\/redis.conf\r\n    command:  [\"redis-server\",\"\/usr\/local\/redis\/redis.conf\"]\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>redis.conf<\/strong><\/p>\n<p>\u5728docker_redis_cluster \u521b\u5efa conf\u76ee\u5f55\uff0c\u5206\u522b\u521b\u5efa redis1.conf redis2.conf ~ redis6.conf<\/p>\n<p># \u6307\u5b9aredis\u7684\u7aef\u53e3\u53f7<br \/>\nport 7001<br \/>\n# \u5f00\u542fredis\u96c6\u7fa4<br \/>\ncluster-enabled yes<br \/>\n# \u96c6\u7fa4\u4fe1\u606f\u7684\u6587\u4ef6<br \/>\ncluster-config-file nodes-7001.conf<br \/>\n# \u96c6\u7fa4\u7684\u5bf9\u5916ip\u5730\u5740<br \/>\ncluster-announce-ip Linux\u7684ip<br \/>\n# \u96c6\u7fa4\u7684\u5bf9\u5916\u7aef\u53e3<br \/>\ncluster-announce-port 7001<br \/>\n# \u96c6\u7fa4\u7684\u603b\u7ebf\u7aef\u53e3<br \/>\ncluster-announce-bus-port 17001<\/p>\n<p>\u7136\u540e\u5728 docker_redis_cluster\u76ee\u5f55\u4e0b \u542f\u52a8 docker-compose up -d<\/p>\n<p>\u7136\u540e\u8fdb\u5165\u5bb9\u5668\u5185\u90e8<br \/>\n\u6267\u884c \u7ba1\u7406\u96c6\u7fa4\uff1aredis-cli &#8211;cluster create Linux\u7684ip:7001 ip:7002 ~ ip:7006 &#8211;cluster-replicas 1<br \/>\n\u7136\u540e exit\uff0c\u4e4b\u540e\u6267\u884c\uff1aredis-cli -h ip -p 7001 -c<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/30\/3.png\" alt=\"\" width=\"680\" \/><br \/>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/30\/4.png\" alt=\"\" width=\"680\" \/><br \/>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/30\/5.png\" alt=\"\" width=\"680\" \/><br \/>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/30\/6.png\" alt=\"\" width=\"680\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>5.7 java\u8fde\u63a5Redis\u96c6\u7fa4<\/strong><\/p>\n<p>\u4f7f\u7528JedisCluster\u5bf9\u8c61\u8fde\u63a5Redis\u96c6\u7fa4<\/p>\n<pre>@Test\r\npublic void test(){\r\n    \/\/ \u521b\u5efa Set&lt;HostAndPort&gt; nodes\r\n    Set&lt;HostAndPort&gt; nodes=new HashSet&lt;&gt;();\r\n    nodes.add(new HostAndPort(\"192.168.2.123\",7001));\r\n    nodes.add(new HostAndPort(\"192.168.2.123\",7002));\r\n    nodes.add(new HostAndPort(\"192.168.2.123\",7003));\r\n    nodes.add(new HostAndPort(\"192.168.2.123\",7004));\r\n    nodes.add(new HostAndPort(\"192.168.2.123\",7005));\r\n    nodes.add(new HostAndPort(\"192.168.2.123\",7006));\r\n\r\n    \/\/\u521b\u5efa JedisCluster \u5bf9\u8c61\r\n    JedisCluster jc=new JedisCluster(nodes);\r\n    \/\/ \u64cd\u4f5c\r\n    String value = jc.get(\"a\");\r\n    System.out.println(\"value:\"+value);\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<h3>\u516d\u3001Redis\u5e38\u89c1\u95ee\u9898<\/h3>\n<p><strong>6.1 key\u7684\u751f\u5b58\u65f6\u95f4\u5230\u4e86\uff0cRedis\u4f1a\u7acb\u5373\u5220\u9664\u5417\uff1f<\/strong><\/p>\n<p>\u4e0d\u4f1a\u7acb\u5373\u5220\u9664\u3002<\/p>\n<p>1.\u5b9a\u671f\u5220\u9664\uff1a<br \/>\nRedis\u6bcf\u9694\u4e00\u6bb5\u65f6\u95f4\u5c31\u4f1a\u53bb\u67e5\u770bRedis\u8bbe\u7f6e\u4e86\u8fc7\u671f\u65f6\u95f4\u7684key\uff0c\u4f1a\u5728100ms\u7684\u95f4\u9694\u4e2d\u9ed8\u8ba4\u67e5\u770b3\u4e2akey<\/p>\n<p>2.\u60f0\u6027\u5220\u9664\uff1a<br \/>\n\u5982\u679c\u5f53\u4f60\u53bb\u67e5\u8be2\u4e00\u4e2a\u5df2\u7ecf\u8fc7\u4e86\u751f\u5b58\u65f6\u95f4\u7684key\u65f6\uff0cRedis\u4f1a\u67e5\u770b\u5f53\u524dkey\u7684\u751f\u5b58\u65f6\u95f4\uff0c\u662f\u5426\u5df2\u7ecf\u5230\u4e86\uff0c\u76f4\u63a5\u5220\u9664\u5f53\u524dkey\uff0c\u5e76\u4e14\u7ed9\u7528\u6237\u8fd4\u56de\u4e00\u4e2a\u7a7a\u503c\u3002<\/p>\n<p><strong>6.2 Redis\u7684\u6dd8\u6c70\u673a\u5236<\/strong><\/p>\n<p>\u5728Redis\u5185\u5b58\u5df2\u7ecf\u6ee1\u7684\u65f6\u5019\uff0c\u6dfb\u52a0\u4e86\u4e00\u4e2a\u65b0\u7684\u6570\u636e\uff0c\u6267\u884c\u6dd8\u6c70\u673a\u5236\u3002<\/p>\n<p>1. volatile-lru<br \/>\n\u5728\u5185\u5b58\u4e0d\u8db3\u65f6\uff0cRedis\u4f1a\u5728\u8bbe\u7f6e\u8fc7\u4e86\u751f\u5b58\u65f6\u95f4\u7684key\u4e2d\u5e72\u6389\u4e00\u4e2a\u6700\u8fd1<span style=\"color: #ff0000;\">\u6700\u5c11\u4f7f\u7528<\/span>\u7684key<\/p>\n<p>2. allkeys-lru<br \/>\n\u5728\u5185\u5b58\u4e0d\u8db3\u65f6\uff0cRedis\u4f1a\u5728\u5168\u90e8\u7684key\u4e2d\u5e72\u6389\u4e00\u4e2a\u6700\u8fd1<span style=\"color: #ff0000;\">\u6700\u5c11\u4f7f\u7528<\/span>\u7684key<\/p>\n<p>3. volatile-lfu<br \/>\n\u5728\u5185\u5b58\u4e0d\u8db3\u65f6\uff0cRedis\u4f1a\u5728\u8bbe\u7f6e\u8fc7\u4e86\u751f\u5b58\u65f6\u95f4\u7684key\u4e2d\u5e72\u6389\u4e00\u4e2a\u6700\u8fd1<span style=\"color: #ff0000;\">\u6700\u5c11\u9891\u6b21\u4f7f\u7528<\/span>\u7684key<\/p>\n<p>4. allkeys-lfu<br \/>\n\u5728\u5185\u5b58\u4e0d\u8db3\u65f6\uff0cRedis\u4f1a\u5728\u5168\u90e8\u7684key\u4e2d\u5e72\u6389\u4e00\u4e2a\u6700\u8fd1<span style=\"color: #ff0000;\">\u6700\u5c11\u9891\u6b21\u4f7f\u7528<\/span>\u7684key<\/p>\n<p>5. volatile-random<br \/>\n\u5728\u5185\u5b58\u4e0d\u8db3\u65f6\uff0cRedis\u4f1a\u5728\u8bbe\u7f6e\u8fc7\u4e86\u751f\u5b58\u65f6\u95f4\u7684key\u4e2d<span style=\"color: #ff0000;\">\u968f\u673a<\/span>\u5e72\u6389\u4e00\u4e2a<\/p>\n<p>6. allkeys-random<br \/>\n\u5728\u5185\u5b58\u4e0d\u8db3\u65f6\uff0cRedis\u4f1a\u5728\u5168\u90e8\u7684key\u4e2d<span style=\"color: #ff0000;\">\u968f\u673a<\/span>\u5e72\u6389\u4e00\u4e2a<\/p>\n<p>7. volatile-ttl<br \/>\n\u5728\u5185\u5b58\u4e0d\u8db3\u65f6\uff0cRedis\u4f1a\u5728\u8bbe\u7f6e\u8fc7\u4e86\u751f\u5b58\u65f6\u95f4\u7684key\u4e2d\u5e72\u6389<span style=\"color: #ff0000;\">\u5269\u4f59\u751f\u5b58\u65f6\u95f4\u6700\u5c11<\/span>\u7684key<\/p>\n<p>8. noeviction(\u9ed8\u8ba4)<br \/>\n\u5728\u5185\u5b58\u4e0d\u8db3\u65f6\uff0c\u76f4\u63a5\u62a5\u9519\u3002<\/p>\n<p>\u6307\u5b9a\u6dd8\u6c70\u673a\u5236\u7684\u65b9\u5f0f\uff1amaxmemory-policy \u5177\u4f53\u7b56\u7565<\/p>\n<p>\u8bbe\u7f6eRedis\u7684\u6700\u5927\u5185\u5b58\uff1amaxmemory &lt;bytes&gt; \/\/\u5b57\u8282\u5927\u5c0f<\/p>\n<p><strong>6.3 Redis\u7684\u7f13\u5b58\u95ee\u9898<\/strong><\/p>\n<p><strong>\u7f13\u5b58\u7a7f\u900f<\/strong><\/p>\n<p>\u95ee\u9898\u51fa\u73b0\u7684\u539f\u56e0\uff1a\u67e5\u8be2\u7684\u6570\u636e\uff0cRedis\u4e2d\u6ca1\u6709\uff0c\u6570\u636e\u5e93\u4e2d\u4e5f\u6ca1\u6709<\/p>\n<p>1.\u6839\u636eid\u67e5\u8be2\u65f6\uff0c\u5982\u679cid\u662f\u81ea\u589e\u7684\uff0c\u5c06id\u7684\u6700\u5927\u503c\u653e\u5230redis\u4e2d\uff0c\u5728\u67e5\u8be2\u6570\u636e\u5e93\u4e4b\u524d\uff0c\u76f4\u63a5\u6bd4\u8f83\u4e00\u4e0bid<br \/>\n2.\u5982\u679cid\u4e0d\u662f\u6574\u5f62\uff0c\u53ef\u4ee5\u5c06\u5168\u90e8\u7684id\u653e\u5230set\u4e2d\uff0c\u5728\u7528\u6237\u67e5\u8be2\u4e4b\u524d\uff0c\u53bbset\u4e2d\u67e5\u770b\u4e00\u4e0b\u662f\u5426\u6709\u4e00\u4e2aid<br \/>\n3.\u83b7\u53d6\u5ba2\u6237\u7aef\u7684ip\u5730\u5740\uff0c\u53ef\u4ee5\u5c06ip\u7684\u8bbf\u95ee\u6dfb\u52a0\u9650\u5236\u3002<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/30\/7.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>\u7f13\u5b58\u51fb\u7a7f<\/strong><\/p>\n<p>\u95ee\u9898\uff1a\u7f13\u5b58\u4e2d\u7684\u70ed\u70b9\u6570\u636e\uff0c\u7a81\u7136\u5230\u671f\u4e86\uff0c\u9020\u6210\u4e86\u5927\u91cf\u7684\u8bf7\u6c42\u90fd\u53bb\u8bbf\u95ee\u6570\u636e\u5e93\uff0c\u9020\u6210\u6570\u636e\u5e93\u5b95\u673a<\/p>\n<p>1.\u5728\u8bbf\u95ee\u7f13\u5b58\u4e2d\u6ca1\u6709\u7684\u65f6\u5019\uff0c\u76f4\u63a5\u6dfb\u52a0\u4e00\u4e2a\u9501\uff0c\u8ba9\u51e0\u4e2a\u8bf7\u6c42\u53bb\u8bbf\u95ee\u6570\u636e\u5e93\uff0c\u907f\u514d\u6570\u636e\u5e93\u5b95\u673a\u3002<br \/>\n2.\u70ed\u70b9\u6570\u636e\u7684\u751f\u5b58\u65f6\u95f4\u53bb\u6389\u3002<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/30\/8.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>\u7f13\u5b58\u96ea\u5d29<\/strong><\/p>\n<p>\u95ee\u9898\uff1a\u5f53\u5927\u91cf\u7f13\u5b58\u540c\u65f6\u5230\u671f\u65f6\uff0c\u6700\u7ec8\u5927\u91cf\u7684\u540c\u65f6\u53bb\u8bbf\u95ee\u6570\u636e\uff0c\u5bfc\u81f4\u6570\u636e\u5e93\u5b95\u673a<\/p>\n<p>\u5c06\u7f13\u5b58\u4e2d\u7684\u6570\u636e\u7684\u751f\u5b58\u65f6\u95f4\uff0c\u8bbe\u7f6e\u4e3a30~60\u7684\u4e00\u4e2a\u968f\u673a\u65f6\u95f4<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/30\/9.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>\u7f13\u5b58\u503e\u659c<\/strong><\/p>\n<p>\u95ee\u9898\uff1a\u70ed\u70b9\u6570\u636e\u653e\u5728\u4e86\u4e00\u4e2aRedis\u8282\u70b9\u4e0a\uff0c\u5bfc\u81f4Redis\u8282\u70b9\u65e0\u6cd5\u627f\u53d7\u4f4f\u5927\u91cf\u7684\u8bf7\u6c42\uff0c\u6700\u7ec8Redis\u5b95\u673a\u3002<\/p>\n<p>1.\u6269\u5c55\u4e3b\u4ece\u67b6\u6784\uff0c\u642d\u5efa\u5927\u91cf\u7684\u4ece\u8282\u70b9\uff0c\u7f13\u89e3Redis\u7684\u538b\u529b<br \/>\n2.\u53ef\u4ee5\u5728Tomcat\u4e2d\u505aJVM\u7f13\u5b58\uff0c\u5728\u67e5\u8be2Redis\u4e4b\u524d\uff0c\u5148\u53bb\u67e5\u8be2Tomcat\u4e2d\u7684\u7f13\u5b58\u3002<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/30\/10.png\" alt=\"\" width=\"680\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>2020java\u5fae\u670d\u52a1\u67b6\u6784\u56db\u4e4bRedis\u6559\u7a0b \u4e00\u3001Redis\u4ecb\u7ecd 1.NoSQL\u4ecb\u7ecd Redis\u5c31\u662f\u4e00\u6b3eNoS [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-2991","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2991","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2991"}],"version-history":[{"count":27,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2991\/revisions"}],"predecessor-version":[{"id":3020,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2991\/revisions\/3020"}],"wp:attachment":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2991"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2991"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2991"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}