{"id":644,"date":"2023-12-16T09:01:01","date_gmt":"2023-12-16T01:01:01","guid":{"rendered":""},"modified":"2023-12-16T09:01:01","modified_gmt":"2023-12-16T01:01:01","slug":"Redis \u7f13\u5b58\u51fb\u7a7f\uff0c\u7f13\u5b58\u7a7f\u900f\uff0c\u7f13\u5b58\u96ea\u5d29\u539f\u56e0+\u89e3\u51b3\u65b9\u6848","status":"publish","type":"post","link":"https:\/\/mushiming.com\/644.html","title":{"rendered":"Redis \u7f13\u5b58\u51fb\u7a7f\uff0c\u7f13\u5b58\u7a7f\u900f\uff0c\u7f13\u5b58\u96ea\u5d29\u539f\u56e0+\u89e3\u51b3\u65b9\u6848"},"content":{"rendered":"

\u4e00\u3001\u524d\u8a00<\/strong><\/span><\/span><\/strong><\/strong><\/span><\/h3>\n\n\n\n
\n

\u5728\u6211\u4eec\u65e5\u5e38\u7684\u5f00\u53d1\u4e2d\uff0c\u65e0\u4e0d\u90fd\u662f\u4f7f\u7528\u6570\u636e\u5e93\u6765\u8fdb\u884c\u6570\u636e\u7684\u5b58\u50a8\uff0c\u7531\u4e8e\u4e00\u822c\u7684\u7cfb\u7edf\u4efb\u52a1\u4e2d\u901a\u5e38\u4e0d\u4f1a\u5b58\u5728\u9ad8\u5e76\u53d1\u7684\u60c5\u51b5\uff0c\u6240\u4ee5\u8fd9\u6837\u770b\u8d77\u6765\u5e76\u6ca1\u6709\u4ec0\u4e48\u95ee\u9898\uff0c\u53ef\u662f\u4e00\u65e6\u6d89\u53ca\u5927\u6570\u636e\u91cf\u7684\u9700\u6c42\uff0c\u6bd4\u5982\u4e00\u4e9b\u5546\u54c1\u62a2\u8d2d\u7684\u60c5\u666f\uff0c\u6216\u8005\u662f\u4e3b\u9875\u8bbf\u95ee\u91cf\u77ac\u95f4\u8f83\u5927\u7684\u65f6\u5019\uff0c\u5355\u4e00\u4f7f\u7528\u6570\u636e\u5e93\u6765\u4fdd\u5b58\u6570\u636e\u7684\u7cfb\u7edf\u4f1a\u56e0\u4e3a\u9762\u5411\u78c1\u76d8\uff0c\u78c1\u76d8\u8bfb\/\u5199\u901f\u5ea6\u6bd4\u8f83\u6162\u7684\u95ee\u9898\u800c\u5b58\u5728\u4e25\u91cd\u7684\u6027\u80fd\u5f0a\u7aef\uff0c\u4e00\u77ac\u95f4\u6210\u5343\u4e0a\u4e07\u7684\u8bf7\u6c42\u5230\u6765\uff0c\u9700\u8981\u7cfb\u7edf\u5728\u6781\u77ed\u7684\u65f6\u95f4\u5185\u5b8c\u6210\u6210\u5343\u4e0a\u4e07\u6b21\u7684\u8bfb\/\u5199\u64cd\u4f5c\uff0c\u8fd9\u4e2a\u65f6\u5019\u5f80\u5f80\u4e0d\u662f\u6570\u636e\u5e93\u80fd\u591f\u627f\u53d7\u7684\uff0c\u6781\u5176\u5bb9\u6613\u9020\u6210\u6570\u636e\u5e93\u7cfb\u7edf\u762b\u75ea\uff0c\u6700\u7ec8\u5bfc\u81f4\u670d\u52a1\u5b95\u673a\u7684\u4e25\u91cd\u751f\u4ea7\u95ee\u9898\u3002<\/span><\/span><\/span><\/p>\n

\u4e3a\u4e86\u514b\u670d\u4e0a\u8ff0\u7684\u95ee\u9898\uff0c\u9879\u76ee\u901a\u5e38\u4f1a\u5f15\u5165NoSQL\u6280\u672f\uff0c\u8fd9\u662f\u4e00\u79cd\u57fa\u4e8e\u5185\u5b58\u7684\u6570\u636e\u5e93\uff0c\u5e76\u4e14\u63d0\u4f9b\u4e00\u5b9a\u7684\u6301\u4e45\u5316\u529f\u80fd\u3002<\/span><\/span><\/span><\/p>\n

redis\u6280\u672f\u5c31\u662fNoSQL\u6280\u672f\u4e2d\u7684\u4e00\u79cd\uff0c\u4f46\u662f\u5f15\u5165redis\u53c8\u6709\u53ef\u80fd\u51fa\u73b0\u7f13\u5b58\u7a7f\u900f\uff0c\u7f13\u5b58\u51fb\u7a7f\uff0c\u7f13\u5b58\u96ea\u5d29\u7b49\u95ee\u9898\u3002\u672c\u6587\u5c31\u5bf9\u8fd9\u4e09\u79cd\u95ee\u9898\u8fdb\u884c\u8f83\u6df1\u5165\u5256\u6790\u3002<\/span><\/span><\/span><\/p>\n

\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\n

\u4e8c\u3001\u521d\u8ba4\u8bc6<\/strong><\/span><\/span><\/strong><\/strong><\/span><\/h3>\n\n\n\n
\n
    \n
  • \u7f13\u5b58\u51fb\u7a7f\uff1akey\u5bf9\u5e94\u7684\u6570\u636e\u5b58\u5728\uff0c\u4f46\u5728redis\u4e2d\u8fc7\u671f\uff0c\u6b64\u65f6\u82e5\u6709\u5927\u91cf\u5e76\u53d1\u8bf7\u6c42\u8fc7\u6765\uff0c\u8fd9\u4e9b\u8bf7\u6c42\u53d1\u73b0\u7f13\u5b58\u8fc7\u671f\u4e00\u822c\u90fd\u4f1a\u4ece\u540e\u7aefDB\u52a0\u8f7d\u6570\u636e\u5e76\u56de\u8bbe\u5230\u7f13\u5b58\uff0c\u8fd9\u4e2a\u65f6\u5019\u5927\u5e76\u53d1\u7684\u8bf7\u6c42\u53ef\u80fd\u4f1a\u77ac\u95f4\u628a\u540e\u7aefDB\u538b\u57ae\u3002<\/span><\/span><\/li>\n
  • \u7f13\u5b58\u7a7f\u900f\uff1akey\u5bf9\u5e94\u7684\u6570\u636e\u5728\u6570\u636e\u6e90\u5e76\u4e0d\u5b58\u5728\uff0c\u6bcf\u6b21\u9488\u5bf9\u6b64key\u7684\u8bf7\u6c42\u4ece\u7f13\u5b58\u83b7\u53d6\u4e0d\u5230\uff0c\u8bf7\u6c42\u90fd\u4f1a\u5230\u6570\u636e\u6e90\uff0c\u4ece\u800c\u53ef\u80fd\u538b\u57ae\u6570\u636e\u6e90\u3002\u6bd4\u5982\u7528\u4e00\u4e2a\u4e0d\u5b58\u5728\u7684\u7528\u6237id\u83b7\u53d6\u7528\u6237\u4fe1\u606f\uff0c\u4e0d\u8bba\u7f13\u5b58\u8fd8\u662f\u6570\u636e\u5e93\u90fd\u6ca1\u6709\uff0c\u82e5\u9ed1\u5ba2\u5229\u7528\u6b64\u6f0f\u6d1e\u8fdb\u884c\u653b\u51fb\u53ef\u80fd\u538b\u57ae\u6570\u636e\u5e93\u3002<\/span><\/span><\/li>\n
  • \u7f13\u5b58\u96ea\u5d29\uff1a\u5f53\u7f13\u5b58\u670d\u52a1\u5668\u91cd\u542f\u6216\u8005\u5927\u91cf\u7f13\u5b58\u96c6\u4e2d\u5728\u67d0\u4e00\u4e2a\u65f6\u95f4\u6bb5\u5931\u6548\uff0c\u8fd9\u6837\u5728\u5931\u6548\u7684\u65f6\u5019\uff0c\u4e5f\u4f1a\u7ed9\u540e\u7aef\u7cfb\u7edf(\u6bd4\u5982DB)\u5e26\u6765\u5f88\u5927\u538b\u529b\u3002<\/span><\/span><\/li>\n<\/ul>\n

    \n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

    \n

    \n

    \u4e09<\/strong><\/span><\/span><\/strong>\u3001\u7f13\u5b58\u51fb\u7a7f\u89e3\u51b3\u65b9\u6848<\/strong><\/span><\/span><\/strong><\/strong><\/span><\/h3>\n\n\n\n
    \n

    key\u53ef\u80fd\u4f1a\u5728\u67d0\u4e9b\u65f6\u95f4\u70b9\u88ab\u8d85\u9ad8\u5e76\u53d1\u5730\u8bbf\u95ee\uff0c\u662f\u4e00\u79cd\u975e\u5e38\u201c\u70ed\u70b9\u201d\u7684\u6570\u636e\u3002\u8fd9\u4e2a\u65f6\u5019\uff0c\u9700\u8981\u8003\u8651\u4e00\u4e2a\u95ee\u9898\uff1a\u7f13\u5b58\u88ab\u201c\u51fb\u7a7f\u201d\u7684\u95ee\u9898\u3002<\/span><\/span><\/span><\/p>\n

    \u4f7f\u7528\u4e92\u65a5\u9501(mutex key)<\/span><\/span><\/strong><\/span><\/p>\n

    \u4e1a\u754c\u6bd4\u8f83\u5e38\u7528\u7684\u505a\u6cd5\uff0c\u662f\u4f7f\u7528mutex\u3002\u7b80\u5355\u5730\u6765\u8bf4\uff0c\u5c31\u662f\u5728\u7f13\u5b58\u5931\u6548\u7684\u65f6\u5019\uff08\u5224\u65ad\u62ff\u51fa\u6765\u7684\u503c\u4e3a\u7a7a\uff09\uff0c\u4e0d\u662f\u7acb\u5373\u53bbload db\uff0c\u800c\u662f\u5148\u4f7f\u7528\u7f13\u5b58\u5de5\u5177\u7684\u67d0\u4e9b\u5e26\u6210\u529f\u64cd\u4f5c\u8fd4\u56de\u503c\u7684\u64cd\u4f5c\uff08\u6bd4\u5982Redis\u7684SETNX\u6216\u8005Memcache\u7684ADD\uff09\u53bbset\u4e00\u4e2amutex key\uff0c\u5f53\u64cd\u4f5c\u8fd4\u56de\u6210\u529f\u65f6\uff0c\u518d\u8fdb\u884cload db\u7684\u64cd\u4f5c\u5e76\u56de\u8bbe\u7f13\u5b58\uff1b\u5426\u5219\uff0c\u5c31\u91cd\u8bd5\u6574\u4e2aget\u7f13\u5b58\u7684\u65b9\u6cd5\u3002<\/span><\/span><\/span><\/p>\n

    SETNX\uff0c\u662f\u300cSET if Not eXists\u300d\u7684\u7f29\u5199\uff0c\u4e5f\u5c31\u662f\u53ea\u6709\u4e0d\u5b58\u5728\u7684\u65f6\u5019\u624d\u8bbe\u7f6e\uff0c\u53ef\u4ee5\u5229\u7528\u5b83\u6765\u5b9e\u73b0\u9501\u7684\u6548\u679c\u3002<\/span><\/span><\/span><\/p>\n\n\n\n
    \n

    public String get(key) {
    \n <\/p>\n

          String value = redis.get(key);<\/p>\n

          if (value == null) { \/\/\u4ee3\u8868\u7f13\u5b58\u503c\u8fc7\u671f<\/p>\n

              \/\/\u8bbe\u7f6e3min\u7684\u8d85\u65f6\uff0c\u9632\u6b62del\u64cd\u4f5c\u5931\u8d25\u7684\u65f6\u5019\uff0c\u4e0b\u6b21\u7f13\u5b58\u8fc7\u671f\u4e00\u76f4\u4e0d\u80fdload db<\/p>\n

          if (redis.setnx(key_mutex, 1, 3 * 60) == 1) {  \/\/\u4ee3\u8868\u8bbe\u7f6e\u6210\u529f<\/p>\n

                   value = db.get(key);<\/p>\n

                          redis.set(key, value, expire_secs);<\/p>\n

                          redis.del(key_mutex);<\/p>\n

                  } else {  \/\/\u8fd9\u4e2a\u65f6\u5019\u4ee3\u8868\u540c\u65f6\u5019\u7684\u5176\u4ed6\u7ebf\u7a0b\u5df2\u7ecfload db\u5e76\u56de\u8bbe\u5230\u7f13\u5b58\u4e86\uff0c\u8fd9\u65f6\u5019\u91cd\u8bd5\u83b7\u53d6\u7f13\u5b58\u503c\u5373\u53ef<\/p>\n

                          sleep(50);<\/p>\n

                          get(key);  \/\/\u91cd\u8bd5<\/p>\n

                  }<\/p>\n

              } else {
    \n <\/p>\n

                  return value;      <\/p>\n

              }<\/p>\n

     }<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

    \n

    \n

    \u90a3\u4e48\u5728\u9ad8\u5e76\u53d1\u7684\u60c5\u51b5\u4e0b\uff0c\u4e00\u4e2a key \u8fc7\u671f\u4e86\uff0c\u7136\u540e\uff0c\u5c31\u662f\u51e0\u5343\u51e0\u4e07\u7684\u5e76\u53d1\u8702\u62e5\u800c\u81f3\uff0c\u8fd9\u8be5\u600e\u4e48\u89e3\u51b3\uff1f<\/span><\/span><\/p>\n

    \u5148\uff0c\u5927\u90e8\u5206\u4eba\u4f1a\u60f3\u5230\u8fd9\u4e48\u4e00\u4e2a\u7b54\u6848\uff1a\u70ed\u70b9\u6570\u636e\u6c38\u4e0d\u8fc7\u671f\u3002<\/span><\/span><\/span><\/p>\n

    \u5728\u7f51\u7edc\u4e0a\u76db\u884c\u7684\u89e3\u51b3\u65b9\u6848\u6709\u5f88\u591a\uff1a<\/span><\/span><\/span><\/p>\n

    \u8bbe\u7f6e key \u6c38\u4e0d\u8fc7\u671f\uff0c\u5728\u4fee\u6539\u6570\u636e\u5e93\u65f6\uff0c\u540c\u65f6\u66f4\u65b0\u7f13\u5b58\uff1b<\/span><\/span>
    \u540e\u53f0\u8d77\u4e00\u4e2a\u5b9a\u65f6\u4efb\u52a1\uff0c\u6bcf\u9694\u4e00\u6bb5\u65f6\u95f4\uff0c\u518d key \u5feb\u8981\u5931\u6548\u7684\u65f6\u5019\uff0c\u63d0\u524d\u5c06 key \u5237\u65b0\u4e3a\u6700\u65b0\u6570\u636e\uff1b<\/span><\/span>
    \u6bcf\u6b21\u83b7\u53d6 key \u90fd\u68c0\u67e5\uff0ckey \u8fd8\u6709\u591a\u4e45\u8fc7\u671f\uff0c\u5982\u679c\u5feb\u8fc7\u671f\uff0c\u5219\u66f4\u65b0\u8fd9\u4e2a key\uff1b<\/span><\/span>
    \u5206\u7ea7\u7f13\u5b58\uff0c\u4e00\u7ea7\u7f13\u5b58\u5931\u6548\uff0c\u8fd8\u6709\u4e8c\u7ea7\u7f13\u5b58\u57ab\u80cc\u3002<\/span><\/span>
    \u8fd9\u4e00\u7c7b\u7684\u56de\u7b54\u8fd8\u6709\u5f88\u591a\uff0c\u7edf\u79f0\u5f52\u7eb3\u8d77\u6765\uff0c\u5c31\u662f\u8ba9 redis \u7684\u7f13\u5b58\u4e0d\u8fc7\u671f\uff0c<\/span><\/span>
    \u666e\u904d\u7684\u505a\u6cd5\u5c31\u662f\uff1a<\/span><\/span><\/span><\/p>\n

    \u8bbe\u7f6e key \u6c38\u8fdc\u4e0d\u4f1a\u8fc7\u671f\uff1b<\/span><\/span>
    \u5728\u7f13\u5b58\u8fd8\u6ca1\u6709\u5931\u6548\u524d\uff0c\u5c31\u66f4\u65b0\u7f13\u5b58\u3002<\/span><\/span>
    \u5982\u679c\u4f60\u7ed9\u51fa\u8fc7\u8fd9\u6837\u7684\u7b54\u6848\uff0c\u90a3\u8bf4\u660e\u4f60\u5e94\u8be5\u6ca1\u6709\u5728\u5b9e\u9645\u7684\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u6ca1\u6709\u771f\u6b63\u78b0\u5230\u8fc7\uff0c\u4e14\u9700\u8981\u5904\u7406\u8fd9\u6837\u7684\u60c5\u51b5\uff0c<\/span><\/span>
    \u56e0\u4e3a\u786e\u5b9e\uff0c\u5b58\u5728\u7f13\u5b58\u51fb\u7a7f\u95ee\u9898\u7684\uff0c\u5149\u5e76\u53d1\u91cf\u7684\u8981\u6c42\uff0c\u5c31\u53ef\u4ee5\u6392\u9664\u6389 99% \u7684\u4f01\u4e1a\uff0c<\/span><\/span>
    \u6240\u4ee5\uff0c\u771f\u6b63\u6709\u5b9e\u9645\u573a\u666f\u7684\uff0c\u53bb\u8003\u8651\u89e3\u51b3\u7f13\u5b58\u51fb\u7a7f\u95ee\u9898\u7684\u4eba\uff0c\u5c11\u4e4b\u53c8\u5c11\u3002<\/span><\/span><\/span><\/p>\n

    \u6240\u4ee5\uff0c\u5927\u90e8\u5206\u4eba\uff0c\u90fd\u53ea\u662f\u505c\u7559\u4e8e\u7eb8\u4e0a\u8c08\u5175\u7684\u9636\u6bb5\uff0c\u6b63\u786e\u4e0e\u5426\uff0c\u6ca1\u6709\u5b9e\u9645\u573a\u666f\u7684\u9a8c\u8bc1\uff0c\u53ea\u80fd\u9760\u76f4\u89c9\u53bb\u5224\u65ad\uff1b<\/span><\/span>
    \u6216\u8005\uff0c\u6d4f\u89c8\u4e86\u5f88\u591a\u7684\u6587\u7ae0\u535a\u5ba2\uff0c\u53d1\u73b0\u4eba\u4eba\u90fd\u8fd9\u4e48\u8bf4\uff0c\u4fbf\u4e5f\u81ea\u7136\u800c\u7136\u8ba4\u4e3a\uff0c\u4e8b\u5b9e\u5c31\u662f\u8fd9\u4e48\u4e00\u56de\u4e8b\u3002<\/span><\/span><\/span><\/p>\n

    \u4e0b\u9762\u6211\u6765\u8be6\u7ec6\u5206\u6790\uff0c\u4e3a\u4ec0\u4e48\uff0c\u8fd9\u4e9b\u89e3\u51b3\u65b9\u6848\uff0c\u5728\u5b9e\u9645\u7684\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u662f\u65e0\u6cd5\u80dc\u4efb\u7684\u3002<\/span><\/span><\/span><\/p>\n

    \u9996\u5148\uff0c\u6211\u6765\u5206\u6790\uff0ckey \u6c38\u4e0d\u5931\u6548\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u4e3a\u4ec0\u4e48\u4e0d\u53ef\u884c\u3002<\/span><\/span><\/span><\/p>\n

    \u56e0\u4e3a\uff0c\u5bf9\u4e8e\u4e00\u4e2a\u9700\u8981\u89e3\u51b3\u7f13\u5b58\u51fb\u7a7f\u95ee\u9898\u7684\u4f01\u4e1a\uff0c\u4ed6\u4eec\u7684\u4e1a\u52a1\u91cf\u4e00\u5b9a\u662f\u666e\u901a\u4eba\u65e0\u6cd5\u60f3\u8c61\u548c\u4f01\u53ca\u7684\uff1b<\/span><\/span>
    \u6240\u4ee5\uff0c\u4ed6\u4eec\u7684\u6570\u636e\u91cf\u662f\u5de8\u5927\u7684\uff0c\u56e0\u800c\u9700\u8981\u7f13\u5b58\uff0c\u53bb\u4fdd\u7559\u70ed\u70b9\u6570\u636e\uff0c\u51cf\u8f7b\u6570\u636e\u5e93\u7684\u538b\u529b\uff1b<\/span><\/span>
    \u6240\u4ee5\u6839\u636e\u8fd9\u4e00\u70b9\u5c31\u53ef\u4ee5\u660e\u786e\uff0c\u4e0d\u5b58\u5728\u7f13\u5b58\u4e0d\u4f1a\u5931\u6548\u7684\u60c5\u51b5\u3002<\/span><\/span><\/span><\/p>\n

    \u4e3a\u4ec0\u4e48\u5462\uff1f<\/span><\/span>
    \u56e0\u4e3a\u6570\u636e\u7684\u91cf\u5de8\u5927\uff0c\u6211\u4eec\u7684 redis \u7f13\u5b58\uff0c\u662f\u57fa\u4e8e\u5185\u5b58\u7684\uff0c\u4e00\u4e2a\u5355\u70b9\uff0c\u4e00\u822c\u4e5f\u4e0d\u4f1a\u5206\u914d\u8fc7\u5927\u7684\u5185\u5b58\uff0c\u6765\u4fdd\u8bc1\u5b83\u8db3\u591f\u7075\u6d3b\u3002<\/span><\/span>
    \u4f46\u662f\uff0c\u5373\u4fbf\u662f\u96c6\u7fa4\uff0c\u6240\u80fd\u5b58\u50a8\u7684\u6570\u636e\u91cf\u4e5f\u662f\u6709\u9650\u7684\u3002redis \u4e0d\u53ef\u80fd\u628a\u6240\u6709\u7684\u6570\u636e\u5168\u90e8\u7f13\u5b58\u5165\u5185\u5b58\uff0c\u6ca1\u6709\u4ec0\u4e48\u4f01\u4e1a\u53ef\u4ee5\u8bf4\u7528\u5185\u5b58\u5c31\u53ef\u4ee5\u5b58\u50a8\u6240\u6709\u7684\u6570\u636e\u3002<\/span><\/span><\/span><\/p>\n

    \u4f46\u662f\uff0c\u4f60\u53ef\u4ee5\u8bf4\uff0c\u53ea\u5b58\u70ed\u70b9\u6570\u636e\u554a\uff01<\/span><\/span><\/span><\/p>\n

    \u4f46\u662f\uff0c\u4ec0\u4e48\u53eb\u70ed\u70b9\u6570\u636e\uff1f\u4f60\u89c9\u5f97\u662f\u5c31\u662f\u5417\uff1f<\/span><\/span><\/span><\/p>\n

    \u771f\u6b63\u7684\u73af\u5883\u4e2d\uff0c\u70ed\u70b9\u6570\u636e\u662f\u5728\u65f6\u65f6\u53d8\u5316\u7740\u7684\uff0c\u6211\u4eec\u53ef\u4ee5\u5bf9\u4e00\u4e9b\u70ed\u70b9\u505a\u4e00\u4e9b\u9884\u4f30\uff0c\u4f46\u662f\uff0c\u6211\u4eec\u6c38\u8fdc\u65e0\u6cd5\u4fdd\u8bc1\u6211\u4eec\u80fd\u9884\u4f30\u5230\u591a\u5c11\u3002<\/span><\/span>
    \u5728\u8fd9\u6837\u5343\u53d8\u4e07\u5316\u7684\u73af\u5883\u4e2d\uff0c\u4e00\u4e2a\u660e\u661f\u5e72\u4e86\u70b9\u4ec0\u4e48\u4e8b\uff0c\u5c31\u80fd\u6380\u8d77\u4f60\u65e0\u6cd5\u60f3\u8c61\u7684\u6d41\u91cf\uff1b<\/span><\/span>
    \u6bd4\u5982 xxx \u600e\u4e48\u600e\u4e48\u7684\u4e86\uff0c\u7136\u540e\u65b0\u6d6a\u5c31\u762b\u75ea\u4e86\uff0c\u4e5f\u4e0d\u662f\u6ca1\u6709\u7684\u4e8b\u3002<\/span><\/span>
    \u6240\u4ee5\uff0c\u6570\u636e\u662f\u6d41\u52a8\u7684\u3002<\/span><\/span>
    \u6240\u4ee5\u5728\u771f\u5b9e\u573a\u666f\u4e2d\u7684\u70ed\u70b9\u6570\u636e\uff0c\u662f\u7edd\u5bf9\u4e0d\u53ef\u80fd\u662f\u7531\u4eba\u53bb\u8bc4\u4f30\u7684\uff0c\u6240\u6709\u7684\u70ed\u70b9\u6570\u636e\uff0c\u90fd\u662f\u6839\u636e\u65f6\u65f6\u7684\u6d41\u91cf\uff0c\u7cfb\u7edf\u7f13\u5b58\u81ea\u52a8\u8fc7\u671f\u6389\u90a3\u4e00\u90e8\u5206\u5df2\u7ecf\u51b7\u95e8\u7684\u6570\u636e\uff0c\u7136\u540e\u53c8\u7f13\u5b58\u8d77\u65b0\u7684\u70ed\u70b9\u6570\u636e\u3002<\/span><\/span>
    \u6240\u4ee5\u8bf4\uff0c\u70ed\u70b9\u6570\u636e\uff0c\u4e00\u5b9a\u662f\u65f6\u65f6\u51fa\u73b0\uff0c\u65f6\u65f6\u6d88\u5931\u7684\uff0c\u6211\u4eec\u9760\u4eba\u7684\u5927\u8111\uff0c\u662f\u65e0\u6cd5\u76f4\u63a5\u5224\u65ad\u51fa\u6240\u6709\u5728\u67d0\u4e2a\u65f6\u95f4\u70b9\u4f1a\u51fa\u73b0\u7684\u70ed\u70b9\u6570\u636e\u3002<\/span><\/span>
    \u6240\u4ee5\u8fd9\u5fc5\u987b\u7531\u6211\u4eec\u7684\u7cfb\u7edf\uff0c\u80fd\u591f\u76f4\u63a5\u53bb\u5e94\u5bf9\u6570\u636e\u7684\u53d8\u5316\uff0c\u5728\u5de8\u91cf\u6570\u636e\u7684\u6d41\u52a8\u4e2d\u627e\u5230\u5e73\u8861\u3002<\/span><\/span>
    \u6240\u4ee5\uff0c\u6211\u4eec\u7684 redis \u7f13\u5b58\uff0c\u4e5f\u4e0d\u53ef\u80fd\u8ba9 key \u6c38\u8fdc\u4e0d\u4f1a\u8fc7\u671f\u3002<\/span><\/span>
    \u6240\u4ee5\uff0credis \u4e5f\u4e0d\u662f\u4f60\u60f3\u8ba9\u5b83\u5b58\u4e00\u4e9b\u4e0d\u8fc7\u671f\u7684\u6570\u636e\u5c31\u884c\u7684\uff0c\u7531\u4e8e\u70ed\u70b9\u6570\u636e\u7684\u4e0d\u65ad\u53d8\u52a8\uff0credis \u5fc5\u987b\u5728\u65f6\u523b\u6dd8\u6c70\u65e7\u7684\u6570\u636e\uff0c\u7f13\u5b58\u5165\u65b0\u7684\u6570\u636e\u3002<\/span><\/span><\/span><\/p>\n

    \u7b2c\u4e8c\u4e2a\uff0c\u7f51\u7edc\u4e0a\u5f88\u6d41\u884c\u7684\u7b54\u6848\u5c31\u662f\uff1a\u52a0\u9501<\/span><\/span><\/span><\/p>\n

    synchronized \u52a0\u9501\uff0c\u800c\u4e14\u8fd8\u884d\u751f\u51fa\u53cc\u91cd\u68c0\u67e5\u9501\uff1b<\/span><\/span>
    ReentrantLock.tryLock()\uff0c\u7f13\u5b58\u6ca1\u6709\uff0c\u5c1d\u8bd5\u52a0\u9501\uff0c\u62a2\u4e0d\u5230\u5c31\u7761\u4e00\u4f1a\uff0c\u62a2\u5230\u7684\u90a3\u4e00\u4e2a\u67e5\u6570\u636e\u5e93\uff1b<\/span><\/span>
    redis \u7684\u547d\u4ee4 setnx()\uff0c\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u8bbe\u7f6e\u6210\u529f\uff0c\u4e5f\u5c31\u662f\u80fd\u52a0\u5230\u9501\uff0c\u53ea\u6709\u52a0\u5230\u9501\u4e86\uff0c\u624d\u8bfb\u6570\u636e\u5e93\uff0c\u7136\u540e\u5b58\u4f1a redis \u91cc\uff0c\u5176\u5b83\u5219\u7b49\u5f85\u4e00\u4f1a\uff0c\u7136\u540e\u518d\u53bb redis \u53d6\u3002<\/span><\/span>
    \u5176\u5b9e\u52a0\u9501\u786e\u5b9e\u662f\u53ef\u4ee5\u89e3\u51b3\u7684\uff0c<\/span><\/span>
    \u4f46\u662f\uff0c\u5982\u679c\u4f60\u8981\u662f\u5199\u4e86 synchronized\uff0c\u90a3\u4f60\u4e00\u5b9a\u4f1a\u88ab\u76f4\u63a5\u7092\u9c7f\u9c7c\u3002<\/span><\/span>
    \u8fd9\u79cd\u90fd\u662f\u4e25\u91cd\u7684\u95ee\u9898\uff0c\u4f1a\u4f7f\u4f60\u7684\u7cfb\u7edf\u53ef\u80fd\u5c31\u762b\u4e86\u3002<\/span><\/span><\/span><\/p>\n

    \u9996\u5148\uff0c\u5bf9\u4e8e\u7f13\u5b58\u7a7f\u900f\u7684\u60c5\u51b5\uff0c\u80af\u5b9a\u662f\u9ad8\u5e76\u53d1\u573a\u666f\uff0c\u6240\u4ee5\u6570\u636e\u5e93\u624d\u53ef\u80fd\u625b\u4e0d\u4f4f\u3002<\/span><\/span>
    \u6240\u4ee5\uff0c\u67e5\u8be2 redis\uff0c\u6216\u8005 mysql \u7684\uff0c\u4e00\u5b9a\u4e0d\u53ef\u80fd\u662f\u5355\u53f0 tomcat \u8fdb\u7a0b\u3002<\/span><\/span><\/span><\/p>\n

    \u6240\u4ee5\uff0c\u5728\u5982\u6b64\u591a\u7684 Tomcat \u96c6\u7fa4\u7684\u60c5\u51b5\u4e0b\uff0c\u4e00\u628a Java \u9501\uff0c\u662f\u4e0d\u53ef\u80fd\u9501\u4f4f\u4e00\u4e2a\u96c6\u7fa4\u7684\u3002<\/span><\/span>
    \u800c\u4e14\uff0csynchronized \u4e00\u4f46\u52a0\u9501\uff0c\u662f\u4e0d\u53ef\u64a4\u9500\u7684\uff0c\u5b83\u4e0d\u50cf ReentrantLock \u90a3\u6837\uff0c\u53ef\u4ee5 tryLock\uff0c\u52a0\u4e0d\u5230\u9501\u4e5f\u53ef\u4ee5\u8fd4\u56de\u3002<\/span><\/span>
    \u6240\u4ee5\uff0c\u4e00\u4f46\u4f7f\u7528\u4e86 synchronized \u52a0\u9501\uff0c\u4f1a\u4f7f\u5f97\u6240\u6709\u7684\u8bfb redis \u7f13\u5b58\u4e5f\u52a0\u9501\u3002<\/span><\/span>
    \u8bfb\u8bf7\u6c42\u52a0\u4e92\u65a5\u9501\u7edd\u5bf9\u662f\u81f4\u547d\u7684\uff0c\u8fd9\u4e2a\u7cfb\u7edf\u7edd\u5bf9\u662f\u4e00\u542f\u52a8\u5c31\u88ab\u6d41\u91cf\u51fb\u57ae\u3002<\/span><\/span><\/span><\/p>\n

    \u867d\u7136\u8bf4\uff0c\u7528 ReentrantLock\uff0ctryLock \u52a0\u9501\uff0c\u6210\u529f\u7684\u53bb\u6570\u636e\u5e93\u8bfb\u53d6\u6570\u636e\uff1b<\/span><\/span>
    \u800c\u90a3\u4e9b\u5931\u8d25\u7684\uff0c\u5219\u7761\u7720\u4e00\u6bb5\u65f6\u95f4\uff0c\u518d\u91cd\u65b0\u53bb\u7f13\u5b58\u8bfb\u53d6\uff0c<\/span><\/span>
    \u8fd9\u4e2a\u6d41\u7a0b\u5df2\u7ecf\u5f00\u59cb\u50cf\u5b9e\u9645\u7684\u89e3\u51b3\u65b9\u6848\u4e86\u3002<\/span><\/span><\/span><\/p>\n

    \u4f46\u662f\uff0c\u4e00\u4e2a Java \u9501\u6700\u591a\u53ea\u80fd\u591f\u9501\u4e00\u4e2a JVM \u8fdb\u7a0b\uff0c\u5bf9\u4e8e\u4e00\u4e2a\u96c6\u7fa4\u6765\u8bf4\uff0c\u8fd9\u7edd\u5bf9\u662f\u8fdc\u8fdc\u4e0d\u591f\u7684\u3002<\/span><\/span>
    \u800c\u4e14\uff0c\u53bb redis \u91cc\u8bfb\u53d6\u6570\u636e\u7684\uff0c\u53ef\u80fd\u4e0d\u4ec5\u4ec5\u53ea\u662f Java \u8fdb\u7a0b\uff0c\u50cf Nginx \u4e5f\u80fd\u76f4\u63a5\u8bbf\u95ee redis\u3001mysql\uff0c\u662f\u4e0d\u662f\u6709\u70b9\u8d85\u51fa\u4f60\u7684\u8ba4\u77e5\uff1f<\/span><\/span>
    \u5982\u679c\u4f60\u7684\u89e3\u51b3\u65b9\u6848\u4ec5\u4ec5\u662f\u4e00\u628a Java \u9501\uff0c\u90a3\u4e48\u7edd\u5bf9\u8fbe\u4e0d\u5230\u751f\u4ea7\u73af\u5883\u7684\u8981\u6c42\u3002<\/span><\/span><\/span><\/p>\n

    \u6240\u4ee5\u5b9e\u9645\u4e0a\uff0c\u7f13\u5b58\u7a7f\u900f\uff0c\u52a0\u9501\u89e3\u51b3\uff0c\u5fc5\u987b\u8fd8\u8981\u6d89\u53ca\u5230\u5206\u5e03\u5f0f\u9501\u7684\u6982\u5ff5\u3002<\/span><\/span><\/span><\/p>\n

    \u8fd9\u91cc\u4e0d\u8c08 zookeeper \u4e4b\u7c7b\u7684\u4e1c\u897f\uff0c\u65e2\u7136\u8c08 redis\uff0c\u90a3\u4e48\u5c31\u7528 redis \u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<\/span><\/span><\/span><\/p>\n

    \u9996\u5148\uff0c\u5f53\u4e00\u4e2a key \u5931\u6548\uff0c\u4e0d\u7ba1\u662f\u65f6\u95f4\u8fc7\u671f\uff0c\u8fd8\u662f\u88ab LRU\u3001LFU \u5254\u9664\uff0c<\/span><\/span>
    \u5047\u8bbe\u4f1a\u6709 1w \u4e2a\u5e76\u53d1\u6765\u8bbf\u95ee\u8fd9\u4e2a key\uff0c\u90a3\u4e48\u5b83\u4eec\u5c31\u4f1a\u5148\u67e5\u8be2 redis\uff0c\u7136\u540e\u90fd\u53d1\u73b0\uff0c\u8fd9\u4e2a key \u4e0d\u5b58\u5728\uff1b<\/span><\/span>
    \u7136\u540e\uff0c\u5b83\u4eec\u5c31\u4f1a\u5bf9\u5e94\u7684\uff0c\u5f80 redis \u7528 setnx \u8bbe\u7f6e\u4e00\u4e2a key\uff0c\u6765\u8868\u793a\u8fd9\u662f\u4e00\u628a\u9501\uff1b<\/span><\/span>
    \u7136\u540e\uff0c\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\uff0c\u4f1a\u8bbe\u7f6e\u6210\u529f\uff0c\u7136\u540e\u53bb\u8bfb\u53d6\u6570\u636e\u5e93\uff0c\u5199\u56de redis\uff1b<\/span><\/span>
    \u5176\u4ed6\u7684 9999 \u4e2a\u7ebf\u7a0b\uff0c\u5219 sleep \u4e00\u5c0f\u4f1a\uff0c\u7136\u540e\u518d\u53bb\u8bbf\u95ee\u6211\u4eec\u7684 redis\u3002<\/span><\/span>
    \u6709\u4eba\u770b\u5230\u8fd9\uff0c\u9996\u5148\u4f1a\u95ee\uff0c\u8fd9\u4e2a sleep \u8981\u591a\u4e45\uff1f<\/span><\/span>
    \u8fd9\u4e2a\u662f\u8981\u6839\u636e\u538b\u6d4b\uff0c\u4ee5\u53ca\u7ebf\u4e0a\u73af\u5883\u8fdb\u884c\u8c03\u6574\u7684\uff0c\u4e00\u822c\u4f1a\u7ed9\u51fa\u4e00\u4e2a\u5408\u9002\u7684\u503c\uff0c\u4e5f\u5c31\u662f\u5927\u7ea6\u4ece\u6570\u636e\u5e93\u53d6\u51fa\u6570\u636e\u7684\u65f6\u95f4\u3002<\/span><\/span>
    \u6240\u4ee5\uff0c\u6b63\u5e38\u60c5\u51b5\u662f\u4e0d\u4f1a\u51fa\u73b0\u5927\u9762\u79ef\u957f\u65f6\u95f4\u7b49\u5f85\u7684\u60c5\u51b5\u7684\u3002<\/span><\/span><\/span><\/p>\n

    \"Redis  <\/p>\n

    \u770b\u8d77\u6765\u4f3c\u4e4e\u53ef\u884c\uff0c\u4f46\u662f\uff0c\u8fd8\u6709\u95ee\u9898\u5417\uff1f<\/span><\/span><\/span><\/p>\n

    \u6211\u8981\u8fd9\u4e48\u8bf4\u80af\u5b9a\u662f\u6709\u95ee\u9898\uff0c\u4f46\u662f\uff0c\u4f60\u53ef\u4ee5\u60f3\u4e00\u60f3\uff0c\u5b58\u5728\u4ec0\u4e48\u95ee\u9898\uff1f<\/span><\/span><\/span><\/p>\n

    \u5982\u679c\u4f60\u4e0d\u77e5\u9053\uff0c\u8bf4\u660e\u5bf9\u5206\u5e03\u5f0f\u9501\u8fd8\u4e0d\u591f\u4e86\u89e3\uff0c\u90a3\u4e48\uff0c\u5c31\u7ee7\u7eed\u8ddf\u7740\u6211\u5206\u6790\u3002<\/span><\/span><\/span><\/p>\n

    \u73b0\u5728\uff0c\u6211\u5f00\u59cb\u5047\u8bbe\uff1a<\/span><\/span><\/span><\/p>\n

    \u9996\u5148\uff0c\u4e00\u5806\u8bf7\u6c42\u8bbf\u95ee redis\uff0c\u53d1\u73b0\u4e3a\u7a7a\uff1b<\/span><\/span>
    \u7136\u540e\uff0c\u8fd9\u4e00\u5806\u5e76\u53d1\u5f00\u59cb\u5c1d\u8bd5\u52a0\u9501\uff0c\u6700\u7ec8\u53ea\u6709\u4e00\u4e2a\u4eba\uff0c\u83b7\u53d6\u5230\u4e86\u9501\uff0c\u5176\u5b83\u4eba\u90fd\u5931\u8d25\uff1b<\/span><\/span>
    \u7136\u540e\uff0c\u6301\u6709\u9501\u7684\u673a\u5668\uff0c\u65ad\u7535\u4e86\uff1b<\/span><\/span>
    \u5176\u4ed6\u4eba\uff0c\u4e00\u76f4\u7b49\u7740\uff0c\u4f46\u662f\u59cb\u7ec8\u6ca1\u6709\u4eba\u7b49\u5230\u9501\u88ab\u91ca\u653e\uff0c\u6216\u8005 redis \u88ab\u91cd\u65b0\u5b58\u5165\u8be5\u6570\u636e\u3002<\/span><\/span>
    \u8fd9\u662f\u4e00\u4e2a\u5206\u5e03\u5f0f\u9501\u6700\u5e38\u89c1\u7684\u95ee\u9898\uff0c\u5c31\u662f\u52a0\u9501\u8fdb\u7a0b\u6b7b\u4ea1\uff0c\u5bfc\u81f4\u9501\u65e0\u6cd5\u88ab\u91ca\u653e\u3002<\/span><\/span>
    \u4e8e\u662f\u5c31\u4ea7\u751f\u4e86\u6b7b\u9501\u95ee\u9898\u3002<\/span><\/span><\/span><\/p>\n

    \"Redis
    \u73b0\u5728\uff0c\u65e2\u7136\u51fa\u73b0\u4e86\u95ee\u9898\uff0c\u90a3\u4e48\uff0c\u6211\u4eec\u4e00\u5b9a\u5f97\u60f3\u529e\u6cd5\u53bb\u89e3\u51b3\u3002<\/span><\/span><\/span><\/p>\n

     <\/p>\n

    \u9996\u5148\uff0c\u5bf9\u4e8e\u6211\u4eec\u7684\u5206\u5e03\u5f0f\u96c6\u7fa4\u7cfb\u7edf\uff0c\u4efb\u610f\u4e00\u53f0\u673a\u5668\u90fd\u6709\u6302\u6389\u7684\u53ef\u80fd\u3002<\/span><\/span>
    \u6240\u4ee5\uff0c\u6211\u4eec\u9996\u5148\u8981\u660e\u786e\u7684\u601d\u8def\u5c31\u662f\uff0c\u5982\u4f55\u5728\u52a0\u9501\u8fdb\u7a0b\u6b7b\u4ea1\u7684\u60c5\u51b5\u4e0b\uff0c\u53bb\u91ca\u653e\u8fd9\u4e2a\u9501\u3002<\/span><\/span><\/span><\/p>\n

    \u53ef\u4ee5\u60f3\u5230\u4e24\u79cd\u65b9\u6848\uff1a<\/span><\/span>
    \u7b2c\u4e00\uff1a<\/span><\/span>
    \u5c31\u662f\u53e6\u8d77\u4e00\u4e2a\u96c6\u7fa4\uff0c\u8d1f\u8d23\u4e13\u95e8\u76d1\u7ba1\u9501\u7684\u83b7\u53d6\u548c\u91ca\u653e\uff1b<\/span><\/span>
    \u4e00\u4f46\u6301\u6709\u9501\u7684\u8fdb\u7a0b\u5b95\u673a\uff0c\u76d1\u7ba1\u96c6\u7fa4\u5c31\u8d1f\u8d23\u5c06\u6b7b\u9501\u7ed9\u91ca\u653e\u3002<\/span><\/span><\/span><\/p>\n

    \u660e\u663e\uff0c\u8fd9\u4e48\u505a\u6210\u672c\u6bd4\u8f83\u9ad8\u6602\uff0c\u8fd8\u4e0d\u5982\u7528\u5b8c\u5584\u7684 zookeeper \u53bb\u5b9e\u73b0\u5206\u5e03\u5f0f\u9501\u3002<\/span><\/span><\/span><\/p>\n

    \u7b2c\u4e8c\u79cd\uff1a<\/span><\/span>
    \u5c31\u662f\u5e73\u65f6\u6bd4\u8f83\u5e38\u89c1\u7684\uff0c\u7528 redis \u7684\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\uff0c\u6765\u4fdd\u8bc1\uff0c\u5373\u4f7f\u5b95\u673a\uff0c\u9501\u4e5f\u80fd\u5728\u8d85\u65f6\u8fc7\u540e\u81ea\u52a8\u91ca\u653e\u3002<\/span><\/span><\/span><\/p>\n

    \u4e8e\u662f\uff0c\u4e4b\u524d\u7684\u65b9\u6848\uff0c\u5c31\u53ef\u4ee5\u7a0d\u4f5c\u4fee\u6539\uff1a<\/span><\/span><\/span><\/p>\n

    \u9996\u5148\uff0c\u4e00\u5806\u5e76\u53d1\u5f00\u59cb\u5c1d\u8bd5\u52a0\u9501\uff0c\u6700\u7ec8\u53ea\u6709\u4e00\u4e2a\u4eba\uff0c\u83b7\u53d6\u5230\u4e86\u9501\uff0c\u5176\u5b83\u4eba\u90fd\u5931\u8d25\uff1b<\/span><\/span>
    \u7136\u540e\uff0c\u9501\u88ab\u8bbe\u7f6e\u4e0a\u8fc7\u671f\u65f6\u95f4\uff0c\u4fdd\u8bc1\u65e0\u8bba\u5982\u4f55\u4e00\u5b9a\u4f1a\u88ab\u91ca\u653e\uff1b<\/span><\/span>
    \u7136\u540e\uff0c\u6301\u6709\u9501\u7684\u673a\u5668\uff0c\u65ad\u7535\u6302\u4e86\u3002\u3002\u3002\uff1b<\/span><\/span>
    \u5176\u4ed6\u4eba\uff0c\u7b49\u4e86\u4e00\u4f1a\uff0c\u53d1\u73b0\u9501\u53c8\u6ca1\u4e86\uff0c\u4e8e\u662f\u91cd\u65b0\u5f00\u59cb\u4e4b\u524d\u7684\u64cd\u4f5c\u3002<\/span><\/span><\/span><\/p>\n

    \"Redis
    \u770b\u8d77\u6765\u5f88\u5b8c\u7f8e\u3002<\/span><\/span><\/span><\/p>\n

     <\/p>\n

    \u4f46\u662f\uff0c\u8fd8\u6709\u95ee\u9898\u5417\uff1f<\/span><\/span><\/span><\/p>\n

    \u6211\u8981\u8fd9\u4e48\u95ee\u4e86\uff0c\u90a3\u4e48\u4e00\u5b9a\u8bf4\u660e\u6709\u3002<\/span><\/span><\/span><\/p>\n

    \u90a3\u4e48\uff0c\u73b0\u5728\u8bf7\u4f60\u5148\u4e0d\u8981\u62d6\u5230\u540e\u6587\uff0c\u5148\u81ea\u5df1\u601d\u8003\uff0c\u4f1a\u5b58\u5728\u4ec0\u4e48\u95ee\u9898\uff0c\u7136\u540e\u518d\u6765\u770b\u6211\u7684\u5206\u6790\u3002<\/span><\/span><\/span><\/p>\n

    \u73b0\u5728\u6211\u7ee7\u7eed\u5217\u51fa\u573a\u666f\uff0c<\/span><\/span>
    \u5047\u8bbe\uff1a<\/span><\/span><\/span><\/p>\n

    \u9996\u5148\uff0c\u4e00\u5806\u5e76\u53d1\u5f00\u59cb\u5c1d\u8bd5\u52a0\u9501\uff0c\u6700\u7ec8\u53ea\u6709\u4e00\u4e2a\u4eba\uff0c\u83b7\u53d6\u5230\u4e86\u9501\uff0c\u5176\u5b83\u4eba\u90fd\u5931\u8d25\uff1b<\/span><\/span>
    \u7136\u540e\uff0c\u6301\u6709\u9501\u7684\u4eba\u8fd8\u6ca1\u6765\u5f97\u53ca\u8bbe\u7f6e\u9501\u7684\u8fc7\u671f\u65f6\u95f4\uff0c\u5c31\u6302\u4e86\u3002\u3002\u3002<\/span><\/span>
    \u5176\u4ed6\u4eba\uff0c\u4e00\u76f4\u7b49\u7740\uff0c\u4f46\u662f\u59cb\u7ec8\u6ca1\u6709\u4eba\u7b49\u5230\u9501\u88ab\u91ca\u653e\uff0c\u6216\u8005 redis \u88ab\u91cd\u65b0\u5b58\u5165\u8be5\u6570\u636e\uff0c\u53c8\u662f\u6b7b\u9501\u3002<\/span><\/span>
    \u65e2\u7136\u95ee\u9898\u6765\u4e86\uff0c\u6211\u4eec\u5c31\u9700\u8981\u60f3\u529e\u6cd5\uff0c\u53bb\u52a0\u4ee5\u89e3\u51b3\u3002<\/span><\/span><\/span><\/p>\n

    \u9996\u5148\uff0c\u53ef\u4ee5\u786e\u5b9a\u7684\u662f\uff0c\u53ef\u80fd\u9501\u6ca1\u6709\u6765\u5f97\u53ca\u589e\u52a0\u8fc7\u671f\u65f6\u95f4\uff0c\u4ece\u800c\u5bfc\u81f4\uff0c\u53ef\u80fd\u51fa\u73b0\u6b7b\u9501\u7684\u60c5\u51b5\u3002<\/span><\/span>
    \u56e0\u4e3a\uff0c\u4e4b\u524d\u7684\u8bbe\u7f6e\u9501\u3001\u548c\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\uff0c\u662f\u4e24\u6b65\u64cd\u4f5c\uff0c\u4e0d\u662f\u539f\u5b50\u7684\u3002<\/span><\/span><\/span><\/p>\n

    \u6709\u4e9b\u4eba\u53ef\u80fd\u5c31\u4f1a\u8bf4\uff0c\u90a3\u5c31\u653e\u4e00\u4e2a\u539f\u5b50\u64cd\u4f5c\u554a\uff01<\/span><\/span><\/span><\/p>\n

    \u4f46\u662f\uff0credis \u5e76\u6ca1\u6709\u4e00\u4e2a API\uff0c\u65e2\u53ef\u4ee5 setnx\uff0c\u53c8\u540c\u65f6\u7ed9\u4e88\u5b83\u4e00\u4e2a\u8fc7\u671f\u65f6\u95f4\u3002<\/span><\/span><\/span><\/p>\n

    \u90a3\u8be5\u600e\u4e48\u529e\uff1f<\/span><\/span><\/span><\/p>\n

    \u6240\u4ee5\uff0c\u8fd9\u5c31\u9700\u8981\u8003\u9a8c\uff0c\u6211\u4eec\u5bf9 redis \u7684\u5404\u79cd\u673a\u5236\u7684\u638c\u63e1\u7a0b\u5ea6\u4e86\u3002<\/span><\/span><\/span><\/p>\n

    \u9996\u5148\uff0credis \u6709\u4e8b\u52a1\u8fd9\u4e48\u4e00\u4e2a\u6982\u5ff5\uff0c<\/span><\/span>
    \u4e0d\u8fc7\uff0credis \u7684\u4e8b\u52a1\u4e0d\u50cf mysql \u90a3\u6837\uff0c\u53ef\u4ee5\u652f\u6301\u56de\u6eda\u3002<\/span><\/span><\/span><\/p>\n

    \u90a3\u4e48\u4e0d\u80fd\u56de\u6eda\u7684\u4e8b\u52a1\u4e5f\u53ef\u4ee5\u7528\u6765\u5b8c\u6210\u9501\u64cd\u4f5c\u5417\uff1f<\/span><\/span><\/span><\/p>\n

    \u867d\u7136\u4e0d\u652f\u6301\u56de\u6eda\uff0c\u4f46\u662f\u4e3b\u8981\u662f\u56e0\u4e3a redis \u7684\u4e8b\u52a1\u662f\u4fdd\u8bc1\u539f\u5b50\u6027\u7684\uff1a<\/span><\/span>
    \u4e8b\u52a1\u4e2d\u7684\u547d\u4ee4\u8981\u4e48\u5168\u90e8\u88ab\u6267\u884c\uff0c\u8981\u4e48\u5168\u90e8\u90fd\u4e0d\u6267\u884c\u3002<\/span><\/span>
    \u5982\u679c\u5ba2\u6237\u7aef\u5728\u4f7f\u7528 MULTI \u5f00\u542f\u4e86\u4e00\u4e2a\u4e8b\u52a1\u4e4b\u540e\uff0c\u5374\u56e0\u4e3a\u65ad\u7ebf\u800c\u6ca1\u6709\u6210\u529f\u6267\u884c EXEC \uff0c\u90a3\u4e48\u4e8b\u52a1\u4e2d\u7684\u6240\u6709\u547d\u4ee4\u90fd\u4e0d\u4f1a\u88ab\u6267\u884c\u3002<\/span><\/span>
    \u53e6\u4e00\u65b9\u9762\uff0c\u5982\u679c\u5ba2\u6237\u7aef\u6210\u529f\u5728\u5f00\u542f\u4e8b\u52a1\u4e4b\u540e\u6267\u884c EXEC \uff0c\u90a3\u4e48\u4e8b\u52a1\u4e2d\u7684\u6240\u6709\u547d\u4ee4\u90fd\u4f1a\u88ab\u6267\u884c\u3002<\/span><\/span><\/span><\/p>\n

    \u5728\u4e00\u4e2a\u4e8b\u52a1\u4e2d\uff0c\u53ea\u6709\u5168\u90e8\u7684\u547d\u4ee4\u53d1\u9001\u7ed3\u675f\u4e86\uff0c\u5e76\u4e14\u63d0\u4ea4\u4e8b\u52a1\uff0c\u90a3\u4e48\u6574\u4e2a\u4e8b\u52a1\u4e2d\u7684\u6240\u6709\u6307\u4ee4\uff0c\u624d\u4f1a\u88ab redis \u6267\u884c\uff1b<\/span><\/span>
    \u4e5f\u5c31\u662f\u8bf4\uff0c\u5728\u5c1d\u8bd5\u53bb\u7ed9 redis \u7684\u4e00\u4e2a key\uff0c\u52a0\u9501\uff0c\u53ea\u8981\u4e0d\u6700\u7ec8 EXEC \u89e6\u53d1\u4e8b\u52a1\uff0c\u90a3\u4e48\u8fd9\u4e9b\u65b9\u6cd5\u5c31\u6c38\u8fdc\u4e0d\u4f1a\u88ab\u6267\u884c\uff1b<\/span><\/span>
    \u90a3\u4e5f\u5c31\u662f\uff0c\u8981\u662f EXEC \u89e6\u53d1\u4e8b\u52a1\u6267\u884c\uff0c\u5c31\u4e00\u5b9a\u4f1a\u6267\u884c\u52a0\u9501\u548c\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\u7684\u547d\u4ee4\u3002<\/span><\/span>
    \u5426\u5219\uff0c\u6ca1\u6709 EXEC\uff0c\u5c31\u4e24\u6761\u6307\u4ee4\u90fd\u4e0d\u4f1a\u6267\u884c\u3002<\/span><\/span><\/span><\/p>\n

    \u8fd9\u6837\uff0c\u5c31\u53ef\u4ee5\u4fdd\u8bc1\uff0credis \u4e0d\u4f1a\u51fa\u73b0\u6b7b\u9501\u7684\u95ee\u9898\u3002<\/span><\/span><\/span><\/p>\n

    \u8fd9\u6837\uff0c\u89e3\u51b3\u4e86\u6b7b\u9501\u95ee\u9898\uff0c\u5c31\u770b\u8d77\u6765\u5f88\u5b8c\u7f8e\u4e86\u3002<\/span><\/span><\/span><\/p>\n

    \u4f46\u662f\uff0c<\/span><\/span>
    \u8fd9\u6837\u5c31\u53ef\u4ee5\u4e86\u5417\uff1f<\/span><\/span><\/span><\/p>\n

    \u786e\u5b9e\uff0c\u5982\u679c\u53ea\u662f\u89e3\u51b3\u4e86\u6b7b\u9501\u7684\u95ee\u9898\u7684\u60c5\u51b5\u4e0b\uff0c\u662f\u6ca1\u6709\u4ec0\u4e48\u95ee\u9898\u7684\u3002<\/span><\/span><\/span><\/p>\n

    \u4f46\u662f\uff0c\u56e0\u4e3a\u6211\u4eec\u5728\u89e3\u51b3\u6b7b\u9501\u95ee\u9898\u7684\u65f6\u5019\uff0c\u5f15\u5165\u4e86\u8d85\u65f6\u65f6\u95f4\uff0c\u6240\u4ee5\uff0c\u5c31\u4f1a\u5bfc\u81f4\u65b0\u7684\u95ee\u9898\u7684\u4ea7\u751f\u3002<\/span><\/span>
    \u6211\u4eec\u5728\u89e3\u51b3\u4e00\u4e2a\u95ee\u9898\u7684\u65f6\u5019\uff0c\u5f80\u5f80\u4f1a\u5f15\u5165\u65b0\u7684\u95ee\u9898\u3002<\/span><\/span><\/span><\/p>\n

    \u73b0\u5728\uff0c\u5047\u8bbe\uff1a<\/span><\/span><\/span><\/p>\n

    \u9996\u5148\uff0c\u4e00\u5806\u5e76\u53d1\u5f00\u59cb\u5c1d\u8bd5\u52a0\u9501\uff0c\u6700\u7ec8\u53ea\u6709\u4e00\u4e2a\u4eba\uff0c\u83b7\u53d6\u5230\u4e86\u9501\uff0c\u4e14\u8bbe\u7f6e\u4e86\u8d85\u65f6\u65f6\u95f4\uff1b<\/span><\/span>
    \u7136\u540e\uff0c\u6301\u6709\u9501\u7684\u7ebf\u7a0b\uff0c\u5f00\u59cb\u8fdb\u884c\u8bfb\u6570\u636e\u5e93\u7684\u64cd\u4f5c\uff1b<\/span><\/span>
    \u4f46\u662f\uff0c\u7531\u4e8e\u5404\u79cd\u4e0d\u786e\u5b9a\u56e0\u7d20\uff0c\u5b83\u8fd9\u6b21\u8bfb\u6570\u636e\u5e93\u8bfb\u5f97\u5f88\u6162\uff0c\u6240\u4ee5\u8fd8\u6ca1\u7ed3\u675f\uff0c\u9501\u5c31\u8d85\u65f6\u91ca\u653e\u4e86\uff1b<\/span><\/span>
    \u7136\u540e\uff0c\u7b2c\u4e8c\u4e2a\u7ebf\u7a0b\u4e5f\u62ff\u4e86\u4e00\u4e2a\u9501\uff0c\u5f00\u59cb\u5b83\u7684\u64cd\u4f5c\uff1b<\/span><\/span>
    \u7136\u540e\uff0c\u7b2c\u4e00\u4e2a\u7ebf\u7a0b\u7ed3\u675f\u4e86\uff0c\u8fd9\u65f6\uff0c\u672c\u8be5\u6240\u6709\u5176\u4ed6\u7ebf\u7a0b\u53ef\u4ee5\u8bbf\u95ee\u6570\u636e\u5e93\u4e86\uff0c\u4f46\u662f\uff0c\u7531\u4e8e\u7b2c\u4e8c\u4e2a\u7ebf\u7a0b\u53bb\u52a0\u4e86\u9501\uff0c\u5bfc\u81f4\u73b0\u5728\u5b83\u4eec\u5f97\u989d\u5916\u7ee7\u7eed\u7b49\u5230\u7b2c\u4e8c\u4e2a\u7ebf\u7a0b\u53bb\u91ca\u653e\uff1b<\/span><\/span>
    \u8fd9\u6837\uff0c\u5c31\u4f1a\u589e\u52a0\u4e86\u7b49\u5f85\u65f6\u95f4\uff0c\u54cd\u5e94\u5ef6\u8fdf\u5c31\u4f1a\u589e\u5927\uff0c\u5982\u679c\uff0c\u518d\u591a\u51e0\u6b21\u52a0\u9501\u8fc7\u7a0b\uff0c\u54cd\u5e94\u5ef6\u8fdf\u5c31\u4f1a\u8d8a\u53d1\u4e25\u91cd\uff0c\u6216\u8005\u76f4\u63a5\u8d85\u65f6\u65ad\u5f00\u3002<\/span><\/span><\/span>
    \"Redis
    \u6240\u4ee5\uff0c\u5728\u8bbe\u7f6e\u9501\u7684\u8d85\u65f6\u65f6\u95f4\u7684\u65f6\u5019\uff0c\u8be5\u600e\u4e48\u8bbe\u7f6e\uff1f<\/span><\/span>
    \u8bbe\u7f6e\u77ed\u4e00\u70b9\uff1f<\/span><\/span>
    \u90a3\u5c31\u4f1a\u5f88\u5bb9\u6613\u53d1\u751f\u9501\u88ab\u522b\u4eba\u53c8\u62a2\u8fc7\u53bb\u7684\u60c5\u51b5\uff1b<\/span><\/span>
    \u90a3\u8bbe\u7f6e\u957f\u4e00\u70b9\uff1f<\/span><\/span>
    \u90a3\u4e48\u5c31\u53c8\u53ef\u80fd\u4f7f\u5f97\u963b\u585e\u65f6\u95f4\u53d8\u957f\u3002<\/span><\/span><\/span><\/p>\n

     <\/p>\n

    \u6240\u4ee5\uff0c\u9501\u7684\u8d85\u65f6\u65f6\u95f4\u53c8\u6210\u4e86\u95ee\u9898\u3002<\/span><\/span><\/span><\/p>\n

    \u65e2\u7136\u65b0\u95ee\u9898\u51fa\u73b0\u4e86\uff0c\u6211\u4eec\u5c31\u5f97\u60f3\u529e\u6cd5\u53bb\u89e3\u51b3\u5b83\u3002<\/span><\/span><\/span><\/p>\n

    \u800c\u73b0\u5728\u666e\u904d\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u5c31\u662f\u591a\u7ebf\u7a0b\uff1a<\/span><\/span><\/span><\/p>\n

    \u5728\u52a0\u9501\u4e86\u4e4b\u540e\uff0c\u7531\u4e8e\u9501\u4f1a\u6709\u8fc7\u671f\u65f6\u95f4\uff0c\u7136\u800c\u53c8\u4e0d\u80fd\u4fdd\u8bc1\uff0c\u9501\u4e00\u5b9a\u4e0d\u4f1a\u5728\u6267\u884c\u7ed3\u675f\u8fc7\u540e\u8fc7\u671f\uff0c<\/span><\/span>
    \u90a3\u4e48\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u91c7\u7528\u591a\u7ebf\u7a0b\u7684\u65b9\u6848\uff0c\u8ba9\u9501\u6bcf\u9694\u4e00\u5b9a\u65f6\u95f4\uff0c\u5c31\u91cd\u65b0\u8bbe\u7f6e\u5b83\u7684\u8d85\u65f6\u65f6\u95f4\u3002<\/span><\/span><\/span><\/p>\n

    \u4e8e\u662f\u5c31\u51fa\u73b0\u4e0b\u9762\u8fd9\u6837\u7684\u573a\u666f\uff1a<\/span><\/span><\/span><\/p>\n

    \u9996\u5148\uff0c\u4e00\u4e2a\u624b\u901f\u5feb\u7684\u5bb6\u4f19\u62a2\u5230\u4e86\u9501\uff0c\u5e76\u4e14\u4e5f\u8bbe\u7f6e\u4e86\u8d85\u65f6\u65f6\u95f4\uff0c\u6bd4\u5982 30 \u79d2\u3002<\/span><\/span>
    \u7136\u540e\uff0c\u4e00\u4e2a\u7ebf\u7a0b\u6267\u884c\u4e1a\u52a1\u64cd\u4f5c\uff1b\u53c8\u53e6\u8d77\u4e00\u4e2a\u7ebf\u7a0b\uff0c\u53bb\u76d1\u7ba1\u9501\u7684\u65f6\u95f4\uff1b<\/span><\/span>
    \u5047\u8bbe\uff0c\u8fd9\u4e2a\u4e1a\u52a1\u505a\u8d77\u6765\u6bd4\u8f83\u6f2b\u957f\uff0c\u8fc7\u4e86 10 \u79d2\u8fd8\u6ca1\u7ed3\u675f\uff1b<\/span><\/span>
    \u4e8e\u662f\uff0c\u76d1\u63a7\u7ebf\u7a0b\u611f\u89c9\u4e0d\u5999\uff0c\u4e8e\u662f\u5c06\u8fc7\u671f\u65f6\u95f4\u53c8\u91cd\u65b0\u8bbe\u7f6e\u6210\u4e86 30 \u79d2\uff1b<\/span><\/span>
    \u4e1a\u52a1\u7ee7\u7eed\u6267\u884c\u7740\uff0c\u7136\u540e\u53c8\u8fc7\u4e86 10 \u79d2\uff0c\u9501\u7684\u8fc7\u671f\u65f6\u95f4\u8fd8\u5269 20 \u79d2\uff1b<\/span><\/span>
    \u4e8e\u662f\uff0c\u76d1\u63a7\u7ebf\u7a0b\u53c8\u611f\u89c9\u4e0d\u5999\uff0c\u4e8e\u662f\u5c06\u8fc7\u671f\u65f6\u95f4\u518d\u4e00\u6b21\u91cd\u65b0\u8bbe\u7f6e\u6210\u4e86 30 \u79d2\uff1b<\/span><\/span>
    \u5468\u800c\u590d\u59cb\uff0c\u53ea\u8981\u4e1a\u52a1\u6ca1\u505a\u5b8c\uff0c\u9501\u5c31\u4e0d\u4f1a\u8fc7\u671f\uff1b<\/span><\/span>
    \u5047\u8bbe 1\uff0c\u8fdb\u7a0b\u6302\u4e86\uff0c\u7136\u540e\uff0c30 \u79d2\u4e00\u5230\uff0c\u9501\u88ab\u91ca\u653e\uff1b<\/span><\/span>
    \u5047\u8bbe 2\uff0c\u4e1a\u52a1\u6267\u884c\u5b8c\u4e86\uff0c\u4e8e\u662f\u7ebf\u7a0b\u4e3b\u52a8\u91ca\u653e\u9501\u3002<\/span><\/span>
    \u4e8e\u662f\uff0c\u591a\u7ebf\u7a0b\u7684\u6280\u672f\uff0c\u5c31\u628a\u8fd9\u4e2a\u7f13\u5b58\u7a7f\u900f\u7684\u65b9\u6848\u7ed9\u89e3\u51b3\u4e86\u3002<\/span><\/span><\/span><\/p>\n

    \"Redis
    \u662f\u4e0d\u662f\u89c9\u5f97\u5de8\u9ebb\u70e6\uff0c\u7adf\u7136\u8981\u4ece\u5934\u5230\u5c3e\u7ecf\u5386\u8fd9\u4e48\u591a\u7684\u8fc7\u7a0b\uff0c\u624d\u80fd\u6700\u7ec8\uff0c\u5b9e\u73b0\u4e00\u4e2a\u4e0d\u8d77\u773c\u7684\u7f13\u5b58\u7a7f\u900f\uff01<\/span><\/span><\/span><\/p>\n

     <\/p>\n

    \u4e0d\u8fc7\uff0c\u5b9e\u9645\u4e0a\u4f60\u518d\u7ec6\u60f3\uff0c\u5176\u5b9e\uff0c\u6211\u4e0a\u9762\u63d0\u53ca\u7684\u5404\u79cd\u95ee\u9898\u548c\u89e3\u51b3\u65b9\u6848\uff0c\u90fd\u523b\u610f\u56de\u907f\u4e86\u4e00\u4e2a\u95ee\u9898\uff1a<\/span><\/span>
    \u5c31\u662f\uff0credis \u662f\u5355\u8282\u70b9\u5355\u5b9e\u4f8b\u7684\u3002<\/span><\/span><\/span><\/p>\n

    \u4e5f\u5c31\u662f\u8bf4\uff0c\u6211\u4eec\u5bf9\u8fd9\u4e00\u4e2a key \u7684\u64cd\u4f5c\uff0c\u90fd\u662f\u5728\u4e00\u4e2a redis \u4e0a\uff0c\u800c\u6ca1\u6709\u540c\u65f6\u7275\u626f\u5230\u5176\u4ed6 redis\uff1b<\/span><\/span>
    \u6240\u4ee5\uff0c\u53ea\u8981\u8fd9\u4e2a redis \u4e0d\u6302\uff0c\u90a3\u4e48\u5c31\u4e0d\u5b58\u5728\u95ee\u9898\u3002<\/span><\/span><\/span><\/p>\n

    \u4e0d\u8fc7\u8981\u662f redis \u6302\u4e86\uff0c\u90a3\u4e48\u9762\u4e34\u7684\u95ee\u9898\uff0c\u4e5f\u5c31\u4e0d\u662f redis \u7684\u7f13\u5b58\u51fb\u7a7f\u95ee\u9898\u4e86\u3002<\/span><\/span>
    \u800c\u662f\u7cfb\u7edf\u7684\u9ad8\u53ef\u7528\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u6bd4\u5982\u6211\u4e0a\u4e00\u7bc7\u6587\u7ae0\u63d0\u5230\u7684\uff1a<\/span><\/span>
    redis \u7684\u4e3b\u4ece\u3001\u4e3b\u5907\uff0c\u54e8\u5175\u76d1\u63a7\uff0c\u6765\u4fdd\u8bc1 redis \u6302\u4e86\u4e4b\u540e\uff0c\u80fd\u7acb\u523b\u6709 redis \u524d\u6765\u66ff\u8865\u3002<\/span><\/span><\/span><\/p>\n

    \u6587\u7ae0\u6307\u5f15>><\/span><\/span>
    \u4e0d\u4e3a\u6280\u672f\u800c\u6280\u672f\uff1aRedis \u4ece\u5355\u70b9\u5230\u96c6\u7fa4<\/span><\/span><\/span><\/p>\n

    \u56e0\u4e3a\u540e\u9762\u7684\u8fd9\u4e9b\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5bf9\u96c6\u7fa4\u6709\u76f8\u5173\u7684\u77e5\u8bc6\uff0c\u6240\u4ee5\uff0c\u6211\u4e5f\u5f88\u5efa\u8bae\uff0c\u4f60\u53ef\u4ee5\u770b\u4e00\u4e0b\u6211\u7684\u8fd9\u4e00\u7bc7\u6587\u7ae0\u3002<\/span><\/span>
    \u4f60\u4e5f\u53ef\u4ee5\u5148\u770b\u540e\u9762\u7684\uff0c\u7136\u540e\u770b\u5b8c\u540e\uff0c\u53bb\u770b\u6211\u4e4b\u524d\u7684\u8fd9\u4e00\u7bc7\u6587\u7ae0\uff0c\u505a\u4e00\u6b21\u77e5\u8bc6\u7684\u6574\u5408\u548c\u7406\u89e3\uff0c\u7136\u540e\u518d\u56de\u8fc7\u5934\u6765\u770b\u5230\u8fd9\u91cc\uff0c\u4e5f\u8bb8\u4f60\u53c8\u4f1a\u6709\u4e0d\u4e00\u6837\u7684\u611f\u89c9\u3002<\/span><\/span><\/span><\/p>\n

    \u4e0d\u8fc7\uff0c\u5373\u4f7f\u662f\u4e3b\u4ece\u6a21\u578b\uff0c\u5141\u8bb8 redis \u7684\u4ece\u8282\u70b9\u4e5f\u63d0\u4f9b\u8bfb\u670d\u52a1\uff0c<\/span><\/span>
    \u8fd9\u6837\u5c31\u4f1a\u5b58\u5728\u6570\u636e\u5728\u4e00\u5b9a\u65f6\u95f4\u5185\u4e0d\u4e00\u81f4\u7684\u60c5\u51b5\uff0c\u90a3\u4e48\u5176\u5b9e\u4e5f\u6ca1\u6709\u592a\u5927\u7684\u95ee\u9898\u3002<\/span><\/span><\/span><\/p>\n

    \u5047\u8bbe\uff1a<\/span><\/span><\/span><\/p>\n

    \u7b2c\u4e00\u4e2a\u7ebf\u7a0b\uff0c\u62a2\u5230\u4e86\u9501\uff0c\u7136\u540e\u8bbf\u95ee\u5b8c\u6570\u636e\u5e93\uff0c\u5c06\u6570\u636e\u5199\u56de\u4e3b\u7ed3\u70b9\uff1b<\/span><\/span>
    \u7136\u540e\uff0c\u5176\u5b83\u7ebf\u7a0b\u53bb\u4ece\u7ed3\u70b9\u8bfb\u53d6\uff0c\u7531\u4e8e\u53ef\u80fd\u6570\u636e\u540c\u6b65\u7684\u4e0d\u53ca\u65f6\uff0c\u5bfc\u81f4\u4e00\u90e8\u5206\u7ed3\u70b9\u8bfb\u51fa\u7684\u6570\u636e\u8fd8\u662f\u7a7a\uff1b<\/span><\/span>
    \u4e8e\u662f\uff0c\u90a3\u4e9b\u8bfb\u540c\u6b65\u4e0d\u53ca\u65f6\u7684\u90a3\u90e8\u5206\u4ece\u8282\u70b9\u7684\u7ebf\u7a0b\uff0c\u518d\u91cd\u590d\u4e00\u904d\u4e4b\u524d\u7684\u64cd\u4f5c\uff1b<\/span><\/span>
    \u8fd9\u6837\uff0c\u5c31\u53ef\u80fd\u51fa\u73b0\u90e8\u5206\u7ebf\u7a0b\u7684\u5f80\u590d\u591a\u6b21\u64cd\u4f5c\uff0c\u4e00\u76f4\u8bfb\uff0c\u4e00\u76f4\u662f\u7a7a\u3002<\/span><\/span>
    \u5982\u679c\u4ece\u8282\u70b9\u591a\u7684\u8bdd\uff0c\u90a3\u4e48\u6240\u6709\u7684\u4ece\u8282\u70b9\u4e4b\u4e2d\uff0c\u81f3\u5c11\u5927\u90e8\u5206\u4ece\u7ed3\u70b9\uff0c\u90fd\u662f\u901a\u4fe1\u6b63\u5e38\u7684\uff0c<\/span><\/span>
    \u4e00\u822c\u4e0d\u4f1a\u51fa\u73b0\u5927\u9762\u79ef\u574f\u6b7b\u7684\u60c5\u51b5\uff1b<\/span><\/span>
    \u6240\u4ee5\uff0c\u5982\u679c\u6709\u5c11\u91cf\u4ece\u8282\u70b9\u6ca1\u6709\u6570\u636e\uff0c\u90a3\u4e48\u4f1a\u5bfc\u81f4\u7684\u4e8c\u6b21\u91cd\u65b0\u64cd\u4f5c\uff0c\u4e5f\u53ea\u662f\u5c11\u91cf\u7684\u4e00\u90e8\u5206\u7ebf\u7a0b\uff0c\u8fd9\u6837\uff0c\u4e5f\u53ea\u662f\u518d\u6b21\u52a0\u9501\u4e00\u6b21\uff0c\u591a\u8bfb\u53d6\u4e86\u4e00\u6b21\u6570\u636e\u5e93\u3002<\/span><\/span><\/span><\/p>\n

    \u7136\u800c\u5b9e\u9645\u4e0a\uff0c\u4e5f\u6839\u672c\u5e76\u4e0d\u7528\u90a3\u4e48\u9ebb\u70e6\uff0c\u5047\u8bbe\u4ece\u8282\u70b9\u6ca1\u6709\u8bfb\u53d6\u5230\uff0c\u53ef\u4ee5\u76f4\u63a5\u53bb\u4e3b\u8282\u70b9\u8bfb\u53d6\uff0c\u90a3\u4e48\u5c31\u4e0d\u4f1a\u51fa\u73b0\u6570\u636e\u8fdf\u8fdf\u8bfb\u53d6\u4e0d\u5230\u7684\u60c5\u51b5\u4e86\u3002<\/span><\/span>
    \u4e5f\u5c31\u662f\uff0c\u5bf9\u4e8e\u8fd9\u6837\u7684\u52a0\u9501\u64cd\u4f5c\uff0c\u6ca1\u6709\u5fc5\u8981\u8981\u53bb\u6d89\u53ca\u5230\u4ece\u8282\u70b9\uff0c\u6240\u6709\u7684\u9501\u64cd\u4f5c\uff0c\u76f4\u63a5\u5bf9\u4e3b\u8282\u70b9\u5373\u53ef\u3002<\/span><\/span><\/span><\/p>\n

    \u6240\u4ee5\u8bf4\uff0c\u901a\u8fc7\u53cc\u7ebf\u7a0b\u7684\u52a0\u9501\u64cd\u4f5c\uff0c\u662f\u53ef\u4ee5\u89e3\u51b3\u7f13\u5b58\u51fb\u7a7f\u7684\u95ee\u9898\u7684\u3002<\/span><\/span><\/span><\/p>\n

    \u4e0d\u8fc7\uff0c\u7531\u4e8e\u6211\u5728\u4e0a\u6587\uff0c\u63d0\u5230\u4e86\u8fd9\u662f\u4e00\u4e2a\u5206\u5e03\u5f0f\u9501\u7684\u6982\u5ff5\uff0c<\/span><\/span>
    \u8981\u662f\uff0c\u6211\u5728\u8fd9\u91cc\uff0c\u4ec5\u4ec5\u5c31\u8fd9\u4e48\u7ed3\u675f\u7684\u8bdd\uff0c\u96be\u514d\u4f1a\u6709\u540c\u5fd7\u8bef\u4ee5\u4e3a\u8fd9\u5c31\u5df2\u7ecf\u662f\u4e00\u4e2a\u5b8c\u7f8e\u7684\u5206\u5e03\u5f0f\u9501\uff0c<\/span><\/span>
    \u6240\u4ee5\uff0c\u6211\u518d\u7a0d\u5fae\u63d0\u4e00\u4e0b\uff0credis \u96c6\u7fa4\u7684\u5206\u5e03\u5f0f\u9501\u7684\u77e5\u8bc6\u70b9\u3002<\/span><\/span><\/span><\/p>\n

    \u5bf9\u4e8e\u5355\u4e2a redis \u6765\u8bf4\uff0c\u4e0a\u9762\u7684\u77e5\u8bc6\u70b9\u5df2\u7ecf\u53ef\u4ee5\u5b9e\u73b0\u5206\u5e03\u5f0f\u9501\u4e86\u3002<\/span><\/span><\/span><\/p>\n

    \u4f46\u662f\uff0c\u65e2\u7136\u8981\u8ba8\u8bba\u9ad8\u5e76\u53d1\u9ad8\u53ef\u7528\u7684\u7cfb\u7edf\uff0c\u5c31\u4f1a\u6d89\u53ca\u5230\u96c6\u7fa4\u3002<\/span><\/span><\/span><\/p>\n

    \u5bf9\u4e8e\u5355\u4e2a redis \u6765\u8bf4\uff0c\u5047\u8bbe\uff0c\u52a0\u9501\u7684 redis \u6302\u4e86\uff0c\u90a3\u8be5\u600e\u4e48\u529e\uff1f<\/span><\/span><\/span><\/p>\n

    redis \u7684\u4e3b\u4ece\u6a21\u578b\uff0c\u9ed8\u8ba4\u4f7f\u7528\u5f02\u6b65\u540c\u6b65\u6570\u636e\u7684\u65b9\u5f0f\uff0c\u6240\u4ee5\uff0c\u5b58\u5728\u6570\u636e\u4e0d\u4e00\u81f4\u7684\u60c5\u51b5\uff0c<\/span><\/span>
    \u4e3b\u8282\u70b9\u6302\u4e86\uff0c\u4ece\u8282\u70b9\u9876\u66ff\u7684\u65f6\u5019\uff0c\u662f\u53ef\u80fd\u4e22\u5931\u6570\u636e\u7684\uff0c<\/span><\/span><\/span><\/p>\n

    \u6240\u4ee5\uff0c\u8fd9\u628a\u9501\u5f88\u53ef\u80fd\u5c31\u4e22\u4e86\u3002<\/span><\/span><\/span><\/p>\n

    \u4e3a\u4e86\u80fd\u591f\u89e3\u51b3\u8fd9\u6837\u7684\u95ee\u9898\uff0cRedis \u7684\u4f5c\u8005 antirez \u7ed9\u51fa\u4e86\u4e00\u4e2a\u66f4\u597d\u7684\u5b9e\u73b0\uff0c\u79f0\u4e3a Redlock\uff0c\u7b97\u662f Redis \u5b98\u65b9\u5bf9\u4e8e\u5b9e\u73b0\u5206\u5e03\u5f0f\u9501\u7684\u6307\u5bfc\u89c4\u8303\u3002<\/span><\/span><\/span><\/p>\n

    \u5982\u679c\u4f60\u4eec\u4e0d\u5584\u4e8e\u9605\u8bfb\u82f1\u6587\uff0c\u90a3\u4e48\u5c31\u76f4\u63a5\u770b\u6211\u4e2d\u6587\u7684\u63cf\u8ff0\uff1a<\/span><\/span><\/span><\/p>\n

    \u5728\u7b97\u6cd5\u7684\u5206\u5e03\u5f0f\u7248\u672c\u4e2d\uff0c\u6211\u4eec\u5047\u8bbe\u6709 N \u4e2a redis\uff0c\u4e14\u8fd9\u4e9b\u8282\u70b9\u662f\u5b8c\u5168\u72ec\u7acb\u7684\uff0c\u4e5f\u5c31\u662f\u4e0d\u5b58\u5728\u4efb\u4f55\u4e3b\u4ece\u5173\u7cfb\uff0c\u4e00\u4e2a redis \u7684\u6b7b\u6d3b\u548c\u5176\u4ed6 redis \u6ca1\u6709\u4efb\u4f55\u5173\u7cfb\u3002<\/span><\/span><\/span><\/p>\n

    \u90a3\u4e48\uff0c\u63a5\u4e0b\u6765\uff0c\u5c31\u8bf7\u601d\u8003\u4e00\u4e0b\uff0c\u52a0\u9501\u7684\u64cd\u4f5c\uff1a<\/span><\/span>
    \u9996\u5148\uff0c\u65e2\u7136\u662f\u5206\u5e03\u5f0f\u9501\uff0c\u90a3\u4e48\u5c31\u4e0d\u80fd\u53ea\u5bf9\u5355\u53f0\u7ed3\u70b9\u52a0\u9501\uff0c\u56e0\u4e3a\u4e0a\u9762\u5df2\u7ecf\u63cf\u8ff0\u8fc7\u4e86\uff0c\u4e00\u4f46\u8be5\u7ed3\u70b9\u5b95\u673a\uff0c\u5c31\u53ef\u80fd\u4f1a\u4f7f\u5f97\u9501\u4e22\u5931\uff0c\u56e0\u6b64\uff0c\u5b58\u5728\u5355\u70b9\u6545\u969c\u7684\u95ee\u9898\u3002<\/span><\/span>
    \u6240\u4ee5\uff0c\u5c31\u5fc5\u987b\u5bf9\u96c6\u7fa4\u4e2d\u7684\u591a\u4e2a\u7ed3\u70b9\u52a0\u9501\u3002<\/span><\/span><\/span><\/p>\n

    \u90a3\u4e48\uff0c\u5e94\u8be5\u7ed9\u51e0\u53f0\u7ed3\u70b9\u52a0\u9501\u5462\uff1f<\/span><\/span><\/span><\/p>\n

    \u5982\u679c\u91c7\u7528\u5168\u90e8\u7ed3\u70b9\u52a0\u9501\u6210\u529f\uff0c\u624d\u8868\u793a\u52a0\u9501\u6210\u529f\uff0c\u90a3\u4e48\u5c31\u6210\u4e86\u5f3a\u4e00\u81f4\u6027\uff0c<\/span><\/span>
    \u5982\u679c\u4f60\u9605\u8bfb\u8fc7\u6211\u7684\u300aRedis\u4ece\u5355\u70b9\u5230\u96c6\u7fa4\u300b\u8fd9\u7bc7\u6587\u7ae0\uff0c\u5e94\u8be5\u80fd\u660e\u767d\uff0c\u5f3a\u4e00\u81f4\u6027\uff0c\u4f1a\u5bf9\u53ef\u7528\u6027\u4ea7\u751f\u51b2\u51fb\uff0c\u56e0\u800c\u4e0d\u9002\u5408\u91c7\u53d6\u8fd9\u6837\u7684\u65b9\u5f0f\u3002<\/span><\/span><\/span><\/p>\n

    \u90a3\u4e48\u5e94\u8be5\u7ed9\u51e0\u4e2a\u7ed3\u70b9\u52a0\u9501\u6210\u529f\uff0c\u624d\u8868\u793a\u52a0\u9501\u6210\u529f\u5462\uff1f<\/span><\/span>
    \u5728 Redlock \u7684\u5b9e\u73b0\u4e2d\uff0c\u52a0\u9501\u7684 redis \u7ed3\u70b9\uff0c\u53ea\u8981\u6ee1\u8db3\uff0cN\/2+1\uff0c\u4e5f\u5c31\u662f\u8fc7\u534a\uff0c\u5373\u4ee3\u8868\u52a0\u9501\u6210\u529f\u3002<\/span><\/span>
    \u4e3a\u4ec0\u4e48\u8981\u8fc7\u534a\u5462\uff1f<\/span><\/span>
    \u56e0\u4e3a\u8fc7\u534a\u624d\u80fd\u4fdd\u8bc1\uff0c\u771f\u6b63\u52a0\u9501\u6210\u529f\u7684\uff0c\u53ea\u6709\u4e00\u4e2a\u3002<\/span><\/span>
    \u8fc7\u534a\u53c8\u4e0d\u8981\u6c42\u5168\u90e8\uff0c\u8fd9\u6837\uff0c\u4fdd\u8bc1\u4e86\u6301\u6709\u9501\u7684\u552f\u4e00\u6027\uff0c\u5e76\u4e14\u4e5f\u4fdd\u8bc1\u4e86\u96c6\u7fa4\u7684\u53ef\u7528\u6027\u8db3\u591f\u597d\u3002<\/span><\/span><\/span><\/p>\n

    \u90a3\u4e48\u65e2\u7136\u6700\u57fa\u7840\u7684\u95ee\u9898\u89e3\u51b3\u4e86\uff0c\u4e0b\u9762\uff0c\u5047\u8bbe\u51fa\u73b0\u8fd9\u4e48\u4e00\u4e2a\u573a\u666f\uff1a<\/span><\/span>
    \u5047\u8bbe\uff0cN=5\uff0c\u6709 5 \u53f0 redis\uff1a<\/span><\/span><\/span><\/p>\n

    \u4e00\u4e2a\u7ebf\u7a0b\uff0c\u5411 redis \u96c6\u7fa4\u53d1\u8d77\u52a0\u9501\u64cd\u4f5c\uff0c\u7136\u540e\u7b2c\u4e00\u4e2a\u7ed3\u70b9\u52a0\u9501\u6210\u529f\u4e86\uff1b<\/span><\/span>
    \u7136\u540e\uff0c\u5b83\u53c8\u7d27\u63a5\u7740\u7acb\u523b\u5411\u4e0b\u4e00\u4e2a\u7ed3\u70b9\u53d1\u8d77\u52a0\u9501\uff0c\u4e5f\u52a0\u9501\u6210\u529f\u4e86\uff1b<\/span><\/span>
    \u7136\u540e\uff0c\u5b83\u53c8\u5411\u7b2c\u4e09\u53f0 redis \u52a0\u9501\uff0c\u4e5f\u52a0\u9501\u6210\u529f\u4e86\uff1b<\/span><\/span>
    \u90a3\u4e48\uff0c\u8fd9\u65f6\u5019\uff0c\u5df2\u7ecf\u4ee3\u8868\uff0c\u5b83\u83b7\u5f97\u4e86 redis \u96c6\u7fa4\u7684\u5206\u5e03\u5f0f\u9501\uff1b<\/span><\/span>
    \u4f46\u662f\uff0c\u5b83\u4e0d\u77e5\u9053\uff0c\u5b83\u524d\u4e24\u4e2a\u8282\u70b9\u52a0\u7684\u9501\uff0c\u5df2\u7ecf\u8fc7\u671f\u4e86\uff0c\u8fd9\u65f6\u5019\uff0c\u5b83\u53ea\u52a0\u4e86\u4e00\u628a\u9501\u3002<\/span><\/span>
    \u7136\u540e\uff0c\u53e6\u4e00\u4e2a\u4eba\u63ed\u7aff\u800c\u8d77\uff0c\u4e5f\u7acb\u523b\u52a0\u4e0a\u4e86 3 \u4e2a\u8282\u70b9\uff0c\u4e5f\u4ee3\u8868\u83b7\u53d6\u4e86\u9501\u3002<\/span><\/span>
    \u8fd9\u4e0b\uff0c\u5c31\u51fa\u73b0\u4e86\u4e00\u4e2a\u96c6\u7fa4\uff0c\u6709\u4e24\u4eba\u6301\u9501\uff0c\u9501\u5c31\u4e0d\u53ef\u9760\u4e86\u3002<\/span><\/span>
    \u4e0d\u8fc7\uff0c\u5728\u4e4b\u524d\u63d0\u5230\u8fc7\uff0c\u6211\u4eec\u53ef\u4ee5\u7ed9 redis \u7684\u9501\uff0c\u5ef6\u7eed\u8d85\u65f6\u65f6\u95f4\u3002<\/span><\/span>
    \u4e8e\u662f\uff0c\u5047\u8bbe\uff1a<\/span><\/span><\/span><\/p>\n

    \u4e00\u4e2a\u7ebf\u7a0b\uff0c\u5411 redis \u96c6\u7fa4\u53d1\u8d77\u52a0\u9501\u64cd\u4f5c\uff0c\u5411 1\u30012 redis \u52a0\u9501\uff0c\u90fd\u52a0\u9501\u6210\u529f\u4e86\uff1b<\/span><\/span>
    \u4f46\u662f\uff0c\u52a0\u9501\u5230 redis 3\uff0c\u7531\u4e8e\u7f51\u7edc\u901a\u4fe1\u5ef6\u8fdf\uff0c\u4e00\u76f4\u5361\u5728\u90a3\u52a0\u9501\uff1b<\/span><\/span>
    \u8fd9\u65f6\uff0c\u53e6\u4e00\u4e2a\u54e5\u4e48\u770b\u4e0d\u4e0b\u53bb\u4e86\uff0c\u4e8e\u662f\u4ed6\u4e5f\u53d1\u8d77\u52a0\u9501\u64cd\u4f5c\uff1b<\/span><\/span>
    \u4e8e\u662f\uff0c\u5b83\u5411 redis 1\u30012 \u5f00\u59cb\u52a0\u9501\uff1b<\/span><\/span>
    1\u30012 \u56e0\u4e3a\u5df2\u7ecf\u88ab\u52a0\u8fc7\u9501\u4e86\uff0c\u6240\u4ee5\u52a0\u9501\u5931\u8d25\uff0c\u7136\u540e\u52a0\u9501 3\u30014\u30015\uff1b<\/span><\/span>
    \u4f46\u662f\uff0c\u7531\u4e8e\u5b83\u548c 4\u30015 \u8fde\u63a5\u6709\u6545\u969c\uff0c\u5bfc\u81f4\u65e0\u6cd5\u52a0\u9501\u6210\u529f\uff1b<\/span><\/span>
    \u7136\u540e\uff0c\u8fd9\u65f6\u7b2c\u4e00\u4e2a\u52a0\u9501\u7684\u54e5\u4eec\uff0c\u7531\u4e8e\u7f51\u7edc\u6545\u969c\uff0c\u4e5f\u6ca1\u6709\u52a0\u9501\u6210\u529f\uff1b<\/span><\/span>
    \u4ece\u800c\uff0c\u4fe9\u4eba\u90fd\u6ca1\u52a0\u9501\u6210\u529f\u3002<\/span><\/span>
    \u5176\u5b9e\uff0c\u5982\u679c\u6ca1\u6709\u7b2c\u4e00\u4e2a\u5bb6\u4f19\uff0c\u7b2c\u4e8c\u4e2a\u54e5\u4eec\u662f\u80fd\u52a0\u5230\u9501\u7684\uff0c<\/span><\/span>
    \u4f46\u662f\uff0c\u7531\u4e8e\u7b2c\u4e00\u4e2a\u52a0\u9501\u8005\uff0c\u5360\u636e\u4e86\u9501\u7684\u4f4d\u7f6e\uff0c\u5360\u7528\u4e86\u5927\u91cf\u7684\u65f6\u95f4\uff0c\u5bfc\u81f4\u4e4b\u540e\u52a0\u9501\u7684\u7ebf\u7a0b\uff0c\u5c31\u4f1a\u56e0\u4e3a\u88ab\u5360\u7528\uff0c\u5f88\u5bb9\u6613\u52a0\u4e0d\u5230\u9501\uff0c\u5c31\u4f1a\u4f7f\u5f97\u52a0\u9501\u8d44\u6e90\u88ab\u767d\u767d\u6d6a\u8d39\uff0c\u7cfb\u7edf\u7684\u52a0\u9501\u8fc7\u7a0b\u5c31\u4f1a\u53d8\u957f\uff0c\u6548\u7387\u53d8\u4f4e\u3002<\/span><\/span><\/span><\/p>\n

    \u6240\u4ee5\uff0c\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u5c31\u53ef\u4ee5\u8bbe\u7f6e\u4e00\u4e2a\u8d85\u65f6\u65f6\u95f4\u7684\u6982\u5ff5\uff0c\u8ba9\u52a0\u9501\u7684\u6bcf\u4e00\u6b65\uff0c\u90fd\u5feb\u901f\uff0c\u8f7b\u76c8\uff0c<\/span><\/span>
    \u52a0\u7684\u5230\u5c31\u52a0\u7684\u5230\uff0c\u52a0\u4e0d\u5230\u5c31\u52a0\u4e0d\u5230\uff0c\u8fc7\u7a0b\u8fc5\u901f\uff0c\u4e0d\u62d6\u6ce5\u5e26\u6c34\uff0c<\/span><\/span>
    \u8fd9\u6837\uff0c\u5c31\u80fd\u4f7f\u5f97\u52a0\u9501\u7684\u8fc7\u7a0b\u66f4\u8fc5\u901f\uff0c\u52a0\u9501\u51b2\u649e\u800c\u5bfc\u81f4\u52a0\u4e0d\u5230\u9501\u7684\u6982\u7387\u4e5f\u4f1a\u53d8\u4f4e\uff0c\u4ece\u800c\u4f7f\u5f97\u52a0\u9501\u66f4\u52a0\u9ad8\u6548\u3002<\/span><\/span><\/span><\/p>\n

    \u6240\u4ee5\uff0c\u52a0\u9501\u7684\u65f6\u5019\uff0c\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4\uff0c\u4f46\u662f\uff0c\u5982\u679c\u52a0\u9501\u6700\u7ec8\u6ca1\u6709\u6210\u529f\uff0c\u5c31\u4e0d\u7ed9\u5355\u72ec\u7ed3\u70b9\u4e0a\u7684\u9501\u7eed\u547d\uff0c\u5c31\u8ba9\u5b83\u5feb\u901f\u8fc7\u671f\uff0c\u8fd9\u6837\uff0c\u5c31\u80fd\u591f\u4f7f\u5f97\u96c6\u7fa4\u4e4b\u95f4\u7684\u52a0\u9501\u66f4\u52a0\u9ad8\u6548\u8fc5\u901f\uff0c\u800c\u4e0d\u5bb9\u6613\u51fa\u73b0\u4e89\u62a2\u6fc0\u70c8\u7684\u60c5\u51b5\u3002<\/span><\/span>
    \u6240\u4ee5\uff0c\u5728\u8fd9\u91cc\uff0c\u5c31\u4e0d\u5e94\u8be5\u50cf\u4e4b\u524d\u90a3\u6837\uff0c\u7ed9\u9501\u5ef6\u957f\u8d85\u65f6\u65f6\u95f4\u3002<\/span><\/span><\/span><\/p>\n

    \u6240\u4ee5\uff0c\u5728\u6574\u4e2a\u52a0\u9501\u8fc7\u7a0b\u4e2d\uff0c\u6574\u4e2a\u52a0\u9501\u7684\u8fc7\u7a0b\uff0c\u4e0d\u80fd\u8d85\u8fc7\u9501\u7684\u6709\u6548\u65f6\u95f4\uff0c\u5426\u5219\uff0c\u5c31\u5e94\u7b97\u4f5c\u52a0\u9501\u5931\u8d25\uff0c\u8981\u7acb\u523b\u6e05\u9664\u6240\u6709\u5355\u72ec\u7ed3\u70b9\u4e0a\u7684\u9501\u3002<\/span><\/span><\/span><\/p>\n

    \"Redis
    \u73b0\u5728\uff0c\u60f3\u6765\u4f60\u5e94\u8be5\u80fd\u5927\u81f4\u7406\u89e3\uff0cRedlock \u52a0\u9501\u7684\u5927\u81f4\u8fc7\u7a0b\u4e86\uff0c\u4e0b\u9762\u6211\u5c31\u7528\u7b80\u7565\u7684\u8bed\u8a00\uff0c\u7ffb\u8bd1\u4e00\u4e0b\u5b98\u65b9\u5bf9\u4e8e Redlock \u7684\u52a0\u9501\u64cd\u4f5c\uff1a<\/span><\/span><\/span><\/p>\n

     <\/p>\n

    \u9996\u5148\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\uff08\u6beb\u79d2\u6570\uff09\uff1b<\/span><\/span>
    \u6309\u987a\u5e8f\u4f9d\u6b21\u5411 N \u4e2a redis \u8282\u70b9\u83b7\u53d6\u9501\uff0c\u5176\u4e2d\u8981\u4fdd\u8bc1 key \u76f8\u540c\uff0c\u4e14 value \u968f\u673a\uff1b<\/span><\/span>
    \u4e3a\u4e86\u4fdd\u8bc1\u5728\u67d0\u4e2a redis \u8282\u70b9\u4e0d\u53ef\u7528\u7684\u65f6\u5019\u7b97\u6cd5\u80fd\u591f\u7ee7\u7eed\u8fd0\u884c\uff0c\u83b7\u53d6\u9501\u7684\u64cd\u4f5c\u8fd8\u6709\u4e00\u4e2a\u8d85\u65f6\u65f6\u95f4\uff0c\u5b83\u8981\u8fdc\u5c0f\u4e8e\u9501\u7684\u6709\u6548\u65f6\u95f4\uff08\u51e0\u5341\u6beb\u79d2\u91cf\u7ea7\uff09\u3002<\/span><\/span>
    \u5ba2\u6237\u7aef\u5728\u5411\u67d0\u4e2a redis \u8282\u70b9\u83b7\u53d6\u9501\u5931\u8d25\u4ee5\u540e\uff0c\u5e94\u8be5\u7acb\u5373\u5c1d\u8bd5\u4e0b\u4e00\u4e2a redis \u8282\u70b9\u3002\u8fd9\u91cc\u7684\u5931\u8d25\uff0c\u5e94\u8be5\u5305\u542b\u4efb\u4f55\u7c7b\u578b\u7684\u5931\u8d25\uff0c\u6bd4\u5982\u8be5 redis \u8282\u70b9\u4e0d\u53ef\u7528\uff0c\u6216\u8005\u8be5 redis \u8282\u70b9\u4e0a\u7684\u9501\u5df2\u7ecf\u88ab\u5176\u5b83\u5ba2\u6237\u7aef\u6301\u6709\uff08\u6ce8\uff1aRedlock \u539f\u6587\u4e2d\u8fd9\u91cc\u53ea\u63d0\u5230\u4e86 redis \u8282\u70b9\u4e0d\u53ef\u7528\u7684\u60c5\u51b5\uff0c\u4f46\u4e5f\u5e94\u8be5\u5305\u542b\u5176\u5b83\u7684\u5931\u8d25\u60c5\u51b5\uff09\u3002<\/span><\/span>
    \u8ba1\u7b97\u6574\u4e2a\u83b7\u53d6\u9501\u7684\u8fc7\u7a0b\u603b\u5171\u6d88\u8017\u4e86\u591a\u957f\u65f6\u95f4\uff0c\u5c31\u662f\u7528\u5f53\u524d\u65f6\u95f4\u51cf\u53bb\u7b2c1\u6b65\u8bb0\u5f55\u7684\u65f6\u95f4\u3002<\/span><\/span>
    \u5982\u679c\u5ba2\u6237\u7aef\u4ece\u5927\u591a\u6570 redis \u8282\u70b9\uff08>= N\/2+1\uff0c\u4e5f\u5c31\u662f\u8fc7\u534a\uff09\u6210\u529f\u83b7\u53d6\u5230\u4e86\u9501\uff0c\u5e76\u4e14\u83b7\u53d6\u9501\u603b\u5171\u6d88\u8017\u7684\u65f6\u95f4\u6ca1\u6709\u8d85\u8fc7\u9501\u7684\u6709\u6548\u65f6\u95f4\uff0c\u90a3\u4e48\u8fd9\u65f6\u5ba2\u6237\u7aef\u624d\u8ba4\u4e3a\u6700\u7ec8\u83b7\u53d6\u9501\u6210\u529f\uff0c\u5426\u5219\uff0c\u8ba4\u4e3a\u6700\u7ec8\u83b7\u53d6\u9501\u5931\u8d25\u3002<\/span><\/span>
    \u5982\u679c\u6700\u7ec8\u83b7\u53d6\u9501\u6210\u529f\u4e86\uff0c\u90a3\u4e48\u8fd9\u4e2a\u9501\u7684\u6709\u6548\u65f6\u95f4\u5e94\u8be5\u91cd\u65b0\u8ba1\u7b97\uff0c\u5b83\u7b49\u4e8e\u6700\u521d\u7684\u9501\u7684\u6709\u6548\u65f6\u95f4\u51cf\u53bb\u7b2c 3 \u6b65\u8ba1\u7b97\u51fa\u6765\u7684\u83b7\u53d6\u9501\u6d88\u8017\u7684\u65f6\u95f4\u3002<\/span><\/span>
    \u5982\u679c\u6700\u7ec8\u83b7\u53d6\u9501\u5931\u8d25\u4e86\uff08\u53ef\u80fd\u7531\u4e8e\u83b7\u53d6\u5230\u9501\u7684 redis \u8282\u70b9\u4e2a\u6570\u5c11\u4e8e N\/2+1\uff0c\u6216\u8005\u6574\u4e2a\u83b7\u53d6\u9501\u7684\u8fc7\u7a0b\u6d88\u8017\u7684\u65f6\u95f4\u8d85\u8fc7\u4e86\u9501\u7684\u6700\u521d\u6709\u6548\u65f6\u95f4\uff09\uff0c\u90a3\u4e48\u5ba2\u6237\u7aef\u5e94\u8be5\u7acb\u5373\u5411\u6240\u6709 redis \u8282\u70b9\u91ca\u653e\u9501\u3002<\/span><\/span>
    \u52a0\u9501\u7684\u8fc7\u7a0b\u6bd4\u8f83\u590d\u6742\uff0c\u4e0d\u8fc7\u91ca\u653e\u9501\u7684\u8fc7\u7a0b\u5c31\u7b80\u5355\u591a\u4e86\uff1a<\/span><\/span>
    \u5411\u6240\u6709 redis \u8282\u70b9\u53d1\u8d77\u91ca\u653e\u9501\u5373\u53ef\uff0c\u4e0d\u7ba1\u8fd9\u4e9b\u8282\u70b9\u5f53\u65f6\u5728\u52a0\u9501\u7684\u65f6\u5019\u6210\u529f\u4e0e\u5426\u3002<\/span><\/span><\/span><\/p>\n

    \u770b\u8d77\u6765\u4f3c\u4e4e\u5f88\u5b8c\u7f8e\u4e86\uff0c\u4f46\u662f\uff0c\u6211\u7ee7\u7eed\u629b\u51fa\u4e00\u4e2a\u95ee\u9898\u3002<\/span><\/span><\/span><\/p>\n

    \u5047\u8bbe\u4e00\u5171\u6709 5 \u4e2a redis \uff0c\u5206\u522b\u662f ABCDE\uff1a<\/span><\/span><\/span><\/p>\n

    \u5ba2\u6237\u7aef1\u6210\u529f\u9501\u4f4f\u4e86A, B, C\uff0c \u52a0\u9501\u6210\u529f\uff08\u4f46 D \u548c E \u6ca1\u6709\u9501\u4f4f\uff09\u3002<\/span><\/span>
    \u8282\u70b9 C \u5d29\u6e83\u91cd\u542f\u4e86\uff0c\u4f46\u5ba2\u6237\u7aef 1 \u5728 C \u4e0a\u52a0\u7684\u9501\u6ca1\u6709\u6301\u4e45\u5316\u4e0b\u6765\uff0c\u4e22\u5931\u4e86\u3002<\/span><\/span>
    \u8282\u70b9 C \u91cd\u542f\u540e\uff0c\u5ba2\u6237\u7aef 2 \u9501\u4f4f\u4e86 C\uff0cD\uff0cE\uff0c\u52a0\u9501\u6210\u529f\u3002<\/span><\/span>
    \u8fd9\u6837\uff0c\u5ba2\u6237\u7aef 1 \u548c\u5ba2\u6237\u7aef 2 \u5c31\u540c\u65f6\u83b7\u5f97\u4e86\u9501\u3002<\/span><\/span><\/span>
    \"Redis
    \u8fd9\u65f6\u5019\u8be5\u600e\u4e48\u529e\uff1f<\/span><\/span>
    \u6211\u4eec\u662f\u4e0d\u80fd\u4fdd\u8bc1\uff0c\u5728\u5206\u5e03\u5f0f\u53ca\u7fa4\u4e2d\uff0c\u6ca1\u6709\u7ed3\u70b9\u4f1a\u5b95\u673a\u7684\u3002<\/span><\/span><\/span><\/p>\n

     <\/p>\n

    \u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0credis \u7684 AOF \u6301\u4e45\u5316\u65b9\u5f0f\u662f\u6bcf\u79d2\u5199\u4e00\u6b21\u78c1\u76d8\uff08\u5373\u6267\u884c fsync\uff09\uff0c\u56e0\u6b64\u6700\u574f\u60c5\u51b5\u4e0b\u53ef\u80fd\u4e22\u5931 1 \u79d2\u7684\u6570\u636e\u3002<\/span><\/span>
    \u4e3a\u4e86\u5c3d\u53ef\u80fd\u4e0d\u4e22\u6570\u636e\uff0credis \u4e5f\u5141\u8bb8\u8bbe\u7f6e\u6210\u6bcf\u6b21\u4fee\u6539\u6570\u636e\u90fd\u8fdb\u884c fsync\uff0c\u4f46\u8fd9\u4f1a\u964d\u4f4e\u6027\u80fd\u3002<\/span><\/span>
    \u5f53\u7136\uff0c\u5373\u4f7f\u6267\u884c\u4e86 fsync \u4e5f\u4ecd\u7136\u6709\u53ef\u80fd\u4e22\u5931\u6570\u636e\uff08\u8fd9\u53d6\u51b3\u4e8e\u7cfb\u7edf\u800c\u4e0d\u662f redis \u7684\u5b9e\u73b0\uff09\u3002<\/span><\/span>
    \u6240\u4ee5\uff0c\u4e0a\u9762\u5206\u6790\u7684\u7531\u4e8e\u8282\u70b9\u91cd\u542f\u5f15\u53d1\u7684\u9501\u5931\u6548\u95ee\u9898\uff0c\u603b\u662f\u6709\u53ef\u80fd\u51fa\u73b0\u7684\u3002<\/span><\/span><\/span><\/p>\n

    \u90a3\u4e48\uff0c\u65e2\u7136\u9501\u53ef\u80fd\u56e0\u5b95\u673a\u800c\u4e22\u5931\uff0c\u5df2\u7ecf\u65e0\u6cd5\u518d\u6062\u590d\u3002\u4e8e\u662f\uff0cantirez \u53c8\u63d0\u51fa\u4e86\u5ef6\u8fdf\u91cd\u542f \uff08delayed restarts\uff09\u7684\u6982\u5ff5\u3002<\/span><\/span>
    \u4e5f\u5c31\u662f\u8bf4\uff0c\u4e00\u4e2a\u8282\u70b9\u5d29\u6e83\u540e\uff0c\u5148\u4e0d\u7acb\u5373\u91cd\u542f\u5b83\uff0c\u800c\u662f\u7b49\u5f85\u4e00\u6bb5\u65f6\u95f4\u518d\u91cd\u542f\uff0c\u8fd9\u6bb5\u65f6\u95f4\u5e94\u8be5\u5927\u4e8e\u9501\u7684\u6709\u6548\u65f6\u95f4\u3002<\/span><\/span>
    \u8fd9\u6837\u7684\u8bdd\uff0c\u53ea\u8981\u8fd9\u4e2a\u7ed3\u70b9\u4e0d\u91cd\u542f\uff0c\u5982\u679c\u6b64\u65f6\uff0c\u6301\u6709\u9501\u7684\u7ebf\u7a0b\u6240\u5360\u636e\u7684 redis \u53ea\u5269\u4e0b\u4e86 2 \u53f0\uff0c\u90a3\u4e48\uff0c\u8fd9\u628a\u9501\u5c31\u65e0\u6cd5\u88ab\u7ee7\u7eed\u7ef4\u6301\uff0c\u90a3\u4e48\uff0c\u53ea\u8981\u5931\u6548\u65f6\u95f4\u4e00\u5230\uff0c\u9501\u5c31\u4f1a\u88ab\u4fdd\u8bc1\u88ab\u8feb\u8fc7\u671f\u91ca\u653e\u3002<\/span><\/span>
    \u6240\u4ee5\uff0c\u5ef6\u8fdf\u91cd\u542f\uff0c\u5c31\u4f7f\u5f97\u8fd9\u4e2a\u8282\u70b9\u5728\u91cd\u542f\u524d\u6240\u53c2\u4e0e\u7684\u9501\u90fd\u4f1a\u8fc7\u671f\uff0c\u5b83\u5728\u91cd\u542f\u540e\u5c31\u4e0d\u4f1a\u5bf9\u73b0\u6709\u7684\u9501\u9020\u6210\u5f71\u54cd\u3002<\/span><\/span><\/span><\/p>\n

    \u4e0d\u8fc7\u5173\u4e8e Redlock \u8fd8\u6709\u4e00\u70b9\u7ec6\u8282\u503c\u5f97\u62ff\u51fa\u6765\u5206\u6790\u4e00\u4e0b\uff1a<\/span><\/span>
    \u5728\u6700\u540e\u91ca\u653e\u9501 \u7684\u65f6\u5019\uff0cantirez \u5728\u7b97\u6cd5\u63cf\u8ff0\u4e2d\u7279\u522b\u5f3a\u8c03\uff0c\u5ba2\u6237\u7aef\u5e94\u8be5\u5411\u6240\u6709 redis \u8282\u70b9\u91ca\u653e\u9501\u3002<\/span><\/span>
    \u4e5f\u5c31\u662f\u8bf4\uff0c\u5373\u4f7f\u5f53\u65f6\u5411\u67d0\u4e2a\u8282\u70b9\u83b7\u53d6\u9501\u6ca1\u6709\u6210\u529f\uff0c\u5728\u91ca\u653e\u9501\u7684\u65f6\u5019\u4e5f\u4e0d\u5e94\u8be5\u6f0f\u6389\u8fd9\u4e2a\u8282\u70b9\u3002<\/span><\/span><\/span><\/p>\n

    \u8fd9\u662f\u4e3a\u4ec0\u4e48\u5462\uff1f<\/span><\/span><\/span><\/p>\n

    \u8bbe\u60f3\u8fd9\u6837\u4e00\u79cd\u60c5\u51b5\uff0c\u5ba2\u6237\u7aef\u53d1\u7ed9\u67d0\u4e2a redis \u8282\u70b9\u7684\u83b7\u53d6\u9501\u7684\u8bf7\u6c42\u6210\u529f\u5230\u8fbe\u4e86\u8be5 redis \u8282\u70b9\uff0c\u8fd9\u4e2a\u8282\u70b9\u4e5f\u6210\u529f\u6267\u884c\u4e86 SET\u64cd\u4f5c\uff0c\u4f46\u662f\u5b83\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u7684\u54cd\u5e94\u5305\u5374\u4e22\u5931\u4e86\u3002<\/span><\/span>
    \u8fd9\u5728\u5ba2\u6237\u7aef\u770b\u6765\uff0c\u83b7\u53d6\u9501\u7684\u8bf7\u6c42\u7531\u4e8e\u8d85\u65f6\u800c\u5931\u8d25\u4e86\uff0c\u4f46\u5728 redis \u8fd9\u8fb9\u770b\u6765\uff0c\u52a0\u9501\u5df2\u7ecf\u6210\u529f\u4e86\u3002<\/span><\/span>
    \u56e0\u6b64\uff0c\u91ca\u653e\u9501\u7684\u65f6\u5019\uff0c\u5ba2\u6237\u7aef\u4e5f\u5e94\u8be5\u5bf9\u5f53\u65f6\u83b7\u53d6\u9501\u5931\u8d25\u7684\u90a3\u4e9b redis \u8282\u70b9\u540c\u6837\u53d1\u8d77\u8bf7\u6c42\u3002<\/span><\/span><\/span><\/p>\n

    \u56e0\u4e3a\u8fd9\u79cd\u60c5\u51b5\u5728\u5f02\u6b65\u901a\u4fe1\u6a21\u578b\u4e2d\u662f\u6709\u53ef\u80fd\u53d1\u751f\u7684\uff1a\u5ba2\u6237\u7aef\u5411\u670d\u52a1\u5668\u901a\u4fe1\u662f\u6b63\u5e38\u7684\uff0c\u4f46\u53cd\u65b9\u5411\u5374\u662f\u6709\u95ee\u9898\u7684\u3002<\/span><\/span><\/span><\/p>\n

    \u8c08\u5230\u8fd9\u91cc\uff0c\u5bf9\u4e8e\u7f13\u5b58\u7684\u51fb\u7a7f\uff0c\u4ee5\u53ca\u6d89\u53ca\u5230\u7684\u4e00\u70b9 redis \u5206\u5e03\u5f0f\u9501\u7684\u77e5\u8bc6\uff0c\u4f60\u5e94\u8be5\u5df2\u7ecf\u4e86\u89e3\u5f97\u5dee\u4e0d\u591a\u4e86\u3002<\/span><\/span>
    \u800c\u4e14\uff0c\u5176\u5b9e\u5b9e\u9645\u4e0a\uff0c\u4f60\u4f1a\u53d1\u73b0\uff0c\u6211\u8c08\u8bba\u5230\u7684\u77e5\u8bc6\uff0c\u7edd\u5bf9\u662f\u4e0d\u9650\u4e8e\u4ec5\u4ec5\u5728\u8fd9\u4e2a redis \u8eab\u4e0a\u7684\uff0c\u800c\u662f\u8fd9\u6574\u4e2a\u67b6\u6784\u7684\u8bbe\u8ba1\u548c\u601d\u7ef4\u3002<\/span><\/span>
    \u5982\u679c\u4f60\u4ec5\u4ec5\u628a\u773c\u5149\u653e\u5728\u8fd9\u4e2a\u5c0f\u5c0f\u7684 redis \u4e0a\uff0c\u90a3\u4f60\u662f\u6c38\u8fdc\u4e0d\u4f1a\u8fbe\u5230\u67b6\u6784\u5e08\u7684\u6c34\u5e73\u7684\u3002<\/span><\/span><\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

    \n

    \n

    \u56db<\/strong><\/span><\/span><\/strong>\u3001\u7f13\u5b58\u7a7f\u900f\u89e3\u51b3\u65b9\u6848<\/strong><\/span><\/span><\/strong><\/strong><\/span><\/h3>\n\n\n\n
    \n

    \u4e00\u4e2a\u4e00\u5b9a\u4e0d\u5b58\u5728\u7f13\u5b58\u53ca\u67e5\u8be2\u4e0d\u5230\u7684\u6570\u636e\uff0c\u7531\u4e8e\u7f13\u5b58\u662f\u4e0d\u547d\u4e2d\u65f6\u88ab\u52a8\u5199\u7684\uff0c\u5e76\u4e14\u51fa\u4e8e\u5bb9\u9519\u8003\u8651\uff0c\u5982\u679c\u4ece\u5b58\u50a8\u5c42\u67e5\u4e0d\u5230\u6570\u636e\u5219\u4e0d\u5199\u5165\u7f13\u5b58\uff0c\u8fd9\u5c06\u5bfc\u81f4\u8fd9\u4e2a\u4e0d\u5b58\u5728\u7684\u6570\u636e\u6bcf\u6b21\u8bf7\u6c42\u90fd\u8981\u5230\u5b58\u50a8\u5c42\u53bb\u67e5\u8be2\uff0c\u5931\u53bb\u4e86\u7f13\u5b58\u7684\u610f\u4e49\u3002<\/span><\/span><\/span><\/p>\n

    \u6709\u5f88\u591a\u79cd\u65b9\u6cd5\u53ef\u4ee5\u6709\u6548\u5730\u89e3\u51b3\u7f13\u5b58\u7a7f\u900f\u95ee\u9898<\/span><\/span><\/strong>\uff0c<\/span><\/span>\u6700\u5e38\u89c1<\/span><\/span><\/strong>\u7684\u5219\u662f\u91c7\u7528\u5e03\u9686\u8fc7\u6ee4\u5668\uff0c\u5c06\u6240\u6709\u53ef\u80fd\u5b58\u5728\u7684\u6570\u636e\u54c8\u5e0c\u5230\u4e00\u4e2a\u8db3\u591f\u5927\u7684bitmap\u4e2d\uff0c\u4e00\u4e2a\u4e00\u5b9a\u4e0d\u5b58\u5728\u7684\u6570\u636e\u4f1a\u88ab \u8fd9\u4e2abitmap\u62e6\u622a\u6389\uff0c\u4ece\u800c\u907f\u514d\u4e86\u5bf9\u5e95\u5c42\u5b58\u50a8\u7cfb\u7edf\u7684\u67e5\u8be2\u538b\u529b\u3002<\/span><\/span>\u53e6\u5916\u4e5f\u6709\u4e00\u4e2a<\/span><\/span><\/strong>\u66f4\u4e3a\u7b80\u5355\u7c97\u66b4\u7684\u65b9\u6cd5\uff08\u6211\u4eec\u91c7\u7528\u7684\u5c31\u662f\u8fd9\u79cd\uff09\uff0c\u5982\u679c\u4e00\u4e2a\u67e5\u8be2\u8fd4\u56de\u7684\u6570\u636e\u4e3a\u7a7a\uff08\u4e0d\u7ba1\u662f\u6570\u636e\u4e0d\u5b58\u5728\uff0c\u8fd8\u662f\u7cfb\u7edf\u6545\u969c\uff09\uff0c\u6211\u4eec\u4ecd\u7136\u628a\u8fd9\u4e2a\u7a7a\u7ed3\u679c\u8fdb\u884c\u7f13\u5b58\uff0c\u4f46\u5b83\u7684\u8fc7\u671f\u65f6\u95f4\u4f1a\u5f88\u77ed\uff0c\u6700\u957f\u4e0d\u8d85\u8fc7\u4e94\u5206\u949f\u3002<\/span><\/span><\/span><\/p>\n\n\n\n
    \n

    \/\/\u4f2a\u4ee3\u7801<\/p>\n

    public object GetProductListNew() {
    \n <\/p>\n

        int cacheTime = 30;<\/p>\n

        String cacheKey = \"product_list\";<\/p>\n

    \n

        String cacheValue = CacheHelper.Get(cacheKey);<\/p>\n

        if (cacheValue != null) {
    \n <\/p>\n

            return cacheValue;<\/p>\n

        }<\/p>\n

    \n

        cacheValue = CacheHelper.Get(cacheKey);<\/p>\n

        if (cacheValue != null) {
    \n <\/p>\n

            return cacheValue;<\/p>\n

        } else {
    \n <\/p>\n

            \/\/\u6570\u636e\u5e93\u67e5\u8be2\u4e0d\u5230\uff0c\u4e3a\u7a7a<\/p>\n

            cacheValue = GetProductListFromDB();<\/p>\n

            if (cacheValue == null) {
    \n <\/p>\n

                \/\/\u5982\u679c\u53d1\u73b0\u4e3a\u7a7a\uff0c\u8bbe\u7f6e\u4e2a\u9ed8\u8ba4\u503c\uff0c\u4e5f\u7f13\u5b58\u8d77\u6765<\/p>\n

                cacheValue = string.Empty;<\/p>\n

            }<\/p>\n

            CacheHelper.Add(cacheKey, cacheValue, cacheTime);<\/p>\n

            return cacheValue;<\/p>\n

        }<\/p>\n

    }<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

    \n

    \n

    \u7f13\u5b58\u7a7f\u900f<\/span><\/span>
    \u5f88\u591a\u4eba\u4f1a\u628a\u7f13\u5b58\u7a7f\u900f\u548c\u51fb\u7a7f\u641e\u6df7\uff0c\u4e3b\u8981\u662f\u540d\u8bcd\u65b9\u9762\u7684\u6df7\u6dc6\u3002<\/span><\/span>
    \u66f4\u591a\u7684\uff0c\u6211\u89c9\u5f97\u5173\u6ce8\u610f\u601d\u5373\u53ef\u3002<\/span><\/span><\/span><\/p>\n

    \u7f13\u5b58\u7a7f\u900f\uff0c\u4e0e\u51fb\u7a7f\u7684\u533a\u522b\u5c31\u662f\uff0c<\/span><\/span>
    \u51fb\u7a7f\uff1a\u6570\u636e\u5e93\u91cc\u201c\u6709\u201d\u6570\u636e\uff1b<\/span><\/span>
    \u7a7f\u900f\uff1a\u6570\u636e\u5e93\u91cc\u201c\u6ca1\u201d\u6570\u636e\u3002<\/span><\/span><\/span><\/p>\n

    \u6240\u4ee5\uff0c\u7f13\u5b58\u51fb\u7a7f\u53ef\u4ee5\u89c4\u907f\uff0c\u56e0\u4e3a\u53ea\u662f redis \u7f13\u5b58\u6570\u636e\u5931\u6548\u4e86\uff0c\u800c\u6570\u636e\u5e93\u91cc\u6709\u6570\u636e\uff0c\u53ea\u8981\u628a\u6570\u636e\u5e93\u91cc\u7684\u6570\u636e\u66f4\u65b0\u5230 redis \u4e0a\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u89e3\u51b3\u6389\u7f13\u5b58\u51fb\u7a7f\u7684\u95ee\u9898\u3002<\/span><\/span><\/span><\/p>\n

    \u4f46\u662f\uff0c\u7f13\u5b58\u7a7f\u900f\uff0c\u610f\u5473\u7740\uff0c\u8fd9\u4e2a\u6570\u636e\uff0c\u6570\u636e\u5e93\u91cc\u4e5f\u6ca1\u6709\u3002<\/span><\/span>
    \u6240\u4ee5\uff0c\u5c31\u4e0d\u53ef\u80fd\u4f1a\u628a\u6570\u636e\u5b58\u5230 redis \u7f13\u5b58\u91cc\uff0c\u56e0\u6b64\u53ea\u8981\u6709\u4eba\u6765\u67e5\u8be2\uff0c\u5c31\u4e00\u5b9a\u7f13\u5b58\u4e2d\u67e5\u4e0d\u5230\uff0c\u6240\u4ee5\u5c31\u4e00\u5b9a\u8981\u8d70\u6570\u636e\u5e93\u3002<\/span><\/span>
    \u90a3\u4e48\uff0c\u5047\u8bbe\u5f88\u591a\u4eba\uff0c\u6545\u610f\u53bb\u67e5\u90a3\u4e9b\u6570\u636e\u5e93\u91cc\u4e5f\u6ca1\u6709\u7684\u8bb0\u5f55\uff0c\u6211\u4eec\u7684 redis \u5c31\u8d77\u4e0d\u5230\u5c4f\u969c\u7684\u4f5c\u7528\uff0c\u56e0\u4e3a redis \u91cc\u4e0d\u53ef\u80fd\u6709\u6570\u636e\uff0c\u6240\u4ee5\u5e76\u53d1\u67e5\u8be2\u5c31\u4e00\u5b9a\u4f1a\u6253\u5230\u6570\u636e\u5e93\u7684\u8eab\u4e0a\u3002<\/span><\/span><\/span><\/p>\n

    \u90a3\u4e48\uff0c\u60f3\u8981\u89e3\u51b3\u7f13\u5b58\u7a7f\u900f\uff0c\u5c31\u5fc5\u987b\u60f3\u529e\u6cd5\uff0c\u80fd\u591f\u8bc6\u522b\u51fa\uff0c\u54ea\u4e9b\u8bf7\u6c42\u7684\u6570\u636e\uff0c\u662f\u6570\u636e\u5e93\u6ca1\u6709\u7684\uff0c\u7136\u540e\uff0c\u5bf9\u8fd9\u4e9b\u8bf7\u6c42\u7684\u67e5\u8be2\uff0c\u8fdb\u884c\u8fc7\u6ee4\u3002<\/span><\/span><\/span><\/p>\n

    \u5982\u679c\u4f60\u4ee5\u524d\u6ca1\u6709\u4e86\u89e3\u8fc7\u8fd9\u4e9b\u77e5\u8bc6\uff0c\u90a3\u4f60\u53ef\u4ee5\u5148\u60f3\u4e00\u60f3\uff0c\u53ef\u4ee5\u7528\u4ec0\u4e48\u529e\u6cd5\uff1f<\/span><\/span><\/span><\/p>\n

    \u6bd4\u8f83\u7b80\u5355\u7684\uff0c\u5c31\u662f\u9009\u62e9\uff0c\u5f53\u7528\u6237\u67e5\u8be2\u4e0d\u5b58\u5728\u7684\u6570\u636e\u65f6\uff0c\u5c06\u8fd9\u4e2a key\uff0c\u5b58\u5165 redis\uff0c\u7136\u540e\u7528\u4e00\u4e2a\u7279\u6b8a\u7684 value \u6765\u8868\u793a\uff0c\u8fd9\u662f\u4e00\u4e2a\u4e0d\u5b58\u5728\u7684\u6570\u636e\u3002<\/strong><\/span><\/span><\/strong>
    \u4f46\u662f\uff0c\u5982\u679c\u6709\u5927\u91cf\u7684\u8bf7\u6c42\uff0c\u90fd\u8bf7\u6c42\u5404\u4e0d\u76f8\u540c\u7684\u4e0d\u5b58\u5728\u7684\u6570\u636e\uff0c\u90a3\u4e48\uff0credis \u7684\u7f13\u5b58\uff0c\u5c31\u4f1a\u7528\u6765\u5b58\u50a8\u5927\u91cf\u6ca1\u7528\u7684\u6570\u636e\uff0c\u5c31\u4f1a\u9020\u6210\u7a7a\u95f4\u7684\u6d6a\u8d39\u3002<\/strong><\/span><\/span><\/strong>
    \u800c\u4e14\uff0c\u4e00\u822c\u8fd9\u90e8\u5206\u7684\u8bf7\u6c42\uff0c\u90fd\u662f\u4eba\u523b\u610f\u653b\u51fb\u670d\u52a1\u5668\u3002<\/span><\/span><\/span><\/p>\n

    \u800c\u4e14\uff0c\u5f88\u660e\u786e\u7684\u4e00\u70b9\uff0c\u5c31\u662f\u6570\u636e\u662f\u65e0\u9650\u7684\uff0c\u6211\u4eec\u4e0d\u53ef\u80fd\u627e\u51fa\u6240\u6709\u7684\u6570\u636e\u5e93\u4e2d\u4e0d\u5b58\u5728\u7684\u6570\u636e\uff1b<\/span><\/span>
    \u4f46\u662f\uff0c\u5bf9\u4e8e\u6570\u636e\u5e93\u91cc\u5df2\u6709\u7684\u6570\u636e\uff0c\u90a3\u5c31\u662f\u6709\u9650\u7684\uff0c\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u627e\u51fa\u6240\u6709\u5df2\u7ecf\u5b58\u5728\u7684\u6570\u636e\uff1b<\/span><\/span>
    \u8fd9\u6837\uff0c\u5f53\u8bf7\u6c42\u6253\u8fc7\u6765\u7684\u65f6\u5019\uff0c\u6211\u4eec\u5c31\u80fd\u4ee5\u6b64\u6765\u5224\u65ad\uff0c\u8fd9\u4e2a\u6570\u636e\u662f\u5426\u5b58\u5728\u3002<\/span><\/span><\/span><\/p>\n

    \u4f46\u662f\uff0c\u7531\u4e8e\u6570\u636e\u91cf\u7684\u5de8\u5927\uff0c\u6211\u4eec\u5fc5\u987b\u5f97\u60f3\u4e00\u4e2a\u65b9\u6cd5\uff0c\u600e\u6837\u7528\u5c3d\u53ef\u80fd\u5c11\u7684\u7a7a\u95f4\u548c\u65f6\u95f4\uff0c\u53bb\u5bf9\u6570\u636e\u662f\u5df2\u6709\u5728\u505a\u4e00\u4e2a\u5224\u65ad\u3002<\/span><\/span>
    \u6b63\u662f\u56e0\u4e3a redis \u7684\u5c0f\uff0c\u5185\u5b58\u7a7a\u95f4\u7684\u53ef\u8d35\uff0c\u624d\u4f7f\u5f97\uff0c\u6211\u4eec\u4e0d\u80fd\u591f\u53bb\u7f13\u5b58\u6240\u6709\u7684\u6570\u636e\uff0c\u56e0\u800c\u624d\u4f1a\u6709\u67e5\u8be2 DB \u7684\u64cd\u4f5c\u3002<\/span><\/span>
    \u6240\u4ee5\uff0c\u6211\u4eec\u4e0d\u53ef\u80fd\u76f4\u63a5\u5c06\u5b8c\u6574\u7684\u6570\u636e\u4fe1\u606f\u5168\u90e8\u642c\u5165\u5185\u5b58\u3002<\/span><\/span><\/span><\/p>\n

    \u90a3\u4e48\uff0c\u65e2\u7136\u6570\u636e\u65e0\u6cd5\u5b8c\u6574\u5b58\u50a8\uff0c\u90a3\u4e48\u662f\u5426\u53ef\u4ee5\uff0c\u53ea\u4fdd\u7559 key\uff0c\u7701\u7565 value\uff0c\u4ece\u800c\u4f7f\u5f97\u5355\u4f4d\u8303\u56f4\u5185\u5185\u5b58\u80fd\u5b58\u50a8\u7684\u4fe1\u606f\u91cf\u5927\u4e86\u5f88\u591a\u3002<\/span><\/span>
    \u56e0\u4e3a\u6570\u636e\u7684\u5927\u90e8\u5206\u7a7a\u95f4\uff0c\u90fd\u662f value \u5360\u7528\u7684\uff0c\u4e00\u822c key \u548c value \u76f8\u6bd4\uff0c\u90fd\u662f\u975e\u5e38\u975e\u5e38\u5c0f\u7684\u3002<\/span><\/span><\/span><\/p>\n

    \u6240\u4ee5\uff0c\u662f\u4e0d\u662f\u5c31\u53ef\u4ee5\u989d\u5916\u5f00\u8f9f\u4e00\u7247 Set\uff0c\u7528\u6765\u4e13\u95e8\u5b58\u50a8 key\uff0c\u8fd9\u6837\uff0c\u6bcf\u6b21\u8981\u8bbf\u95ee\u6570\u636e\u5e93\u524d\uff0c\u5148\u53bb key set \u4e2d\u67e5\u8be2\u65f6\u5019\u5b58\u5728\uff0c\u5982\u679c\u5b58\u5728\uff0c\u90a3\u4e48\u518d\u53bb\u8bbf\u95ee\u6570\u636e\u5e93\u3002<\/span><\/span><\/span><\/p>\n

    \u8fd9\u6837\uff0c\u786e\u5b9e\u53ef\u4ee5\u4f7f\u5f97\u7f13\u5b58\u4e0d\u4f1a\u7a7f\u900f\u4e86\u3002\u800c\u4e14\u76f8\u6bd4\u7f13\u5b58\u5168\u91cf key\u3001value\uff0c\u53ea\u5b58\u50a8 key \u4f1a\u4f7f\u5f97\u5185\u5b58\u7684\u5360\u7528\u53d8\u5c0f\u4e86\u5f88\u591a\u3002<\/span><\/span><\/span><\/p>\n

    \u4f46\u662f\uff0c\u7406\u8bba\u4e0a\u542c\u8d77\u6765\u4f3c\u4e4e\u4e0d\u9519\uff0c\u5047\u8bbe\uff0c\u6211\u4eec\u4e00\u53f0 redis\uff0c\u7528\u6765\u7f13\u5b58\u540e\u7aef 4T \u7684\u70ed\u70b9\u6570\u636e\uff1b<\/span><\/span>
    \u73b0\u5728\u4e3a\u4e86\u5b9e\u73b0\u7f13\u5b58\u7a7f\u900f\u7684\u89e3\u51b3\uff0c\u5047\u8bbe\u4e00\u4e2a key : value = 1 : 99\uff0c\u90a3\u4e48\u9700\u8981\u7f13\u5b58\u7684\u603b\u91cf key \u5927\u7ea6\u8981 40G\u3002<\/span><\/span><\/span><\/p>\n

    \u6240\u4ee5\uff0c\u5230\u4e86\u6570\u636e\u9762\u524d\uff0c\u5c31\u80fd\u53d1\u73b0\u4ecd\u7136\u662f\u4e00\u4e2a\u8d85\u9ad8\u6210\u672c\u7684\u65b9\u6cd5\u3002<\/span><\/span><\/span><\/p>\n

    \u90a3\u4e48\uff0c\u65e2\u7136\u5982\u679c\u5b58\u50a8 key\uff0c\u7a7a\u95f4\u4ecd\u7136\u5f88\u5927\uff0c\u90a3\u4e48\u6211\u4eec\u80fd\u5426\u60f3\u51fa\u4e00\u4e2a\u66f4\u8282\u7701\u7a7a\u95f4\u7684\u5b58\u50a8\u65b9\u5f0f\uff1f<\/span><\/span><\/span><\/p>\n

    \u4e00\u822c\u6709\u70b9\u7ecf\u9a8c\u7684\u90fd\u4f1a\u60f3\u5230\u7528 bit\uff0c\u4e5f\u5c31\u662f\u7528\u4e00\u4e2a\u4f4d\u6765\u5b58\u50a8\uff0c\u8fd9\u5df2\u7ecf\u662f\u8ba1\u7b97\u673a\u4e2d\u7684\u4e00\u4e2a\u6700\u5c0f\u7684\u5b58\u50a8\u5355\u4f4d\u4e86\u3002<\/span><\/span><\/span><\/p>\n

    \u73b0\u5728\uff0c\u5148\u4e0d\u7ba1\u5982\u4f55\u5b9e\u73b0\uff0c\u6211\u4eec\u5148\u6765\u770b\u4e00\u4e0b\uff0c\u5047\u8bbe\u7528 bitmap\uff0c\u90a3\u4e48\u7a7a\u95f4\u7684\u82b1\u8d39\u4ee3\u4ef7\u6709\u591a\u5c11\u3002<\/span><\/span>
    \u56e0\u4e3a\u4e00\u4e2a key \u53ea\u5360\u7528\u4e00\u4e2a bit\uff0c\u6240\u4ee5\uff0c\u5047\u8bbe\u6211\u4eec\u82b1\u8d39 1 \u4e2a\u5b57\u8282\u7684\u7a7a\u95f4\uff0c\u5c31\u80fd\u5b58\u50a8 8 \u4e2a key\uff1b<\/span><\/span>
    \u5047\u8bbe\uff0c\u6211\u4eec\u7528\u4e86 1 M\u5b57\u8282\u7684\u7a7a\u95f4\uff0c\u5c31\u53ef\u4ee5\u5b58\u50a8 800w \u4e2a key\uff1b<\/span><\/span>
    \u90a3\u4e48\u6211\u4eec\u5728\u589e\u591a\u4e00\u70b9\uff0c\u7528 100MB\uff0c\u90a3\u4e48\u5c31\u80fd\u5b58\u50a8 8\u4ebf \u4e2a key\uff1b<\/span><\/span><\/span><\/p>\n

    \u7531\u6b64\u53ef\u89c1\uff0c\u7528 bitmap\uff0c\u786e\u786e\u5b9e\u5b9e\u53ef\u4ee5\u8fbe\u5230\u5bf9\u7a7a\u95f4\u5229\u7528\u7684\u6781\u81f4\u3002<\/span><\/span><\/span><\/p>\n

    \u90a3\u4e48\uff0c\u65e2\u7136\u7a7a\u95f4\u7684\u95ee\u9898\u89e3\u51b3\u4e86\uff0c\u4e0b\u9762\u5c31\u8981\u89e3\u51b3\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u7a7a\u95f4\uff1a<\/span><\/span>
    \u4e5f\u5c31\u662f\u5982\u4f55\u628a\u4e00\u4e2a key\uff0c\u548c\u4e00\u4e2a bit \u53bb\u5bf9\u5e94\u8d77\u6765\u3002<\/span><\/span><\/span><\/p>\n

    \u6709\u70b9\u7ecf\u9a8c\u7684\uff0c\u7acb\u523b\u5c31\u80fd\u591f\u60f3\u5230\uff0c\u7528\u54c8\u5e0c\u6620\u5c04\u3002<\/span><\/span>
    \u5c31\u6bd4\u5982\u6211\u4eec\u7684 HashMap\uff0c\u6211\u4eec\u7684\u6bcf\u4e00\u4e2a key\uff0c\u90fd\u80fd\u901a\u8fc7\u54c8\u5e0c\u51fd\u6570\uff0c\u8f6c\u6362\u6210\u4e00\u4e2a\u6570\u7ec4\u7684\u4e0b\u6807\uff0c\u7136\u540e\u5c06\u952e\u503c\u5bf9\uff0c\u5b58\u50a8\u5728 HashMap \u4e2d\u3002<\/span><\/span>
    HashSet\uff0c\u5c31\u662f\u53ea\u5b58\u50a8 key\uff0c\u800c\u4e0d\u5b58\u50a8 value\u3002<\/span><\/span><\/span><\/p>\n

    \u6240\u4ee5\uff0c\u91c7\u7528\u54c8\u5e0c\u6620\u5c04\uff0c\u5c31\u53ef\u4ee5\u5c06\u90a3\u4e9b\u6240\u6709\u5b58\u5728\u7684 key\uff0c\u5168\u90e8\u5bf9\u5e94\u5230\u8fd9\u4e2a bitmap \u7684\u6bcf\u4e00\u4e2a\u69fd\u4f4d\u4e0a\uff0c<\/span><\/span>
    \u8fd9\u6837\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u6240\u6709\u5b58\u5728\u7684 key\uff0c\u628a\u5b83\u6620\u5c04\u5230\u4e00\u4e2a bit \u69fd\u4f4d\u4e0a\uff0c\u7136\u540e\u7528 1 \u8868\u793a\uff0c\u5176\u4ed6\u5269\u4f59\u7684\u90e8\u5206\uff0c\u5c31\u7528 0 \u8868\u793a\uff0c<\/span><\/span>
    \u8fd9\u6837\uff0c\u5f53\u4e00\u4e2a\u67e5\u8be2\u7684 key \u88ab\u6620\u5c04\u5230 0 \u8fd9\u4e2a\u69fd\u4f4d\uff0c\u90a3\u4e48\u5c31\u4ee3\u8868\u8fd9\u4e2a\u6570\u636e\u4e0d\u5b58\u5728\uff0c\u6240\u4ee5\u5c31\u53ef\u4ee5\u76f4\u63a5\u8fd4\u56de\u3002<\/span><\/span>
    \u56e0\u6b64\uff0c\u5c31\u53ef\u4ee5\u5b9e\u73b0\u5bf9\u8bf7\u6c42\u6570\u636e\u7684\u8fc7\u6ee4\u3002<\/span><\/span><\/span><\/p>\n

    \u770b\u8d77\u6765\u4f3c\u4e4e\u5f88\u5b8c\u7f8e\uff0c\u65e2\u89e3\u51b3\u4e86\u7a7a\u95f4\u7684\u95ee\u9898\uff0c\u53c8\u53ef\u4ee5\u4fdd\u8bc1\u6bcf\u4e00\u4e2a key\uff0c\u80fd\u591f\u6620\u5c04\u5230\u4e00\u4e2a\u69fd\u4f4d\u4e0a\u3002<\/span><\/span><\/span><\/p>\n

    \u4f46\u662f\uff0c\u4ed4\u7ec6\u4e00\u601d\u8003\uff0c\u5c31\u4f1a\u53d1\u73b0\uff0c\u5176\u5b9e\u8fd8\u6709\u95ee\u9898\u3002<\/span><\/span><\/span><\/p>\n

    \u9996\u5148\uff0c\u6211\u4eec\u5148\u8c08\u6211\u4eec\u719f\u6089\u7684\uff1aHashMap\u3002<\/span><\/span>
    \u6211\u4eec\u77e5\u9053\uff0c\u5982\u679c HashMap \u51fa\u73b0\u51b2\u7a81\u7684\u8bdd\uff0c\u4f1a\u7528\u4e00\u4e2a\u94fe\u8868\u53bb\u8fde\u63a5\u8d77\u90a3\u4e9b\u51b2\u7a81\u7684\u7ed3\u70b9\uff0c\u4ece\u800c\u4fdd\u8bc1\uff0c\u6240\u6709\u7684 key\uff0c\u90fd\u80fd\u5728\u91cc\u9762\u5b8c\u597d\u65e0\u7f3a\u7684\u5b58\u7740\uff0c\u4e0d\u5b58\u5728\u4e0d\u540c\u7684 key \u5c06\u5176\u4ed6 key \u6324\u5360\u7684\u60c5\u51b5\u3002<\/span><\/span><\/span><\/p>\n

    \u4f46\u662f\uff0c\u7531\u4e8e\u6b64\u65f6\u7684\u69fd\u4f4d\u5df2\u7ecf\u7f29\u51cf\u4e3a bit\uff0c\u5df2\u7ecf\u4e0d\u80fd\u591f\u518d\u5f80\u4e0a\u53bb\u8ffd\u52a0\u5176\u5b83\u7684\u6570\u636e\u7ed3\u6784\u4e86\uff0c\u6240\u4ee5\uff0c\u5c31\u65e0\u6cd5\u7528\u94fe\u8868\u89e3\u51b3\u51b2\u7a81\u78b0\u649e\u7684\u4ea7\u751f\u3002<\/span><\/span>
    \u800c\u4e14\uff0c\u4e0d\u5355\u5355\u662f\u4e0d\u80fd\u7528\u94fe\u8868\uff0c\u8fd8\u6709\u4e00\u4e2a\u539f\u56e0\uff0c\u5c31\u662f\u7531\u4e8e bit \u69fd\u4f4d\u53ea\u5b58 0\u30011\uff0c\u5373\u4f7f\u78b0\u649e\uff0c\u4e5f\u65e0\u6cd5\u5224\u65ad\u539f\u6709\u7684\u4fe1\u606f\u662f\u4ec0\u4e48\uff0c\u5230\u5e95\u662f\u4e0d\u662f\u540c\u4e00\u6761\u4fe1\u606f\u3002<\/span><\/span><\/span><\/p>\n

    \u6240\u4ee5\uff0cbitmap \u7531\u4e8e\u5b83\u7684\u7cbe\u7b80\uff0c\u56e0\u6b64\uff0c\u4e0d\u80fd\u591f\u5c06\u78b0\u649e\u7ed9\u6d88\u9664\u89e3\u51b3\u3002<\/span><\/span><\/span><\/p>\n

    \"Redis<\/p>\n

     <\/p>\n

    \u90a3\u4e48\uff0c\u8be5\u600e\u4e48\u529e\uff1f<\/span><\/span><\/span><\/p>\n

    \u5b9e\u9645\u4e0a\uff0c\u8fd9\u4e2a\u95ee\u9898\u662f\u65e0\u6cd5\u88ab\u5b8c\u5168\u89e3\u51b3\u7684\uff0c\u7531\u4e8e\u8282\u7701\u7a7a\u95f4\uff0c\u6bcf\u4e00\u4e2a\u69fd\u4f4d\u88ab\u7cbe\u7b80\u5230\u4e86\u4e00\u4e2a\u6bd4\u7279\uff0c\u6240\u4ee5\uff0c\u80fd\u8868\u793a\u7684\u4fe1\u606f\u5df2\u7ecf\u53ea\u6709 0\u30011 \u4e24\u79cd\uff0c\u4ece\u800c\u65e0\u6cd5\u8868\u793a\u51fa\u5176\u4ed6\u4fe1\u606f\u3002<\/span><\/span>
    \u9664\u975e\u589e\u52a0\u7a7a\u95f4\u6765\u4fdd\u5b58\u66f4\u591a\u7684\u4fe1\u606f\uff0c\u5426\u5219\u5c31\u65e0\u6cd5\u88ab\u89e3\u51b3\u3002<\/span><\/span><\/span><\/p>\n

    \u90a3\u4e48\uff0c\u5047\u8bbe\u589e\u52a0\u7a7a\u95f4\uff0c\u52a0\u4e00\u4e2a bit\uff0c\u4f53\u79ef\u5c31\u4f1a\u589e\u5927\u4e00\u500d\uff1b\u518d\u52a0\u4e24\u4e2a\uff0c\u4f53\u79ef\u53c8\u4f1a\u7ffb\u4e00\u500d\uff1b<\/span><\/span>
    \u770b\u8d77\u6765\uff0c\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4e3a\u4e86\u7edd\u5bf9\u7684\u89e3\u51b3\u51b2\u7a81\uff0c\u82b1\u8d39\u7684\u4ee3\u4ef7\uff0c\u662f\u6709\u70b9\u9ad8\u7684\u3002<\/span><\/span>
    \u6211\u4eec\u8d39\u5c3d\u5fc3\u601d\u8282\u4e0b\u6765\u7684\u7a7a\u95f4\uff0c\u53c8\u4f1a\u88ab\u91cd\u65b0\u82b1\u8d39\u3002<\/span><\/span><\/span><\/p>\n

    \u90a3\u4e48\uff0c\u65e2\u7136\u4f5c\u4e3a\u8f6f\u4ef6\u5de5\u7a0b\u7684\u5b66\u4e60\u8005\uff0c\u6211\u4eec\u5fc5\u987b\u6709\u8fd9\u4e48\u4e00\u4e2a\u601d\u7ef4\uff0c\u5c31\u662f\u4e0d\u8f83\u771f\uff0c\u4e0d\u53bb\u8ffd\u6c42\u6781\u9650\u3002<\/span><\/span>
    \u6bd4\u5982\u5f3a\u4e00\u81f4\u6027\uff0c\u56e0\u4e3a\u4f1a\u7834\u574f\u53ef\u7528\u6027\uff0c\u6240\u4ee5\u4e00\u822c\u90fd\u4f1a\u91c7\u53d6\u5f31\u4e00\u81f4\u6027\uff0c\u6216\u8005\u6700\u7ec8\u4e00\u81f4\u6027\u3002<\/span><\/span><\/span><\/p>\n

    \u8fd9\u91cc\u4e5f\u662f\u5982\u6b64\uff0c\u65e2\u7136\u4e0d\u80fd\u89e3\u51b3\u51b2\u7a81\u95ee\u9898\uff0c\u90a3\u4e48\uff0c\u53ef\u4ee5\u60f3\u529e\u6cd5\uff0c\u8ba9\u51b2\u7a81\u53d1\u751f\u7684\u6982\u7387\u66f4\u5c0f\uff0c\u800c\u4e0d\u662f\u53bb\u5b8c\u5168\u5730\u8ba9\u51b2\u7a81\u6d88\u5931\u3002<\/span><\/span><\/span><\/p>\n

    \u6240\u4ee5\uff0c\u5c31\u53ef\u4ee5\u5ef6\u4f38\u5230\u5e03\u9686\u7b97\u6cd5\u3002<\/span><\/span><\/span><\/p>\n

    \u9996\u5148\uff0c\u56e0\u4e3a\u5728\u5355\u6b21\u54c8\u5e0c\u7684\u60c5\u51b5\u4e0b\uff0c\u4f1a\u4ea7\u751f\u4e00\u5b9a\u7684\u78b0\u649e\uff1b<\/span><\/span>
    \u56e0\u6b64\uff0c\u4e3a\u4e86\u964d\u4f4e\u78b0\u649e\u800c\u5bfc\u81f4\u7684\u6982\u7387\uff0c\u4e8e\u662f\uff0c\u91c7\u7528\u591a\u6b21\u54c8\u5e0c\u7684\u65b9\u5f0f\uff0c\u6bcf\u4e00\u6b21\u54c8\u5e0c\u90fd\u5f80\u4e00\u4e2a\u69fd\u4f4d\u5199\u4e0a 1\uff1b<\/span><\/span>
    \u5f53\u6765\u67e5\u8be2\u4e00\u4e2a\u4e0d\u5b58\u5728\u7684 key \u7684\u65f6\u5019\uff0c\u5c31\u53ef\u4ee5\u8fdb\u884c\u540c\u6837\u7684\u591a\u6b21\u54c8\u5e0c\uff0c\u7b2c\u4e00\u6b21\u53ef\u80fd\u78b0\u5de7\u649e\u5bf9\uff0c\u5f97\u5230 1\uff0c\u4f46\u662f\u540e\u9762\u8fd8\u6709\u4e24\u6b21\uff0c\u8fd9\u6837\uff0c\u5c31\u4e0d\u4e00\u5b9a\u6709\u90a3\u4e48\u597d\u7684\u8fd0\u6c14\uff0c\u8fd8\u80fd\u591f\u649e\u5bf9\u3002<\/span><\/span>
    \u56e0\u6b64\uff0c\u8fd9\u6837\uff0c\u53ef\u4ee5\u964d\u4f4e\u7f13\u5b58\u7a7f\u900f\u7684\u6982\u7387\u3002<\/span><\/span><\/span><\/p>\n

    \u8fd9\u6837\uff0c\u53ea\u8981\u5bf9\u5e94\u51fa\u6211\u4eec\u7684\u9700\u6c42\uff0c\u53bb\u8c03\u6574 bitmap \u7684\u5927\u5c0f\uff0c\u4ee5\u53ca\u54c8\u5e0c\u51fd\u6570\u7684\u4e2a\u6570\uff0c\u5c31\u53ef\u4ee5\u5f97\u5230\u4e0d\u540c\u7684\u8fc7\u6ee4\u7684\u767e\u5206\u6bd4\uff0c\u867d\u7136\u53ef\u80fd\u51fa\u73b0\u6f0f\u7f51\u4e4b\u9c7c\uff0c\u4e0d\u8fc7\u90a3\u4e5f\u5df2\u7ecf\u662f\u5c11\u4e4b\u53c8\u5c11\u4e86\u3002<\/span><\/span><\/span><\/p>\n

    \"Redis
    \u4e0d\u8fc7\uff0c\u5bf9\u4e8e\u5e03\u9686\u8fc7\u6ee4\u5668\uff0c\u6211\u4eec\u7684\u4f7f\u7528\u8fd8\u662f\u9700\u8981\u53bb\u601d\u8003\u4e00\u4e0b\u7684\u3002<\/span><\/span><\/span><\/p>\n

     <\/p>\n

    \u9996\u5148\uff0c\u5bf9\u4e8e\u5e03\u9686\u8fc7\u6ee4\u5668\uff0c\u6211\u4eec\u53ef\u4ee5\u628a\u5b83\u653e\u5728\u5ba2\u6237\u7aef\u3002<\/span><\/span>
    \u4e5f\u5c31\u662f\u6bcf\u4e00\u4e2a\u5ba2\u6237\u7aef\u90fd\u5305\u542b\u8fd9\u4e48\u4e00\u4e2a\u7b97\u6cd5\uff0c\u4ee5\u53ca\u5b58\u50a8\u4e86\u4e00\u4e2a bitmap\uff0c\u6765\u8fc7\u6ee4\u65e0\u6548\u7684\u67e5\u8be2\u8bf7\u6c42\u3002<\/span><\/span>
    \u8fd9\u6837\uff0credis \u7684\u538b\u529b\u5c31\u6bd4\u8f83\u8f7b\u3002<\/span><\/span><\/span><\/p>\n

    \u4e0d\u8fc7\uff0c\u7531\u4e8e\u662f\u57fa\u4e8eJVM\u5185\u5b58\u7684\u4e00\u79cd\u5e03\u9686\u8fc7\u6ee4\u5668\uff0c<\/span><\/span>
    \u6240\u4ee5\u91cd\u542f\u5373\u5931\u6548\uff1b<\/span><\/span>
    \u800c\u4e14\u7531\u4e8e\u5b58\u50a8\u5728\u672c\u5730\u5185\u5b58\u4e2d\uff0c\u5bfc\u81f4\u65e0\u6cd5\u5e94\u7528\u5728\u5206\u5e03\u5f0f\u573a\u666f\uff1b<\/span><\/span>
    \u56e0\u6b64\u4e5f\u4e0d\u652f\u6301\u5927\u6570\u636e\u91cf\u5b58\u50a8\u3002<\/span><\/span><\/span><\/p>\n

    \u7b2c\u4e8c\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u9009\u62e9\uff0c\u5ba2\u6237\u7aef\u5305\u542b\u7b97\u6cd5\uff0c\u7136\u540e\uff0c\u628a bitmap\uff0c\u5b58\u5230 redis \u4e0a\u53bb\uff0c<\/span><\/span>
    \u8fd9\u6837\uff0c\u5ba2\u6237\u7aef\u5c31\u662f\u65e0\u72b6\u6001\u7684\uff0c\u56e0\u800c\u53ef\u4ee5\u8f7b\u677e\u7684\u590d\u5236\u3002<\/span><\/span><\/span><\/p>\n

    \u7b2c\u4e09\uff0c\u6216\u8005\uff0c\u8fd8\u53ef\u4ee5\uff0c\u76f4\u63a5\u628a\u7b97\u6cd5\uff0c\u548c bitmap\uff0c\u4e00\u5e76\u653e\u5230 redis \u4e0a\u53bb\uff0c\u4e5f\u5c31\u662f\u5728 redis \u5f53\u4e2d\u96c6\u6210\u8fd9\u4e48\u4e00\u4e2a\u6a21\u5757\u3002<\/span><\/span>
    \u8fd9\u6837\uff0c\u5ba2\u6237\u7aef\u5c31\u53c8\u7701\u53bb\u4e86\u4ee3\u7801\uff0c\u5c31\u80fd\u591f\u66f4\u52a0\u7075\u6d3b\uff1b<\/span><\/span>
    \u800c\u4e14\u4e5f\u7701\u53bb\u4e86\u91cd\u542f\u5931\u6548\u548c\u5b9a\u65f6\u4efb\u52a1\u7ef4\u62a4\u7684\u6210\u672c\uff1b<\/span><\/span>
    \u4f46\u662f\uff0c\u7531\u4e8e\u5e03\u9686\u8fc7\u6ee4\u5668\u5916\u8fc1\u5230\u4e86 redis \u4e0a\uff0c\u4ece\u800c\u4f1a\u5bfc\u81f4\u7f51\u7edc I\/O \u7684\u5f00\u9500\u589e\u5927\uff0c\u5e76\u4e14\u6027\u80fd\u4f1a\u6bd4\u5728 JVM \u4e0a\u7684 Google \u5e03\u9686\u8fc7\u6ee4\u5668\u6027\u80fd\u7565\u4f4e\u3002<\/span><\/span><\/span><\/p>\n

    \u4e0d\u7ba1\u600e\u6837\uff0c\u81f3\u5c11\uff0c\u7a7f\u900f\u7684\u95ee\u9898\uff0c\u4f3c\u4e4e\u5df2\u7ecf\u8fce\u6765\u4e86\u5927\u7ed3\u5c40\u3002<\/span><\/span><\/span><\/p>\n

    \u4e0d\u8fc7\uff0c\u4f60\u6709\u6ca1\u6709\u60f3\u5230\u5e03\u9686\u8fc7\u6ee4\u5668\u6709\u4e00\u4e2a\u7f3a\u70b9\uff0c<\/span><\/span>
    \u5c31\u662f\uff0c\u6211\u4eec\u8c08\u5230\u8fd9\u91cc\uff0c\u597d\u50cf\u53ea\u5b57\u672a\u63d0\uff0c\u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u5220\u9664\u3002<\/span><\/span>
    \u4e5f\u5c31\u662f\uff0c\u6211\u4eec\u7684\u5e03\u9686\u8fc7\u6ee4\u5668\uff0c\u53ea\u80fd\u5f80\u91cc\u8fb9\u6dfb\u52a0\u6570\u636e\uff0c\u800c\u4e0d\u80fd\u591f\u5220\u9664\u6570\u636e\u3002<\/span><\/span><\/span><\/p>\n

    \u4f60\u73b0\u5728\u60f3\u4e00\u60f3\uff0c\u662f\u4e0d\u662f\u8fd9\u4e48\u4e00\u4e2a\u60c5\u51b5\uff01<\/span><\/span><\/span><\/p>\n

    \u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u6570\u636e\u9891\u7e41\u589e\u5220\u6539\uff0c\u662f\u4e0d\u592a\u9002\u5408\u7528\u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u3002<\/span><\/span>
    \u56e0\u4e3a\uff0c\u4e00\u4e2a\u6570\u636e\u53d8\u66f4\u4e4b\u540e\uff0c\u5e03\u9686\u8fc7\u6ee4\u5668\u65e0\u6cd5\u5220\u9664 key\uff0c\u56e0\u6b64\uff0c\u53ea\u80fd\u91cd\u65b0\u521b\u5efa\u4e00\u4e2a\u5e03\u9686\u8fc7\u6ee4\u5668\uff0c\u518d\u52a0\u8f7d\u4e00\u904d\u6240\u6709\u7684\u6570\u636e\uff0c\u521b\u5efa\u51fa bitmap\u3002<\/span><\/span><\/span><\/p>\n

    \u90a3\u4e48\uff0c\u89e3\u51b3\u7684\u8bdd\uff0c\u53ef\u4ee5\u7528\u5e03\u8c37\u9e1f\u8fd9\u6837\u7684\uff0c\u5e26\u5220\u9664\u529f\u80fd\u7684\uff0c\u6765\u6ee1\u8db3\u52a8\u6001\u53d8\u5316\u7684\u9700\u6c42\u3002<\/span><\/span><\/span><\/p>\n

    \n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

    \n

    \n

    \u4e94\u3001\u7f13\u5b58\u96ea\u5d29\u89e3\u51b3\u65b9\u6848<\/strong><\/span><\/span><\/strong><\/strong><\/span><\/h3>\n\n\n\n
    \n

    \u6709\u4e00\u4e2a\u7b80\u5355\u65b9\u6848\u5c31\u65f6<\/span><\/span>\u5c06<\/span><\/span>\u7f13\u5b58\u5931\u6548\u65f6\u95f4\u5206\u6563\u5f00\uff0c\u6bd4\u5982\u6211\u4eec\u53ef\u4ee5\u5728\u539f\u6709\u7684\u5931\u6548\u65f6\u95f4\u57fa\u7840\u4e0a\u589e\u52a0\u4e00\u4e2a\u968f\u673a\u503c\uff0c\u6bd4\u59821-5\u5206\u949f\u968f\u673a\uff0c\u8fd9\u6837\u6bcf\u4e00\u4e2a\u7f13\u5b58\u7684\u8fc7\u671f\u65f6\u95f4\u7684\u91cd\u590d\u7387\u5c31\u4f1a\u964d\u4f4e\uff0c\u5c31\u5f88\u96be\u5f15\u53d1\u96c6\u4f53\u5931\u6548\u7684\u4e8b\u4ef6\u3002<\/span><\/span>\u6216\u8005Redis\u67e5DB\u6570\u636e\u7684\u65f6\u5019\u5c06\u8bf7\u6c42\u52a0\u4e00\u4e2a\u968f\u673a\u5ef6\u8fdf\u65f6\u95f4\uff0c\u8ba9\u8bf7\u6c42\u4e0d\u8981\u96c6\u4e2d\u3002<\/span><\/span><\/p>\n

    \n\n\n\n
    \n

    \/\/\u4f2a\u4ee3\u7801<\/span><\/span><\/p>\n

    public object GetProductListNew() {
    \n <\/span><\/span><\/p>\n

        int cacheTime = 30;<\/span><\/span><\/p>\n

        String cacheKey = \"product_list\";<\/span><\/span><\/p>\n

        \/\/\u7f13\u5b58\u6807\u8bb0<\/span><\/span><\/p>\n

        String cacheSign = cacheKey + \"_sign\";<\/span><\/span><\/p>\n

    \n

        String sign = CacheHelper.Get(cacheSign);<\/span><\/span><\/p>\n

        \/\/\u83b7\u53d6\u7f13\u5b58\u503c<\/span><\/span><\/p>\n

        String cacheValue = CacheHelper.Get(cacheKey);<\/span><\/span><\/p>\n

        if (sign != null) {
    \n <\/span><\/span><\/p>\n

            return cacheValue; \/\/\u672a\u8fc7\u671f\uff0c\u76f4\u63a5\u8fd4\u56de<\/span><\/span><\/p>\n

        } else {
    \n <\/span><\/span><\/p>\n

            CacheHelper.Add(cacheSign, \"1\", cacheTime);<\/span><\/span><\/p>\n

            ThreadPool.QueueUserWorkItem((arg) -> {
    \n <\/span><\/span><\/p>\n

          \/\/\u8fd9\u91cc\u4e00\u822c\u662f sql\u67e5\u8be2\u6570\u636e<\/span><\/span><\/p>\n

                cacheValue = GetProductListFromDB(); <\/span><\/span><\/p>\n

              \/\/\u65e5\u671f\u8bbe\u7f13\u5b58\u65f6\u95f4\u76842\u500d\uff0c\u7528\u4e8e\u810f\u8bfb<\/span><\/span><\/p>\n

              CacheHelper.Add(cacheKey, cacheValue, cacheTime * 2);                 <\/span><\/span><\/p>\n

            });<\/span><\/span><\/p>\n

            return cacheValue;<\/span><\/span><\/p>\n

        }<\/span><\/span><\/p>\n

    } <\/span><\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

    \n

    \n

    \u7f13\u5b58\u96ea\u5d29<\/span><\/span>
    \u5176\u5b9e\u628a\u7f13\u5b58\u51fb\u7a7f\u641e\u6e05\u695a\u4e86\uff0c\u90a3\u4e48\u4f60\u53bb\u7406\u89e3\u7f13\u5b58\u96ea\u5d29\u4e5f\u4f1a\u5bb9\u6613\u8bb8\u591a\u3002<\/span><\/span><\/span><\/p>\n

    \u7f13\u5b58\u96ea\u5d29\uff0c\u6307\u7684\u662f\u5927\u9762\u79ef\u7684 key \u540c\u65f6\u8fc7\u671f\uff0c\u5bfc\u81f4\u5927\u91cf\u5e76\u53d1\u6253\u5230\u6211\u4eec\u7684\u6570\u636e\u5e93\u3002<\/span><\/span>
    \u4e0d\u50cf\u51fb\u7a7f\uff0c\u53ea\u662f\u56e0\u4e3a 1 \u4e2a key \u7684\u8fc7\u671f\u3002<\/span><\/span><\/span><\/p>\n

    \u6240\u4ee5\uff0c\u5bf9\u4e8e\u96ea\u5d29\u6765\u8bf4\uff0c\u4e00\u822c\uff0c\u5c11\u91cf\u7684 key \u5931\u6548\uff0c\u6240\u5e26\u6765\u7684\u6570\u636e\u5e93\u7684\u5e76\u53d1\u538b\u529b\u662f\u4e0d\u4f1a\u592a\u5927\u7684\u3002<\/span><\/span>
    \u800c\u662f\u5927\u91cf key \u7684\u540c\u65f6\u5931\u6548\uff0c\u5bfc\u81f4\u6240\u6709 key \u7684\u5e76\u53d1\u52a0\u8d77\u6765\uff0c\u4f1a\u5f71\u54cd\u5230\u6211\u4eec\u7684\u6570\u636e\u5e93\u3002<\/span><\/span><\/span><\/p>\n

    \u90a3\u5c31\u7b97\u4e00\u4e2a key \u5931\u6548\uff0c\u4e5f\u4f1a\u5bf9\u6570\u636e\u5e93\u9020\u6210\u5f88\u5927\u7684\u5f71\u54cd\uff0c\u90a3\u4e48\u4f60\u628a\u96ea\u5d29\u7684\u6240\u6709 key \u62c6\u6210\u4e00\u4e2a\u4e00\u4e2a key \u6765\u770b\uff0c\u4e5f\u5c31\u662f\u96ea\u5d29\u53ef\u4ee5\u62c6\u5206\u6210\u4e00\u4e2a\u4e00\u4e2a\u7f13\u5b58\u51fb\u7a7f\u7684\u96c6\u5408\u3002<\/span><\/span><\/span><\/p>\n

    \u5176\u5b9e\u5728\u771f\u5b9e\u573a\u666f\u4e2d\uff0c\u96ea\u5d29\u624d\u662f\u4e00\u4e2a\u66f4\u5bb9\u6613\u53d1\u751f\u7684\u4e00\u4e2a\u95ee\u9898\uff0c\u5b83\u4e0d\u50cf\u51fb\u7a7f\u90a3\u4e48\u6781\u7aef\uff0c\u4e00\u4e2a key \u5c31\u6210\u5343\u4e0a\u4e07\u7684\u5e76\u53d1\uff0c\u76f4\u63a5\u628a\u6570\u636e\u5e93\u6253\u57ae\u4e86\uff1b<\/span><\/span>
    \u800c\u662f\uff0c\u53ef\u80fd\u5c31\u4e00\u4e2a key \u51e0\u5341\u51e0\u767e\u7684\u5e76\u53d1\uff0c\u7136\u540e\u5927\u91cf\u7684 key \u4e00\u8fc7\u671f\uff0c\u7136\u540e\u5c31\u4f7f\u5f97\u597d\u591a\u5e76\u53d1\uff0c\u540c\u65f6\u53e0\u52a0\u8d77\u6765\uff0c\u7d2f\u79ef\u5230\u4e0a\u5343\u4e0a\u4e07\u4e2a\uff0c\u628a\u6570\u636e\u5e93\u6253\u5d29\u4e86\u3002<\/span><\/span><\/span><\/p>\n

    \u90a3\u4e48\u65e2\u7136\u7f13\u5b58\u51fb\u7a7f\u5df2\u7ecf\u7ed9\u8fc7\u89e3\u51b3\u65b9\u6848\u4e86\uff0c\u90a3\u4e48\u6211\u4eec\u73b0\u5728\u8981\u5173\u6ce8\u7684\uff0c\u5219\u662f\u5982\u4f55\u7f13\u89e3\u96ea\u5d29\u6240\u5e26\u6765\u7684\u538b\u529b\u3002<\/span><\/span><\/span><\/p>\n

    \u56e0\u4e3a\uff0ckey \u662f\u540c\u65f6\u5931\u6548\uff0c\u6240\u4ee5\u5bfc\u81f4\u5f88\u591a key \u7684\u5e76\u53d1\uff0c\u4e00\u8d77\u538b\u4e0a\u6765\uff0c\u624d\u4f1a\u4f7f\u5f97\u6570\u636e\u5e93\u7684\u5e76\u53d1\u538b\u529b\u8fc7\u5927\uff0c<\/span><\/span>
    \u6240\u4ee5\uff0c\u6211\u4eec\u5f88\u6b63\u5e38\u7684\u601d\u8def\u5c31\u662f\uff0c\u5c31\u662f\u8ba9\u5e76\u53d1\u5206\u6563\u5f00\u6765\u3002<\/span><\/span><\/span><\/p>\n

    \u9996\u5148\u4e00\u4e2a\u5f88\u5e38\u89c1\u7684\u505a\u6cd5\u5c31\u662f\uff0c\u5206\u6563 key \u7684\u8fc7\u671f\u65f6\u95f4\u3002<\/span><\/span><\/span><\/p>\n

    \u786e\u5b9e\uff0c\u8fd9\u4e48\u505a\u662f\u53ef\u884c\u7684\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u95ee\u9898\u7684\u672c\u8d28\uff0c\u5c31\u662f\u8981\u8ba9\u77ac\u95f4\u5230\u6765\u7684\u5e76\u53d1\uff0c\u628a\u5b83\u5206\u6563\u5f00\u3002<\/span><\/span>
    \u800c\u7ed9\u4e86\u4e00\u5b9a\u7684\u968f\u673a\u8fc7\u671f\u65f6\u95f4\u4e4b\u540e\uff0c\u5c31\u80fd\u591f\u4f7f\u5f97 key \u4f1a\u5206\u6563\u5f00\uff0c\u4e00\u4e2a\u4e00\u4e2a\u8fc7\u671f\uff0c<\/span><\/span>
    \u6240\u4ee5\uff0c\u5e76\u53d1\u91cf\u5c31\u4f1a\u5206\u6210\u4e00\u90e8\u5206\uff0c\u4e00\u90e8\u5206\uff0c\u5c11\u91cf\u7684\u6253\u5230\u6570\u636e\u5e93\u4e0a\u3002<\/span><\/span><\/span><\/p>\n

    \u770b\u8d77\u6765\u5c31\u5f88\u50cf\u4e00\u4e2a\u524a\u5cf0\u7684\u64cd\u4f5c\u3002<\/span><\/span><\/span><\/p>\n

    \u8fd9\u4e2a\u65b9\u6cd5\uff0c\u662f\u6700\u7b80\u5355\u6709\u6548\u7684\u3002\u6240\u4ee5\u4e00\u822c\u60c5\u51b5\uff0c\u6211\u4eec\u90fd\u91c7\u7528\u8fd9\u79cd\u65b9\u5f0f\u3002<\/span><\/span><\/span><\/p>\n

    \"Redis
    \u4e0d\u8fc7\uff0c\u8981\u8003\u8651\u4e00\u79cd\u60c5\u51b5\uff0c\u5c31\u662f\uff0c\u5982\u679c\u4f60\u7684\u4e1a\u52a1\u5bf9\u65f6\u70b9\u6027\u8981\u6c42\u9ad8\uff0c\u5fc5\u987b\u6bcf\u5929\u7684\u6307\u5b9a\u65f6\u95f4\uff0c\u53bb\u66f4\u65b0\u6211\u4eec\u7684\u6570\u636e\u3002<\/span><\/span>
    \u5c31\u6bd4\u5982\u6e38\u620f\u6bcf\u65e5\u96f6\u70b9\u66f4\u65b0\uff0c\u6216\u8005\u8d22\u62a5\u8bb0\u5f55\u2026\u2026\u7b49\u7b49\u7b49\u7b49\u3002<\/span><\/span><\/span><\/p>\n

     <\/p>\n

    \u5c31\u662f\uff0c\u5728\u67d0\u4e00\u4e2a\u56fa\u5b9a\u7684\u65f6\u95f4\uff0c\u7531\u4e8e\u4e1a\u52a1\u8981\u6c42\uff0c\u5fc5\u987b\u4f7f\u5f97\u6570\u636e\u5237\u65b0\uff0c\u5e76\u4e14\u4e0d\u5141\u8bb8\u51fa\u73b0\u65e7\u6570\u636e\u3002<\/span><\/span>
    \u6240\u4ee5\uff0c\u5fc5\u987b\u8ba9\u7f13\u5b58\u5168\u90e8\u5931\u6548\u3002<\/span><\/span><\/span><\/p>\n

    \u50cf\u8fd9\u6837\u7684\u4e1a\u52a1\u5e94\u8be5\u600e\u4e48\u529e\uff1f<\/span><\/span><\/span><\/p>\n

    \u56e0\u4e3a\u8fd9\u4e2a\u573a\u666f\uff0c\u975e\u5e38\u7c7b\u4f3c\u524a\u5cf0\u64cd\u4f5c\uff0c\u6240\u4ee5\u6709\u4eba\u4f1a\u89c9\u5f97\uff0c\u53ef\u4ee5\u7528 MQ\uff0c\u5148\u628a\u8bfb\u8bf7\u6c42\u6253\u5165 MQ\uff0c\u518d\u4e00\u4e2a\u4e00\u4e2a\u4f9d\u6b21\u6d88\u8d39\u3002<\/span><\/span><\/span><\/p>\n

    \"Redis<\/p>\n

     <\/p>\n

    \u8fd9\u6837\u53ef\u884c\u5417\uff1f<\/span><\/span><\/span><\/p>\n

    \u9996\u5148\uff0c\u4ece\u7cfb\u7edf\u5b9e\u73b0\u6765\u8bf4\uff0c\u662f\u53ef\u4ee5\u4fdd\u8bc1\uff0c\u6570\u636e\u5e93\u7684\u8bf7\u6c42\u538b\u529b\u5148\u88ab\u625b\u4e0b\u6765\uff0c\u7136\u540e\u5f02\u6b65\u6d88\u8d39\u3002<\/span><\/span>
    \u4f46\u662f\uff0c\u5bf9\u4e8e\u8bfb\u8bf7\u6c42\uff0c\u662f\u4e0d\u5e94\u8be5\u7528\u5230\u6d88\u606f\u961f\u5217\u7684\u3002<\/span><\/span>
    \u5982\u679c\u662f\u5f02\u6b65\u5199\uff0c\u6ca1\u6709\u4ec0\u4e48\u95ee\u9898\uff0c\u7528\u6237\u53ea\u8981\u6c42\u80fd\u628a\u6570\u636e\u5b58\u5165\u5373\u53ef\u3002<\/span><\/span>
    \u4f46\u662f\u5bf9\u4e8e\u8bfb\uff0c\u5982\u679c\u7528\u961f\u5217\u4f9d\u6b21\u8bfb\u53d6\uff0c\u90a3\u4e48\uff0c\u5927\u91cf\u7528\u6237\u7684\u54cd\u5e94\u5ef6\u8fdf\uff0c\u5c31\u4f1a\u53d8\u9ad8\uff0c\u8fd9\u5bf9\u7528\u6237\u4f53\u9a8c\u7684\u5f71\u54cd\u662f\u4e0d\u5bb9\u5ffd\u89c6\u7684\u3002<\/span><\/span><\/span><\/p>\n

    \u6240\u4ee5\uff0c\u5bf9\u4e8e\u8bfb\u8bf7\u6c42\uff0c\u4e0d\u9002\u5408\u7528\u961f\u5217\u7684\u65b9\u5f0f\uff0c\u56e0\u4e3a\u8fd9\u5df2\u7ecf\u628a\u8bf7\u6c42\u4e32\u884c\u5316\u4e86\uff0c\u4e0d\u518d\u662f\u5e76\u53d1\u6267\u884c\u3002<\/span><\/span><\/span><\/p>\n

    \u4e8e\u662f\uff0c\u8fd8\u6709\u4eba\u63d0\u51fa\u89c2\u70b9\uff0c\u8ba9\u7f13\u5b58\u63d0\u524d\u5f00\u59cb\u66f4\u65b0\u3002<\/span><\/span><\/span><\/p>\n

    \u4f46\u662f\uff0c\u63d0\u524d\u66f4\u65b0\u4e86\u4e4b\u540e\uff0c\u6bd4\u5982 58 \u5206\u5f00\u59cb\u66f4\u65b0\uff0c59 \u5206\u7684\u65f6\u5019\uff0c\u6709\u5927\u91cf\u6570\u636e\u53c8\u88ab\u4fee\u6539\u4e86\u5462\uff1f<\/span><\/span>
    \u6240\u4ee5\uff0c\u6570\u636e\u662f\u4e0d\u51c6\u786e\u7684\uff0c\u90a3\u4e9b 59 \u5206\u4fee\u6539\u4e86\u4e4b\u540e\u7684\u5ba2\u6237\uff0c\u5728 12 \u70b9\u67e5\u770b\u6570\u636e\u7684\u65f6\u5019\uff0c\u53d1\u73b0\u6570\u636e\u4ecd\u7136\u6ca1\u6709\u53d8\u5316\uff0c\u4ed6\u4eec\u5c31\u4f1a\u8ba4\u4e3a\uff0c\u7cfb\u7edf\u7684 12 \u70b9\u66f4\u65b0\u7684\u8bf4\u6cd5\u4e0d\u9760\u8c31\uff0c\u516c\u53f8\u4e0d\u503c\u5f97\u4fe1\u4efb\u3002<\/span><\/span><\/span><\/p>\n

    \u6240\u4ee5\uff0c\u7f13\u5b58\u662f\u5fc5\u987b\u8981\u5728 12 \u70b9\u51c6\u65f6\u5931\u6548\uff0c\u51c6\u65f6\u66f4\u65b0\u7684\u3002\u4f60\u65e0\u6cd5\u8ba9\u66f4\u65b0\u65f6\u95f4\u8fdb\u884c\u53d8\u5316\u3002<\/span><\/span><\/span><\/p>\n

    \u90a3\u4e48\uff0c\u4f60\u8fd8\u80fd\u60f3\u5230\u4ec0\u4e48\u529e\u6cd5\uff1f<\/span><\/span><\/span><\/p>\n

    \u56e0\u4e3a\u6b64\u523b\uff0credis \u4e2d\u7684\u6570\u636e\uff0c\u662f\u5fc5\u987b\u7acb\u5373\u5931\u6548\u7684\uff0c\u4f60\u4e0d\u80fd\u591f\u6539\u53d8\u3002<\/span><\/span>
    \u90a3\u4e48\uff0c\u5bf9\u4e8e redis\uff0c\u5c31\u4e0d\u80fd\u591f\u628a\u65f6\u95f4\u5206\u6563\u5f00\u6765\u3002<\/span><\/span><\/span><\/p>\n

    \u65e2\u7136 redis \u4e0d\u53ef\u4ee5\uff0c\u90a3\u4e48\u5176\u5b83\u5730\u65b9\u53ef\u4ee5\u5417\uff1f<\/span><\/span><\/span><\/p>\n

    \u6240\u4ee5\uff0c\u8fd9\u5c31\u662f\u8003\u9a8c\u4f60\u601d\u7ef4\u548c\u529f\u529b\u7684\u65f6\u5019\u3002<\/span><\/span><\/span><\/p>\n

    \u65e2\u7136 redis \u65e0\u6cd5\u5206\u6563\u8fc7\u671f\u65f6\u95f4\uff0c\u90a3\u4e48\uff0c\u6211\u4eec\u53bb\u67e5\u6570\u636e\u7684\u65f6\u5019\uff0c\u662f\u4e0d\u662f\u53ef\u4ee5\u628a\u65f6\u95f4\u7a0d\u5fae\u5730\u5206\u6563\u4e00\u4e0b\uff1f<\/span><\/span><\/span><\/p>\n

    \u6240\u4ee5\u5230\u4e86\u4e0b\u9762\u8fd9\u79cd\u60c5\u666f\uff1a<\/span><\/span><\/span><\/p>\n

    \u65f6\u95f4\u4e00\u5230\uff0credis \u6570\u636e\u5168\u90e8\u5931\u6548\uff1b<\/span><\/span>
    \u5927\u91cf\u5e76\u53d1\u524d\u6765\u67e5\u8be2\uff1b<\/span><\/span>
    \u5728 service \u670d\u52a1\u5c42\uff0c\u67e5\u8be2\u65f6\uff0c\u8bbe\u7f6e\u4e00\u4e2a\u77ed\u6682\u7684\u968f\u673a\u5ef6\u8fdf\u65f6\u95f4\uff1b<\/span><\/span>
    \u8fd9\u6837\uff0c\u4e8e\u662f\u67e5\u8be2\u7684\u64cd\u4f5c\uff0c\u5c31\u88ab\u5206\u6563\u4e86\u5f00\u6765\uff1b<\/span><\/span>
    \u5c11\u91cf\u7684\u8bf7\u6c42\uff0c\u5148\u67e5\u8be2\uff0c\u5c31\u4f1a\u8bfb\u6570\u636e\u5e93\uff0c\u7136\u540e\u5b58\u5165 redis\uff1b<\/span><\/span>
    \u5176\u4ed6\u8bf7\u6c42\uff0c\u7531\u4e8e\u968f\u673a\u65f6\u95f4\uff0c\u7a0d\u7a0d\u6162\u4e86\u70b9\uff0c\u5c31\u53ef\u4ee5\u53bb redis \u8bfb\u51fa\u6570\u636e\u3002<\/span><\/span><\/span><\/p>\n

    \"Redis
    \u8fd9\u5c31\u662f\uff0c\u4ece\u4e1a\u52a1\u5c42\uff0c\u518d\u628a\u65f6\u95f4\u5206\u6563\u3002<\/span><\/span><\/span><\/p>\n

     <\/p>\n

    \u5e26\u6765\u7684\u5f71\u54cd\uff0c\u4e5f\u5c31\u662f\u5ba2\u6237\u7b49\u5f85\u65f6\uff0c\u4f1a\u591a\u90a3\u4e48\u51e0\u5341\u6beb\u79d2\u7684\u5ef6\u8fdf\uff0c\u4e0d\u8fc7\u5bf9\u4e8e\u4eba\u6765\u8bf4\uff0c\u662f\u5fae\u4e4e\u5176\u5fae\uff0c\u53ef\u4ee5\u63a5\u53d7\u7684\u3002<\/span><\/span><\/span><\/p>\n

    \u6240\u4ee5\uff0c\u5bf9\u4e8e\u65f6\u70b9\u6027\u8981\u6c42\u9ad8\u7684\u4e1a\u52a1\u8981\u6c42\uff0c\u96ea\u5d29\u7684\u95ee\u9898\uff0c\u60f3\u8981\u89e3\u51b3\uff0c\u8fd8\u5fc5\u987b\u7a0d\u5fae\u591a\u601d\u8003\uff0c\u53d8\u901a\u4e00\u4e0b\u3002<\/span><\/span><\/span><\/p>\n

    \n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

    \u6765\u6e90\uff1aRedis\u7f13\u5b58\u51fb\u7a7f\u3001\u96ea\u5d29\u3001\u7a7f\u900f\uff01\uff08\u8d85\u8be6\u7ec6\uff09_lin777lin\u7684\u535a\u5ba2-CSDN\u535a\u5ba2_redis\u7f13\u5b58\u51fb\u7a7f<\/p>\n

    \u6765\u6e90\uff1aREDIS\u7f13\u5b58\u7a7f\u900f\uff0c\u7f13\u5b58\u51fb\u7a7f\uff0c\u7f13\u5b58\u96ea\u5d29\u539f\u56e0+\u89e3\u51b3\u65b9\u6848 - \u5927\u7801\u54e5 - \u535a\u5ba2\u56ed<\/p>\n","protected":false},"excerpt":{"rendered":"Redis \u7f13\u5b58\u51fb\u7a7f\uff0c\u7f13\u5b58\u7a7f\u900f\uff0c\u7f13\u5b58\u96ea\u5d29\u539f\u56e0+\u89e3\u51b3\u65b9\u6848\u4e00\u3001\u524d\u8a00\t\t\t\u5728\u6211\u4eec\u65e5\u5e38\u7684\u5f00\u53d1\u4e2d\uff0c\u65e0\u4e0d\u90fd\u662f\u4f7f\u7528\u6570\u636e\u5e93\u6765\u8fdb\u884c\u6570\u636e\u7684\u5b58\u50a8\uff0c\u7531...","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\/644"}],"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=644"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/644\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=644"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=644"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=644"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}