{"id":663,"date":"2023-12-07T18:01:01","date_gmt":"2023-12-07T10:01:01","guid":{"rendered":""},"modified":"2023-12-07T18:01:01","modified_gmt":"2023-12-07T10:01:01","slug":"redis\u9762\u8bd5\u9898\u603b\u7ed3\uff08\u9644\u7b54\u6848\uff09","status":"publish","type":"post","link":"https:\/\/mushiming.com\/663.html","title":{"rendered":"redis\u9762\u8bd5\u9898\u603b\u7ed3\uff08\u9644\u7b54\u6848\uff09"},"content":{"rendered":"
<\/p>\n
\u524d\u7f6e\u77e5\u8bc6\u70b9\uff1a<\/p>\n
2023\u5e74\u518d\u4e0d\u4f1aRedis\uff0c\u5c31\u8981\u88ab\u6dd8\u6c70\u4e86<\/p>\n
\u56fe\u89e3Redis\uff0c\u8c08\u8c08Redis\u7684\u6301\u4e45\u5316\uff0cRDB\u5feb\u7167\u4e0eAOF\u65e5\u5fd7<\/p>\n
Redis bigkeys\u547d\u4ee4\u4f1a\u963b\u585e\u5417\uff1f\u600e\u4e48\u89e3\u51b3\uff1f<\/p>\n
Redis\u96c6\u7fa4\u7684\u6700\u5927\u69fd\u6570\u4e3a\u4ec0\u4e48\u662f16384\u4e2a\uff1f<\/p>\n
Redis\u5355\u7ebf\u7a0b\u8fd8\u662f\u591a\u7ebf\u7a0b\uff1fIO\u591a\u8def\u590d\u7528\u539f\u7406<\/p>\n
MySQL\u6570\u636e\u5e93\u548cRedis\u7f13\u5b58\u4e00\u81f4\u6027\u7684\u66f4\u65b0\u7b56\u7565<\/p>\n
Redis\u7f13\u5b58\u7a7f\u900f\u3001\u51fb\u7a7f\u3001\u96ea\u5d29\u5230\u5e95\u662f\u4e2a\u5565\uff1f7\u5f20\u56fe\u544a\u8bc9\u4f60<\/p>\n
Redis\u5206\u5e03\u5f0f\u9501\u7684\u5b9e\u73b0\u65b9\u5f0f<\/p>\n
Redis\u5206\u5e03\u5f0f\u7f13\u5b58\u3001\u79d2\u6740<\/p>\n
Redis\u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u539f\u7406\u548c\u5e94\u7528\u573a\u666f\uff0c\u89e3\u51b3\u7f13\u5b58\u7a7f\u900f<\/p>\n
\u76ee\u5f55<\/strong><\/p>\n \u4e00\u3001Redis\u662f\u4ec0\u4e48\uff1f<\/p>\n \u4e8c\u3001Redis\u90fd\u6709\u54ea\u4e9b\u4f7f\u7528\u573a\u666f\uff1f<\/p>\n \u4e09\u3001Redis\u6709\u54ea\u4e9b\u529f\u80fd\uff1f<\/p>\n \u56db\u3001Redis\u652f\u6301\u7684\u6570\u636e\u7c7b\u578b\u6709\u54ea\u4e9b\uff1f<\/p>\n \u4e94\u3001Redis\u53d6\u503c\u5b58\u503c\u95ee\u9898<\/p>\n \u516d\u3001Redis\u4e3a\u4ec0\u4e48\u662f\u5355\u7ebf\u7a0b\u7684\uff1f<\/p>\n \u4e03\u3001Redis\u771f\u7684\u662f\u5355\u7ebf\u7a0b\u7684\u5417\uff1f<\/p>\n \u516b\u3001Redis\u6301\u4e45\u5316\u6709\u51e0\u79cd\u65b9\u5f0f\uff1f<\/p>\n \u4e5d\u3001Redis\u548c memecache \u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/p>\n \u5341\u3001Redis\u652f\u6301\u7684 java \u5ba2\u6237\u7aef\u90fd\u6709\u54ea\u4e9b\uff1f<\/p>\n \u5341\u4e00\u3001jedis \u548c redisson \u6709\u54ea\u4e9b\u533a\u522b\uff1f<\/p>\n \u5341\u4e8c\u3001\u4ec0\u4e48\u662f\u7f13\u5b58\u7a7f\u900f\uff1f\u600e\u4e48\u89e3\u51b3\uff1f<\/p>\n \u5341\u4e09\u3001\u600e\u4e48\u4fdd\u8bc1\u7f13\u5b58\u548c\u6570\u636e\u5e93\u6570\u636e\u7684\u4e00\u81f4\u6027\uff1f<\/p>\n \u5341\u56db\u3001Redis\uff0c\u4ec0\u4e48\u662f\u7f13\u5b58\u7a7f\u900f\uff1f\u600e\u4e48\u89e3\u51b3\uff1f<\/p>\n \u5341\u4e94\u3001Redis\u600e\u4e48\u5b9e\u73b0\u5206\u5e03\u5f0f\u9501\uff1f<\/p>\n \u5341\u516d\u3001Redis\u5206\u5e03\u5f0f\u9501\u6709\u4ec0\u4e48\u7f3a\u9677\uff1f<\/p>\n \u5341\u4e03\u3001Redis\u5982\u4f55\u505a\u5185\u5b58\u4f18\u5316\uff1f<\/p>\n \n Redis\u662f\u4e00\u4e2akey-value\u5b58\u50a8\u7cfb\u7edf\uff0c\u5b83\u652f\u6301\u5b58\u50a8\u7684value\u7c7b\u578b\u76f8\u5bf9\u66f4\u591a\uff0c\u5305\u62ecstring\u3001list\u3001set\u3001zset\uff08sorted set --\u6709\u5e8f\u96c6\u5408\uff09\u548chash\u3002\u8fd9\u4e9b\u6570\u636e\u7ed3\u6784\u90fd\u652f\u6301push\/pop\u3001add\/remove\u53ca\u53d6\u4ea4\u96c6\u5e76\u96c6\u548c\u5dee\u96c6\u53ca\u66f4\u4e30\u5bcc\u7684\u64cd\u4f5c\uff0c\u800c\u4e14\u8fd9\u4e9b\u64cd\u4f5c\u90fd\u662f\u539f\u5b50\u6027\u7684\u3002\u5728\u6b64\u57fa\u7840\u4e0a\uff0cRedis\u652f\u6301\u5404\u79cd\u4e0d\u540c\u65b9\u5f0f\u7684\u6392\u5e8f\u3002\u4e3a\u4e86\u4fdd\u8bc1\u6548\u7387\uff0c\u6570\u636e\u90fd\u662f\u7f13\u5b58\u5728\u5185\u5b58\u4e2d\uff0cRedis\u4f1a\u5468\u671f\u6027\u7684\u628a\u66f4\u65b0\u7684\u6570\u636e\u5199\u5165\u78c1\u76d8\u6216\u8005\u628a\u4fee\u6539\u64cd\u4f5c\u5199\u5165\u8ffd\u52a0\u7684\u8bb0\u5f55\u6587\u4ef6\uff0c\u5e76\u4e14\u5728\u6b64\u57fa\u7840\u4e0a\u5b9e\u73b0\u4e86master-slave\uff08\u4e3b\u4ece\uff09\u540c\u6b65\u3002<\/p>\n 1\u3001\u57fa\u4e8e\u672c\u673a\u5185\u5b58\u7684\u7f13\u5b58<\/p>\n \u5f53\u8c03\u7528api\u8bbf\u95ee\u6570\u636e\u5e93\u65f6\uff0c\u5047\u5982\u6b64\u8fc7\u7a0b\u9700\u89812\u79d2\uff0c\u5982\u679c\u6bcf\u6b21\u8bf7\u6c42\u90fd\u8981\u8bbf\u95ee\u6570\u636e\u5e93\uff0c\u90a3\u5c06\u5bf9\u670d\u52a1\u5668\u9020\u6210\u5de8\u5927\u7684\u538b\u529b\uff0c\u5982\u679c\u5c06\u6b64sql\u7684\u67e5\u8be2\u7ed3\u679c\u5b58\u5230Redis\u4e2d\uff0c\u518d\u6b21\u8bf7\u6c42\u65f6\uff0c\u76f4\u63a5\u4eceRedis\u4e2d\u53d6\u5f97\uff0c\u800c\u4e0d\u662f\u8bbf\u95ee\u6570\u636e\u5e93\uff0c\u6548\u7387\u5c06\u5f97\u5230\u5de8\u5927\u7684\u63d0\u5347\uff0cRedis\u53ef\u4ee5\u5b9a\u65f6\u53bb\u66f4\u65b0\u6570\u636e\uff08\u6bd4\u59821\u5206\u949f\uff09\u3002<\/p>\n 2\u3001\u5982\u679c\u7535\u8111\u91cd\u542f\uff0c\u5199\u5165\u5185\u5b58\u7684\u6570\u636e\u662f\u4e0d\u662f\u5c31\u5931\u6548\u4e86\u5462\uff0c\u8fd9\u65f6Redis\u8fd8\u63d0\u4f9b\u4e86\u6301\u4e45\u5316\u7684\u529f\u80fd\u3002<\/p>\n 3\u3001\u54e8\u5175\uff08Sentinel\uff09\u548c\u590d\u5236<\/p>\n Sentinel\u53ef\u4ee5\u7ba1\u7406\u591a\u4e2aRedis\u670d\u52a1\u5668\uff0c\u5b83\u63d0\u4f9b\u4e86\u76d1\u63a7\u3001\u63d0\u9192\u4ee5\u53ca\u81ea\u52a8\u7684\u6545\u969c\u8f6c\u79fb\u529f\u80fd\uff1b<\/p>\n \u590d\u5236\u5219\u662f\u8ba9Redis\u670d\u52a1\u5668\u53ef\u4ee5\u914d\u5907\u5907\u4efd\u7684\u670d\u52a1\u5668\uff1b<\/p>\n Redis\u4e5f\u662f\u901a\u8fc7\u8fd9\u4e24\u4e2a\u529f\u80fd\u4fdd\u8bc1Redis\u7684\u9ad8\u53ef\u7528\uff1b<\/p>\n 4\u3001\u96c6\u7fa4\uff08Cluster\uff09<\/p>\n \u5355\u53f0\u670d\u52a1\u5668\u8d44\u6e90\u603b\u662f\u6709\u4e0a\u9650\u7684\uff0cCPU\u548cIO\u8d44\u6e90\u53ef\u4ee5\u901a\u8fc7\u4e3b\u4ece\u590d\u5236\uff0c\u8fdb\u884c\u8bfb\u5199\u5206\u79bb\uff0c\u628a\u4e00\u90e8\u5206CPU\u548cIO\u7684\u538b\u529b\u8f6c\u79fb\u5230\u4ece\u670d\u52a1\u5668\u4e0a\uff0c\u4f46\u662f\u5185\u5b58\u8d44\u6e90\u600e\u4e48\u529e\uff0c\u4e3b\u4ece\u6a21\u5f0f\u53ea\u662f\u6570\u636e\u7684\u5907\u4efd\uff0c\u5e76\u4e0d\u80fd\u6269\u5145\u5185\u5b58\uff1b<\/p>\n \u73b0\u5728\u6211\u4eec\u53ef\u4ee5\u6a2a\u5411\u6269\u5c55\uff0c\u8ba9\u6bcf\u53f0\u670d\u52a1\u5668\u53ea\u8d1f\u8d23\u4e00\u90e8\u5206\u4efb\u52a1\uff0c\u7136\u540e\u5c06\u8fd9\u4e9b\u670d\u52a1\u5668\u6784\u6210\u4e00\u4e2a\u6574\u4f53\uff0c\u5bf9\u5916\u754c\u6765\u8bf4\uff0c\u8fd9\u4e00\u7ec4\u670d\u52a1\u5668\u5c31\u50cf\u662f\u96c6\u7fa4\u4e00\u6837\u3002<\/p>\n 1\u3001\u5148\u628aRedis\u7684\u8fde\u63a5\u6c60\u62ff\u51fa\u6765<\/p>\n 2\u3001\u5b58\u53d6\u503c<\/p>\n 3\u3001\u5bf9map\u8fdb\u884c\u64cd\u4f5c<\/p>\n Redis6.0\u4e4b\u524d\u662f\u5355\u7ebf\u7a0b\u7684\uff0cRedis6.0\u4e4b\u540e\u5f00\u59cb\u652f\u6301\u591a\u7ebf\u7a0b\uff1b redis\u63d0\u4f9b\u4e86\u4e24\u79cd\u6301\u4e45\u5316\u7684\u65b9\u5f0f\uff0c\u5206\u522b\u662fRDB\uff08Redis DataBase\uff09\u548cAOF\uff08Append Only File\uff09\u3002<\/p>\n RDB\uff0c\u7b80\u800c\u8a00\u4e4b\uff0c\u5c31\u662f\u5728\u4e0d\u540c\u7684\u65f6\u95f4\u70b9\uff0c\u5c06redis\u5b58\u50a8\u7684\u6570\u636e\u751f\u6210\u5feb\u7167\u5e76\u5b58\u50a8\u5230\u78c1\u76d8\u7b49\u4ecb\u8d28\u4e0a\uff1b<\/p>\n AOF\uff0c\u5219\u662f\u6362\u4e86\u4e00\u4e2a\u89d2\u5ea6\u6765\u5b9e\u73b0\u6301\u4e45\u5316\uff0c\u90a3\u5c31\u662f\u5c06redis\u6267\u884c\u8fc7\u7684\u6240\u6709\u5199\u6307\u4ee4\u8bb0\u5f55\u4e0b\u6765\uff0c\u5728\u4e0b\u6b21redis\u91cd\u65b0\u542f\u52a8\u65f6\uff0c\u53ea\u8981\u628a\u8fd9\u4e9b\u5199\u6307\u4ee4\u4ece\u524d\u5230\u540e\u518d\u91cd\u590d\u6267\u884c\u4e00\u904d\uff0c\u5c31\u53ef\u4ee5\u5b9e\u73b0\u6570\u636e\u6062\u590d\u4e86\u3002<\/p>\n \u5176\u5b9eRDB\u548cAOF\u4e24\u79cd\u65b9\u5f0f\u4e5f\u53ef\u4ee5\u540c\u65f6\u4f7f\u7528\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5982\u679credis\u91cd\u542f\u7684\u8bdd\uff0c\u5219\u4f1a\u4f18\u5148\u91c7\u7528AOF\u65b9\u5f0f\u6765\u8fdb\u884c\u6570\u636e\u6062\u590d\uff0c\u8fd9\u662f\u56e0\u4e3aAOF\u65b9\u5f0f\u7684\u6570\u636e\u6062\u590d\u5b8c\u6574\u5ea6\u66f4\u9ad8\u3002<\/p>\n \u5982\u679c\u4f60\u6ca1\u6709\u6570\u636e\u6301\u4e45\u5316\u7684\u9700\u6c42\uff0c\u4e5f\u5b8c\u5168\u53ef\u4ee5\u5173\u95edRDB\u548cAOF\u65b9\u5f0f\uff0c\u8fd9\u6837\u7684\u8bdd\uff0credis\u5c06\u53d8\u6210\u4e00\u4e2a\u7eaf\u5185\u5b58\u6570\u636e\u5e93\uff0c\u5c31\u50cfmemcache\u4e00\u6837\u3002<\/p>\n 1\u3001Redis\u76f8\u6bd4memecache\uff0c\u62e5\u6709\u66f4\u591a\u7684\u6570\u636e\u7ed3\u6784\u548c\u652f\u6301\u66f4\u4e30\u5bcc\u7684\u6570\u636e\u64cd\u4f5c\u3002<\/p>\n \uff081\uff09Redis\u652f\u6301key-value\uff0c\u5e38\u7528\u7684\u6570\u636e\u7c7b\u578b\u4e3b\u8981\u6709String\u3001Hash\u3001List\u3001Set\u3001Sorted Set\u3002<\/p>\n \uff082\uff09memecache\u53ea\u652f\u6301key-value\u3002<\/p>\n 2\u3001\u5185\u5b58\u4f7f\u7528\u7387\u5bf9\u6bd4\uff0cRedis\u91c7\u7528hash\u7ed3\u6784\u6765\u505akey-value\u5b58\u50a8\uff0c\u7531\u4e8e\u5176\u7ec4\u5408\u5f0f\u7684\u538b\u7f29\uff0c\u5176\u5185\u5b58\u5229\u7528\u7387\u4f1a\u9ad8\u4e8ememecache\u3002<\/p>\n 3\u3001\u6027\u80fd\u5bf9\u6bd4\uff1aRedis\u53ea\u4f7f\u7528\u5355\u6838\uff0cmemecache\u4f7f\u7528\u591a\u6838\u3002<\/p>\n 4\u3001Redis\u652f\u6301\u78c1\u76d8\u6301\u4e45\u5316\uff0cmemecache\u4e0d\u652f\u6301\u3002<\/p>\n Redis\u53ef\u4ee5\u5c06\u4e00\u4e9b\u5f88\u4e45\u6ca1\u7528\u5230\u7684value\u901a\u8fc7swap\u65b9\u6cd5\u4ea4\u6362\u5230\u78c1\u76d8\u3002<\/p>\n 5\u3001Redis\u652f\u6301\u5206\u5e03\u5f0f\u96c6\u7fa4\uff0cmemecache\u4e0d\u652f\u6301\u3002<\/p>\n Redisson\u3001Jedis\u3001lettuce \u7b49\u7b49\uff0c\u5b98\u65b9\u63a8\u8350\u4f7f\u7528 Redisson\u3002<\/p>\n Jedis \u548c Redisson \u90fd\u662fJava\u4e2d\u5bf9Redis\u64cd\u4f5c\u7684\u5c01\u88c5\u3002Jedis \u53ea\u662f\u7b80\u5355\u7684\u5c01\u88c5\u4e86 Redis \u7684API\u5e93\uff0c\u53ef\u4ee5\u770b\u4f5c\u662fRedis\u5ba2\u6237\u7aef\uff0c\u5b83\u7684\u65b9\u6cd5\u548cRedis \u7684\u547d\u4ee4\u5f88\u7c7b\u4f3c\u3002Redisson \u4e0d\u4ec5\u5c01\u88c5\u4e86 redis \uff0c\u8fd8\u5c01\u88c5\u4e86\u5bf9\u66f4\u591a\u6570\u636e\u7ed3\u6784\u7684\u652f\u6301\uff0c\u4ee5\u53ca\u9501\u7b49\u529f\u80fd\uff0c\u76f8\u6bd4\u4e8eJedis \u66f4\u52a0\u5927\u3002\u4f46Jedis\u76f8\u6bd4\u4e8eRedisson \u66f4\u539f\u751f\u4e00\u4e9b\uff0c\u66f4\u7075\u6d3b\u3002<\/p>\n 1\u3001\u7f13\u5b58\u7a7f\u900f<\/p>\n \u4e00\u822c\u7684\u7f13\u5b58\u7cfb\u7edf\uff0c\u90fd\u662f\u6309\u7167key\u53bb\u7f13\u5b58\u67e5\u8be2\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u5bf9\u7528\u7684value\uff0c\u5c31\u5e94\u8be5\u53bb\u540e\u7aef\u7cfb\u7edf\u67e5\u627e\uff08\u6bd4\u5982DB\u6570\u636e\u5e93\uff09\u3002\u4e00\u4e9b\u6076\u610f\u7684\u8bf7\u6c42\u4f1a\u6545\u610f\u67e5\u8be2\u4e0d\u5b58\u5728\u7684key\uff0c\u8bf7\u6c42\u91cf\u5f88\u5927\uff0c\u5c31\u4f1a\u5bf9\u540e\u7aef\u7cfb\u7edf\u9020\u6210\u5f88\u5927\u7684\u538b\u529b\u3002\u8fd9\u5c31\u53eb\u505a\u7f13\u5b58\u7a7f\u900f\u3002<\/p>\n 2\u3001\u600e\u4e48\u89e3\u51b3\uff1f<\/p>\n \u5bf9\u67e5\u8be2\u7ed3\u679c\u4e3a\u7a7a\u7684\u60c5\u51b5\u4e5f\u8fdb\u884c\u7f13\u5b58\uff0c\u7f13\u5b58\u65f6\u95f4\u8bbe\u7f6e\u77ed\u4e00\u70b9\uff0c\u6216\u8005\u8be5key\u5bf9\u5e94\u7684\u6570\u636einsert\u4e4b\u540e\u6e05\u7406\u7f13\u5b58\u3002 3\u3001\u7f13\u5b58\u96ea\u5d29<\/p>\n \u5f53\u7f13\u5b58\u670d\u52a1\u5668\u91cd\u542f\u6216\u8005\u5927\u91cf\u7f13\u5b58\u96c6\u4e2d\u5728\u67d0\u4e00\u65f6\u95f4\u6bb5\u5931\u6548\uff0c\u8fd9\u6837\u5728\u5931\u6548\u7684\u65f6\u5019\uff0c\u4f1a\u7ed9\u540e\u7aef\u7cfb\u7edf\u5e26\u6765\u5f88\u5927\u7684\u538b\u529b\uff0c\u5bfc\u81f4\u7cfb\u7edf\u5d29\u6e83\u3002<\/p>\n 4\u3001\u5982\u4f55\u89e3\u51b3\uff1f<\/p>\n 1\u3001\u6dd8\u6c70\u7f13\u5b58<\/p>\n \u6570\u636e\u5982\u679c\u4e3a\u8f83\u4e3a\u590d\u6742\u7684\u6570\u636e\u65f6\uff0c\u8fdb\u884c\u7f13\u5b58\u7684\u66f4\u65b0\u64cd\u4f5c\u5c31\u4f1a\u53d8\u5f97\u5f02\u5e38\u590d\u6742\uff0c\u56e0\u6b64\u4e00\u822c\u63a8\u8350\u9009\u62e9\u6dd8\u6c70\u7f13\u5b58\uff0c\u800c\u4e0d\u662f\u66f4\u65b0\u7f13\u5b58\u3002<\/p>\n 2\u3001\u9009\u62e9\u5148\u6dd8\u6c70\u7f13\u5b58\uff0c\u518d\u66f4\u65b0\u6570\u636e\u5e93<\/p>\n \u5047\u5982\u5148\u66f4\u65b0\u6570\u636e\u5e93\uff0c\u518d\u6dd8\u6c70\u7f13\u5b58\uff0c\u5982\u679c\u6dd8\u6c70\u7f13\u5b58\u5931\u8d25\uff0c\u90a3\u4e48\u540e\u9762\u7684\u8bf7\u6c42\u90fd\u4f1a\u5f97\u5230\u810f\u6570\u636e\uff0c\u76f4\u81f3\u7f13\u5b58\u8fc7\u671f\u3002<\/p>\n \u5047\u5982\u5148\u6dd8\u6c70\u7f13\u5b58\u518d\u66f4\u65b0\u6570\u636e\u5e93\uff0c\u5982\u679c\u66f4\u65b0\u6570\u636e\u5e93\u5931\u8d25\uff0c\u53ea\u4f1a\u4ea7\u751f\u4e00\u6b21\u7f13\u5b58\u7a7f\u900f\uff0c\u76f8\u6bd4\u8f83\u800c\u8a00\uff0c\u540e\u8005\u5bf9\u4e1a\u52a1\u5219\u6ca1\u6709\u672c\u8d28\u4e0a\u7684\u5f71\u54cd\u3002<\/p>\n 3\u3001\u5ef6\u65f6\u53cc\u5220\u7b56\u7565<\/p>\n \u5982\u4e0b\u573a\u666f\uff1a\u540c\u65f6\u6709\u4e00\u4e2a\u8bf7\u6c42A\u8fdb\u884c\u66f4\u65b0\u64cd\u4f5c\uff0c\u53e6\u4e00\u4e2a\u8bf7\u6c42B\u8fdb\u884c\u67e5\u8be2\u64cd\u4f5c\u3002<\/p>\n \u6b21\u6570\u4fbf\u51fa\u73b0\u4e86\u6570\u636e\u4e0d\u4e00\u81f4\u95ee\u9898\u3002\u91c7\u7528\u5ef6\u65f6\u53cc\u5220\u7b56\u7565\u5f97\u4ee5\u89e3\u51b3\u3002<\/p>\n \u8fd9\u4e48\u505a\uff0c\u53ef\u4ee5\u5c061\u79d2\u5185\u6240\u9020\u6210\u7684\u7f13\u5b58\u810f\u6570\u636e\uff0c\u518d\u6b21\u5220\u9664\u3002\u8fd9\u4e2a\u65f6\u95f4\u8bbe\u5b9a\u53ef\u6839\u636e\u4fc4\u4e1a\u52a1\u573a\u666f\u8fdb\u884c\u4e00\u4e2a\u8c03\u8282\u3002<\/p>\n 4\u3001\u6570\u636e\u5e93\u8bfb\u5199\u5206\u79bb\u7684\u573a\u666f<\/p>\n \u4e24\u4e2a\u8bf7\u6c42\uff0c\u4e00\u4e2a\u8bf7\u6c42A\u8fdb\u884c\u66f4\u65b0\u64cd\u4f5c\uff0c\u53e6\u4e00\u4e2a\u8bf7\u6c42B\u8fdb\u884c\u67e5\u8be2\u64cd\u4f5c\u3002<\/p>\n \u4f9d\u65e7\u91c7\u7528\u5ef6\u65f6\u53cc\u5220\u7b56\u7565\u89e3\u51b3\u6b64\u95ee\u9898\u3002<\/p>\n 1\u3001\u7f13\u5b58\u7a7f\u900f<\/p>\n \u4e00\u822c\u7684\u7f13\u5b58\u7cfb\u7edf\uff0c\u90fd\u662f\u6309\u7167key\u53bb\u7f13\u5b58\u67e5\u8be2\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u5bf9\u7528\u7684value\uff0c\u5c31\u5e94\u8be5\u53bb\u540e\u7aef\u7cfb\u7edf\u67e5\u627e\uff08\u6bd4\u5982DB\u6570\u636e\u5e93\uff09\u3002\u4e00\u4e9b\u6076\u610f\u7684\u8bf7\u6c42\u4f1a\u6545\u610f\u67e5\u8be2\u4e0d\u5b58\u5728\u7684key\uff0c\u8bf7\u6c42\u91cf\u5f88\u5927\uff0c\u5c31\u4f1a\u5bf9\u540e\u7aef\u7cfb\u7edf\u9020\u6210\u5f88\u5927\u7684\u538b\u529b\u3002\u8fd9\u5c31\u53eb\u505a\u7f13\u5b58\u7a7f\u900f\u3002<\/p>\n 2\u3001\u600e\u4e48\u89e3\u51b3\uff1f<\/p>\n \u5bf9\u67e5\u8be2\u7ed3\u679c\u4e3a\u7a7a\u7684\u60c5\u51b5\u4e5f\u8fdb\u884c\u7f13\u5b58\uff0c\u7f13\u5b58\u65f6\u95f4\u8bbe\u7f6e\u77ed\u4e00\u70b9\uff0c\u6216\u8005\u8be5key\u5bf9\u5e94\u7684\u6570\u636einsert\u4e4b\u540e\u6e05\u7406\u7f13\u5b58\u3002 3\u3001\u7f13\u5b58\u96ea\u5d29<\/p>\n \u5f53\u7f13\u5b58\u670d\u52a1\u5668\u91cd\u542f\u6216\u8005\u5927\u91cf\u7f13\u5b58\u96c6\u4e2d\u5728\u67d0\u4e00\u65f6\u95f4\u6bb5\u5931\u6548\uff0c\u8fd9\u6837\u5728\u5931\u6548\u7684\u65f6\u5019\uff0c\u4f1a\u7ed9\u540e\u7aef\u7cfb\u7edf\u5e26\u6765\u5f88\u5927\u7684\u538b\u529b\uff0c\u5bfc\u81f4\u7cfb\u7edf\u5d29\u6e83\u3002<\/p>\n 4\u3001\u5982\u4f55\u89e3\u51b3\uff1f<\/p>\n \u4f7f\u7528Redis\u5b9e\u73b0\u5206\u5e03\u5f0f\u9501<\/p>\n redis\u547d\u4ee4\uff1aset users 10 nx ex 12 \u539f\u5b50\u6027\u547d\u4ee4<\/p>\n \u5907\u6ce8\uff1a\u53ef\u4ee5\u901a\u8fc7lua\u811a\u672c\uff0c\u4fdd\u8bc1\u5206\u5e03\u5f0f\u9501\u7684\u539f\u5b50\u6027\u3002<\/p>\n Redis \u5206\u5e03\u5f0f\u9501\u4e0d\u80fd\u89e3\u51b3\u8d85\u65f6\u7684\u95ee\u9898\uff0c\u5206\u5e03\u5f0f\u9501\u6709\u4e00\u4e2a\u8d85\u65f6\u65f6\u95f4\uff0c\u7a0b\u5e8f\u7684\u6267\u884c\u5982\u679c\u8d85\u51fa\u4e86\u9501\u7684\u8d85\u65f6\u65f6\u95f4\u5c31\u4f1a\u51fa\u73b0\u95ee\u9898\u3002<\/p>\n Redis\u5bb9\u6613\u4ea7\u751f\u7684\u51e0\u4e2a\u95ee\u9898\uff1a<\/p>\n 1\u3001\u7f29\u77ed\u952e\u503c\u7684\u957f\u5ea6<\/p>\n 2\u3001\u5171\u4eab\u5bf9\u8c61\u6c60<\/p>\n \u5bf9\u8c61\u5171\u4eab\u6c60\u6307Redis\u5185\u90e8\u7ef4\u62a4[0-9999]\u7684\u6574\u6570\u5bf9\u8c61\u6c60\u3002\u521b\u5efa\u5927\u91cf\u7684\u6574\u6570\u7c7b\u578bredisObject\u5b58\u5728\u5185\u5b58\u5f00\u9500\uff0c\u6bcf\u4e2aredisObject\u5185\u90e8\u7ed3\u6784\u81f3\u5c11\u536016\u5b57\u8282\uff0c\u751a\u81f3\u8d85\u8fc7\u4e86\u6574\u6570\u81ea\u8eab\u7a7a\u95f4\u6d88\u8017\u3002\u6240\u4ee5Redis\u5185\u5b58\u7ef4\u62a4\u4e00\u4e2a[0-9999]\u7684\u6574\u6570\u5bf9\u8c61\u6c60\uff0c\u7528\u4e8e\u8282\u7ea6\u5185\u5b58\u3002 \u9664\u4e86\u6574\u6570\u503c\u5bf9\u8c61\uff0c\u5176\u4ed6\u7c7b\u578b\u5982list,hash,set,zset\u5185\u90e8\u5143\u7d20\u4e5f\u53ef\u4ee5\u4f7f\u7528\u6574\u6570\u5bf9\u8c61\u6c60\u3002\u56e0\u6b64\u5f00\u53d1\u4e2d\u5728\u6ee1\u8db3\u9700\u6c42\u7684\u524d\u63d0\u4e0b\uff0c\u5c3d\u91cf\u4f7f\u7528\u6574\u6570\u5bf9\u8c61\u4ee5\u8282\u7701\u5185\u5b58\u3002<\/p>\n 3\u3001\u5b57\u7b26\u4e32\u4f18\u5316<\/p>\n 4\u3001\u7f16\u7801\u4f18\u5316<\/p>\n 5\u3001\u63a7\u5236key\u7684\u6570\u91cf<\/p>\n<\/p>\n <\/p>\n \ud83c\udfc6\u4f5c\u8005\u7b80\u4ecb\uff1a\u54ea\u5412\uff0cCSDN2022\u535a\u5ba2\u4e4b\u661fTop1\u3001CSDN2021\u535a\u5ba2\u4e4b\u661fTop2\u3001\u591a\u5c4a\u65b0\u661f\u8ba1\u5212\u5bfc\u5e08\u270c\u3001\u535a\u5ba2\u4e13\u5bb6\ud83d\udcaa \ud83c\udfc6\u672c\u6587\u6536\u5f55\u4e8e\uff0cJava\u57fa\u7840\u6559\u7a0b\u7cfb\u5217\uff0c\u76ee\u524d\u5df2\u7ecf700+\u8ba2\u9605\uff0cCSDN\u6700\u5f3aJava\u4e13\u680f\uff0c\u5305\u542b\u5168\u90e8Java\u57fa\u7840\u77e5\u8bc6\u70b9\u3001Java8\u65b0\u7279\u6027\u3001Java\u96c6\u5408\u3001Java\u591a\u7ebf\u7a0b\u3001Java\u4ee3\u7801\u5b9e\u4f8b\uff0c\u7406\u8bba\u7ed3\u5408\u5b9e\u6218\uff0c\u5b9e\u73b0Java\u7684\u8f7b\u677e\u5b66\u4e60\u3002<\/p>\n \ud83c\udfc6\u59d0\u59b9\u7bc7\uff0cJava\u57fa\u7840\u6559\u7a0b\uff08\u5165\u95e8\u7bc7\uff09\uff0c\u5305\u542b\u9762\u5411\u5bf9\u8c61\u3001\u57fa\u672c\u6570\u636e\u7c7b\u578b\u3001\u6570\u7ec4\u3001\u7ee7\u627f\u548c\u591a\u6001\u3001\u6cdb\u578b\u3001\u679a\u4e3e\u7b49Java\u57fa\u7840\u77e5\u8bc6\u70b9\u3002<\/p>\n \ud83c\udfc6\u59d0\u59b9\u8fdb\u9636\u7bc7\uff0cJava\u57fa\u7840\u6559\u7a0b\uff08\u8fdb\u9636\u7bc7\uff09\uff0c\u5305\u542bJava\u9ad8\u5e76\u53d1\u3001Spring\u3001MySQL\u7b49Java\u8fdb\u9636\u6280\u672f\u6808\u3002<\/p>\n \ud83c\udfc6\u5168\u90e8\u8ba2\u9605\uff0c\u53ef\u52a0\u5165Java\u5b66\u4e60\u661f\u7403\uff0c\u5b8c\u6210Java\u4ece\u5165\u95e8\u3001\u5b9e\u6218\u3001\u8fdb\u9636\u5168\u65b9\u4f4d\u7684Java\u77e5\u8bc6\u4f53\u7cfb\u5b66\u4e60\u3002<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"redis\u9762\u8bd5\u9898\u603b\u7ed3\uff08\u9644\u7b54\u6848\uff09Redis\u4e2d\u95f4\u4ef6\u5b9e\u6218\u7cfb\u5217\uff0c\u6253\u9020\u7cbe\u54c1\u4e13\u680f\u3002_redis\u9762\u8bd5\u9898","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\/663"}],"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=663"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/663\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
\n\u4e00\u3001Redis\u662f\u4ec0\u4e48\uff1f<\/h2>\n
\u4e8c\u3001Redis\u90fd\u6709\u54ea\u4e9b\u4f7f\u7528\u573a\u666f\uff1f<\/h2>\n
\n
\u4e09\u3001Redis\u6709\u54ea\u4e9b\u529f\u80fd\uff1f<\/h2>\n
\u56db\u3001Redis\u652f\u6301\u7684\u6570\u636e\u7c7b\u578b\u6709\u54ea\u4e9b\uff1f<\/h2>\n
\n
\u4e94\u3001Redis\u53d6\u503c\u5b58\u503c\u95ee\u9898<\/h2>\n
JedisPool pool = new JedisPool(new JedisPoolConfig(),\"127.0.0.1\");\n \nJedis jedis = pool.getResource();<\/code><\/pre>\n
jedis.set(\"key\",\"value\");\njedis.get(\"key\");\njedis.del(\"key\");\n\/\/\u7ed9\u4e00\u4e2akey\u53e0\u52a0value\njedis.append(\"key\",\"value2\");\/\/\u6b64\u65f6key\u7684\u503c\u5c31\u662fvalue + value2;\n\/\/\u540c\u65f6\u7ed9\u591a\u4e2akey\u8fdb\u884c\u8d4b\u503c\uff1a\njedis.mset(\"key1\",\"value1\",\"key2\",\"value2\");<\/code><\/pre>\n
Map<String,String> user = new HashMap();\nuser.put(\"key1\",\"value1\");\nuser.put(\"key2\",\"value2\");\nuser.put(\"key3\",\"value3\");\n\/\/\u5b58\u5165\njedis.hmset(\"user\",user);\n\/\/\u53d6\u51fauser\u4e2dkey1 \nList<String> nameMap = jedis.hmget(\"user\",\"key1\");\n\/\/\u5220\u9664\u5176\u4e2d\u4e00\u4e2a\u952e\u503c\njedis.hdel(\"user\",\"key2\");\n\/\/\u662f\u5426\u5b58\u5728\u4e00\u4e2a\u952e\njedis.exists(\"user\");\n\/\/\u53d6\u51fa\u6240\u6709\u7684Map\u4e2d\u7684\u503c\uff1a\nIterator<String> iter = jedis.hkeys(\"user\").iterator();\nwhile(iter.next()){\n jedis.hmget(\"user\",iter.next());\n}<\/code><\/pre>\n
\u516d\u3001Redis\u4e3a\u4ec0\u4e48\u662f\u5355\u7ebf\u7a0b\u7684\uff1f<\/h2>\n
\n
\u4e03\u3001Redis\u771f\u7684\u662f\u5355\u7ebf\u7a0b\u7684\u5417\uff1f<\/h2>\n
redis\u5185\u90e8\u4f7f\u7528\u4e86\u57fa\u4e8eepoll\u7684\u591a\u8def\u670d\u7528\uff0c\u4e5f\u53ef\u4ee5\u591a\u90e8\u7f72\u51e0\u4e2aredis\u670d\u52a1\u5668\u89e3\u51b3\u5355\u7ebf\u7a0b\u7684\u95ee\u9898\uff1b
redis\u4e3b\u8981\u7684\u6027\u80fd\u74f6\u9888\u662f\u5185\u5b58\u548c\u7f51\u7edc\uff1b
\u5185\u5b58\u597d\u8bf4\uff0c\u52a0\u5185\u5b58\u6761\u5c31\u884c\u4e86\uff0c\u800c\u7f51\u7edc\u624d\u662f\u5927\u9ebb\u70e6\uff0c\u6240\u4ee5redis6\u5185\u5b58\u597d\u8bf4\uff0c\u52a0\u5185\u5b58\u6761\u5c31\u884c\u4e86\uff1b
\u800c\u7f51\u7edc\u624d\u662f\u5927\u9ebb\u70e6\uff0c\u6240\u4ee5redis6.0\u5f15\u5165\u4e86\u591a\u7ebf\u7a0b\u7684\u6982\u5ff5\uff0c
redis6.0\u5728\u7f51\u7edcIO\u5904\u7406\u65b9\u9762\u5f15\u5165\u4e86\u591a\u7ebf\u7a0b\uff0c\u5982\u7f51\u7edc\u6570\u636e\u7684\u8bfb\u5199\u548c\u534f\u8bae\u89e3\u6790\u7b49\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u6267\u884c\u547d\u4ee4\u7684\u6838\u5fc3\u6a21\u5757\u8fd8\u662f\u5355\u7ebf\u7a0b\u7684\u3002<\/p>\n\u516b\u3001Redis\u6301\u4e45\u5316\u6709\u51e0\u79cd\u65b9\u5f0f\uff1f<\/h2>\n
\u4e5d\u3001Redis\u548c memecache \u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/h2>\n
\u5341\u3001Redis\u652f\u6301\u7684 java \u5ba2\u6237\u7aef\u90fd\u6709\u54ea\u4e9b\uff1f<\/h2>\n
\u5341\u4e00\u3001jedis \u548c redisson \u6709\u54ea\u4e9b\u533a\u522b\uff1f<\/h2>\n
\u5341\u4e8c\u3001\u4ec0\u4e48\u662f\u7f13\u5b58\u7a7f\u900f\uff1f\u600e\u4e48\u89e3\u51b3\uff1f<\/h2>\n
\u5bf9\u4e00\u5b9a\u4e0d\u5b58\u5728\u7684key\u8fdb\u884c\u8fc7\u6ee4\u3002\u53ef\u4ee5\u628a\u6240\u6709\u7684\u53ef\u80fd\u5b58\u5728\u7684key\u653e\u5230\u4e00\u4e2a\u5927\u7684Bitmap\u4e2d\uff0c\u67e5\u8be2\u65f6\u901a\u8fc7\u8be5Bitmap\u8fc7\u6ee4\u3002<\/p>\n\n
\u5341\u4e09\u3001\u600e\u4e48\u4fdd\u8bc1\u7f13\u5b58\u548c\u6570\u636e\u5e93\u6570\u636e\u7684\u4e00\u81f4\u6027\uff1f<\/h2>\n
\n
public void write(String key,Object data){\n redisUtils.del(key);\n db.update(data);\n Thread.Sleep(100);\n redisUtils.del(key);\n}<\/code><\/pre>\n
\n
\u5341\u56db\u3001Redis\uff0c\u4ec0\u4e48\u662f\u7f13\u5b58\u7a7f\u900f\uff1f\u600e\u4e48\u89e3\u51b3\uff1f<\/h2>\n
\u5bf9\u4e00\u5b9a\u4e0d\u5b58\u5728\u7684key\u8fdb\u884c\u8fc7\u6ee4\u3002\u53ef\u4ee5\u628a\u6240\u6709\u7684\u53ef\u80fd\u5b58\u5728\u7684key\u653e\u5230\u4e00\u4e2a\u5927\u7684Bitmap\u4e2d\uff0c\u67e5\u8be2\u65f6\u901a\u8fc7\u8be5Bitmap\u8fc7\u6ee4\u3002<\/p>\n\n
\u5341\u4e94\u3001Redis\u600e\u4e48\u5b9e\u73b0\u5206\u5e03\u5f0f\u9501\uff1f<\/h2>\n
\/\/\u4f7f\u7528uuid\uff0c\u89e3\u51b3\u9501\u91ca\u653e\u7684\u95ee\u9898\n@GetMapping\npublic void testLock() throws InterruptedException {\n String uuid = UUID.randomUUID().toString();\n Boolean b_lock = redisTemplate.opsForValue().setIfAbsent(\"lock\", uuid, 10, TimeUnit.SECONDS);\n if(b_lock){\n Object value = redisTemplate.opsForValue().get(\"num\");\n if(StringUtils.isEmpty(value)){\n return;\n }\n int num = Integer.parseInt(value + \"\");\n redisTemplate.opsForValue().set(\"num\",++num);\n Object lockUUID = redisTemplate.opsForValue().get(\"lock\");\n if(uuid.equals(lockUUID.toString())){\n redisTemplate.delete(\"lock\");\n }\n }else{\n Thread.sleep(100);\n testLock();\n }\n}<\/code><\/pre>\n
\u5341\u516d\u3001Redis\u5206\u5e03\u5f0f\u9501\u6709\u4ec0\u4e48\u7f3a\u9677\uff1f<\/h2>\n
\n
\u5341\u4e03\u3001Redis\u5982\u4f55\u505a\u5185\u5b58\u4f18\u5316\uff1f<\/h2>\n
\n
\n
\uff0c\u4e13\u6ce8Java\u786c\u6838\u5e72\u8d27\u5206\u4eab\uff0c\u7acb\u5fd7\u505a\u5230Java\u8d5b\u9053\u5168\u7f51Top N\u3002<\/p>\n