{"id":197689,"date":"2024-11-14T09:53:54","date_gmt":"2024-11-14T01:53:54","guid":{"rendered":"https:\/\/server.hk\/cnblog\/197689\/"},"modified":"2024-11-14T09:53:55","modified_gmt":"2024-11-14T01:53:55","slug":"%e5%88%a9%e7%94%a8solr%e5%92%8credis%e6%8f%90%e9%ab%98%e6%90%9c%e7%b4%a2%e5%92%8c%e7%b7%a9%e5%ad%98%e6%95%88%e7%8e%87%ef%bc%88solr%e5%92%8credis%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/197689\/","title":{"rendered":"\u5229\u7528Solr\u548cRedis\u63d0\u9ad8\u641c\u7d22\u548c\u7de9\u5b58\u6548\u7387\uff08solr\u548credis\uff09"},"content":{"rendered":"<h1 id=\"%e5%88%a9%e7%94%a8solr%e5%92%8credis%e6%8f%90%e9%ab%98%e6%90%9c%e7%b4%a2%e5%92%8c%e7%b7%a9%e5%ad%98%e6%95%88%e7%8e%87-nvpAmnXMnA\">\u5229\u7528Solr\u548cRedis\u63d0\u9ad8\u641c\u7d22\u548c\u7de9\u5b58\u6548\u7387<\/h1>\n<p>\u5728\u7576\u4eca\u6578\u64da\u9a45\u52d5\u7684\u4e16\u754c\u4e2d\uff0c\u5feb\u901f\u800c\u6e96\u78ba\u7684\u641c\u7d22\u529f\u80fd\u5c0d\u65bc\u4efb\u4f55\u61c9\u7528\u7a0b\u5e8f\u6216\u7db2\u7ad9\u90fd\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u96a8\u8457\u6578\u64da\u91cf\u7684\u6fc0\u589e\uff0c\u50b3\u7d71\u7684\u641c\u7d22\u89e3\u6c7a\u65b9\u6848\u5f80\u5f80\u7121\u6cd5\u6eff\u8db3\u7528\u6236\u7684\u9700\u6c42\u3002\u70ba\u4e86\u89e3\u6c7a\u9019\u4e00\u554f\u984c\uff0c\u8a31\u591a\u958b\u767c\u8005\u9078\u64c7\u5c07Apache Solr\u548cRedis\u7d50\u5408\u4f7f\u7528\uff0c\u4ee5\u63d0\u9ad8\u641c\u7d22\u548c\u7de9\u5b58\u7684\u6548\u7387\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afsolr%ef%bc%9f-nvpAmnXMnA\">\u4ec0\u9ebc\u662fSolr\uff1f<\/h2>\n<p>Apache Solr\u662f\u4e00\u500b\u57fa\u65bcLucene\u7684\u958b\u6e90\u641c\u7d22\u5e73\u53f0\uff0c\u5c08\u70ba\u8655\u7406\u5927\u91cf\u6578\u64da\u800c\u8a2d\u8a08\u3002\u5b83\u63d0\u4f9b\u4e86\u5f37\u5927\u7684\u5168\u6587\u641c\u7d22\u529f\u80fd\uff0c\u652f\u6301\u591a\u7a2e\u67e5\u8a62\u8a9e\u8a00\uff0c\u4e26\u80fd\u5920\u8655\u7406\u8907\u96dc\u7684\u641c\u7d22\u9700\u6c42\u3002Solr\u7684\u4e3b\u8981\u7279\u9ede\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u5168\u6587\u641c\u7d22\uff1a<\/strong>\u652f\u6301\u591a\u7a2e\u6587\u672c\u5206\u6790\u548c\u67e5\u8a62\u529f\u80fd\u3002<\/li>\n<li><strong>\u5206\u9762\u641c\u7d22\uff1a<\/strong>\u80fd\u5920\u6839\u64da\u4e0d\u540c\u7684\u5c6c\u6027\u9032\u884c\u5206\u985e\u548c\u7be9\u9078\u3002<\/li>\n<li><strong>\u9ad8\u53ef\u64f4\u5c55\u6027\uff1a<\/strong>\u80fd\u5920\u8655\u7406\u6578\u767e\u842c\u689d\u8a18\u9304\u3002<\/li>\n<li><strong>\u5be6\u6642\u7d22\u5f15\uff1a<\/strong>\u652f\u6301\u5373\u6642\u66f4\u65b0\u6578\u64da\u3002<\/li>\n<\/ul>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afredis%ef%bc%9f-nvpAmnXMnA\">\u4ec0\u9ebc\u662fRedis\uff1f<\/h2>\n<p>Redis\u662f\u4e00\u500b\u9ad8\u6027\u80fd\u7684\u9375\u503c\u5b58\u5132\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u7528\u65bc\u7de9\u5b58\u548c\u6578\u64da\u5b58\u5132\u3002\u5b83\u7684\u4e3b\u8981\u7279\u9ede\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u9ad8\u6548\u80fd\uff1a<\/strong>\u80fd\u5920\u5728\u6beb\u79d2\u7d1a\u5225\u5167\u8655\u7406\u8acb\u6c42\u3002<\/li>\n<li><strong>\u6301\u4e45\u5316\uff1a<\/strong>\u652f\u6301\u6578\u64da\u6301\u4e45\u5316\uff0c\u80fd\u5920\u5c07\u6578\u64da\u4fdd\u5b58\u5230\u78c1\u789f\u4e2d\u3002<\/li>\n<li><strong>\u591a\u7a2e\u6578\u64da\u7d50\u69cb\uff1a<\/strong>\u652f\u6301\u5b57\u7b26\u4e32\u3001\u54c8\u5e0c\u3001\u5217\u8868\u3001\u96c6\u5408\u7b49\u591a\u7a2e\u6578\u64da\u985e\u578b\u3002<\/li>\n<li><strong>\u5206\u4f48\u5f0f\uff1a<\/strong>\u652f\u6301\u5206\u4f48\u5f0f\u67b6\u69cb\uff0c\u80fd\u5920\u8f15\u9b06\u64f4\u5c55\u3002<\/li>\n<\/ul>\n<h2 id=\"solr%e5%92%8credis%e7%9a%84%e7%b5%90%e5%90%88%e4%bd%bf%e7%94%a8-nvpAmnXMnA\">Solr\u548cRedis\u7684\u7d50\u5408\u4f7f\u7528<\/h2>\n<p>\u5c07Solr\u548cRedis\u7d50\u5408\u4f7f\u7528\uff0c\u53ef\u4ee5\u5145\u5206\u767c\u63ee\u5169\u8005\u7684\u512a\u52e2\uff0c\u5f9e\u800c\u63d0\u9ad8\u641c\u7d22\u6548\u7387\u548c\u6578\u64da\u5b58\u53d6\u901f\u5ea6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5177\u9ad4\u7684\u61c9\u7528\u5834\u666f\uff1a<\/p>\n<h3 id=\"1-%e6%90%9c%e7%b4%a2%e7%b5%90%e6%9e%9c%e7%9a%84%e7%b7%a9%e5%ad%98-nvpAmnXMnA\">1. \u641c\u7d22\u7d50\u679c\u7684\u7de9\u5b58<\/h3>\n<p>\u5728\u4f7f\u7528Solr\u9032\u884c\u641c\u7d22\u6642\uff0c\u67d0\u4e9b\u67e5\u8a62\u53ef\u80fd\u6703\u983b\u7e41\u91cd\u8907\u3002\u9019\u6642\uff0c\u53ef\u4ee5\u5c07\u9019\u4e9b\u67e5\u8a62\u7684\u7d50\u679c\u7de9\u5b58\u5728Redis\u4e2d\u3002\u7576\u7528\u6236\u518d\u6b21\u767c\u51fa\u76f8\u540c\u7684\u67e5\u8a62\u6642\uff0c\u7cfb\u7d71\u53ef\u4ee5\u76f4\u63a5\u5f9eRedis\u4e2d\u7372\u53d6\u7d50\u679c\uff0c\u800c\u7121\u9700\u518d\u6b21\u67e5\u8a62Solr\uff0c\u9019\u6a23\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u97ff\u61c9\u901f\u5ea6\u3002<\/p>\n<pre><code>\n# \u5047\u8a2d\u4f7f\u7528Python\u9032\u884c\u67e5\u8a62\ndef search(query):\n    # \u5617\u8a66\u5f9eRedis\u4e2d\u7372\u53d6\u7de9\u5b58\u7d50\u679c\n    cached_result = redis.get(query)\n    if cached_result:\n        return cached_result  # \u8fd4\u56de\u7de9\u5b58\u7d50\u679c\n    else:\n        # \u5982\u679c\u6c92\u6709\u7de9\u5b58\uff0c\u5247\u67e5\u8a62Solr\n        result = solr.query(query)\n        # \u5c07\u7d50\u679c\u5b58\u5165Redis\n        redis.set(query, result)\n        return result\n<\/code><\/pre>\n<h3 id=\"2-%e5%af%a6%e6%99%82%e6%95%b8%e6%93%9a%e6%9b%b4%e6%96%b0-nvpAmnXMnA\">2. \u5be6\u6642\u6578\u64da\u66f4\u65b0<\/h3>\n<p>\u5728\u67d0\u4e9b\u61c9\u7528\u4e2d\uff0c\u6578\u64da\u7684\u5be6\u6642\u6027\u81f3\u95dc\u91cd\u8981\u3002\u4f7f\u7528Redis\u4f5c\u70ba\u7de9\u5b58\u5c64\uff0c\u53ef\u4ee5\u5728\u6578\u64da\u66f4\u65b0\u6642\u7acb\u5373\u66f4\u65b0Redis\u4e2d\u7684\u6578\u64da\uff0c\u7136\u5f8c\u518d\u5c07\u66f4\u65b0\u7684\u6578\u64da\u63a8\u9001\u5230Solr\u4e2d\u3002\u9019\u6a23\u53ef\u4ee5\u78ba\u4fdd\u7528\u6236\u5728\u641c\u7d22\u6642\u7372\u5f97\u6700\u65b0\u7684\u6578\u64da\u3002<\/p>\n<pre><code>\n# \u66f4\u65b0\u6578\u64da\u7684\u793a\u4f8b\ndef update_data(key, value):\n    # \u66f4\u65b0Redis\u4e2d\u7684\u6578\u64da\n    redis.set(key, value)\n    # \u66f4\u65b0Solr\u4e2d\u7684\u6578\u64da\n    solr.update(key, value)\n<\/code><\/pre>\n<h3 id=\"3-%e5%88%86%e6%9e%90%e5%92%8c%e5%a0%b1%e5%91%8a-nvpAmnXMnA\">3. \u5206\u6790\u548c\u5831\u544a<\/h3>\n<p>\u901a\u904e\u5c07\u641c\u7d22\u8acb\u6c42\u548c\u7d50\u679c\u5b58\u5132\u5728Redis\u4e2d\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u8f15\u9b06\u5730\u9032\u884c\u6578\u64da\u5206\u6790\uff0c\u4e86\u89e3\u7528\u6236\u7684\u641c\u7d22\u884c\u70ba\uff0c\u4e26\u6839\u64da\u9019\u4e9b\u6578\u64da\u9032\u884c\u512a\u5316\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-nvpAmnXMnA\">\u7d50\u8ad6<\/h2>\n<p>\u7d50\u5408\u4f7f\u7528Solr\u548cRedis\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u641c\u7d22\u548c\u7de9\u5b58\u7684\u6548\u7387\uff0c\u70ba\u7528\u6236\u63d0\u4f9b\u66f4\u5feb\u7684\u97ff\u61c9\u6642\u9593\u548c\u66f4\u6e96\u78ba\u7684\u641c\u7d22\u7d50\u679c\u3002\u9019\u7a2e\u67b6\u69cb\u4e0d\u50c5\u80fd\u5920\u6eff\u8db3\u7576\u524d\u7684\u9700\u6c42\uff0c\u9084\u80fd\u5920\u96a8\u8457\u6578\u64da\u91cf\u7684\u589e\u9577\u800c\u64f4\u5c55\uff0c\u70ba\u672a\u4f86\u7684\u767c\u5c55\u6253\u4e0b\u5805\u5be6\u7684\u57fa\u790e\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684\u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u60a8\u7684\u61c9\u7528\u7a0b\u5e8f\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u90e8\u7f72Solr\u548cRedis\uff0c\u9019\u5c07\u70ba\u60a8\u7684\u696d\u52d9\u5e36\u4f86\u66f4\u9ad8\u7684\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u5982\u4f55\u5229\u7528Solr\u548cRedis\u63d0\u5347\u641c\u7d22\u6548\u7387\u548c\u7de9\u5b58\u6027\u80fd\uff0c\u5be6\u73fe\u5feb\u901f\u6578\u64da\u6aa2\u7d22\u548c\u9ad8\u6548\u8cc7\u6e90\u7ba1\u7406\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-197689","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/197689","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=197689"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/197689\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=197689"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=197689"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=197689"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}