{"id":1313,"date":"2023-03-19T08:22:25","date_gmt":"2023-03-19T00:22:25","guid":{"rendered":"http:\/\/viplao.com\/?p=1313"},"modified":"2023-03-19T08:25:25","modified_gmt":"2023-03-19T00:25:25","slug":"%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91flink-sql-%e5%ae%9e%e8%b7%b52-%e8%87%aa%e5%ae%9a%e4%b9%89-redis-%e6%95%b0%e6%8d%ae%e7%bb%b4%e8%a1%a8","status":"publish","type":"post","link":"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91flink-sql-%e5%ae%9e%e8%b7%b52-%e8%87%aa%e5%ae%9a%e4%b9%89-redis-%e6%95%b0%e6%8d%ae%e7%bb%b4%e8%a1%a8\/","title":{"rendered":"\u00a0\u3010\u8fd0\u7ef4\u5de5\u5177\u3011Flink SQL\u00a0\u5b9e\u8df52 &#8211; \u00a0\u81ea\u5b9a\u4e49 redis \u6570\u636e\u7ef4\u8868"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_71 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">\u6587\u7ae0\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91flink-sql-%e5%ae%9e%e8%b7%b52-%e8%87%aa%e5%ae%9a%e4%b9%89-redis-%e6%95%b0%e6%8d%ae%e7%bb%b4%e8%a1%a8\/#1Flink_sql_redis\" title=\"1.Flink sql redis\">1.Flink sql redis<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91flink-sql-%e5%ae%9e%e8%b7%b52-%e8%87%aa%e5%ae%9a%e4%b9%89-redis-%e6%95%b0%e6%8d%ae%e7%bb%b4%e8%a1%a8\/#2%E8%83%8C%E6%99%AF%E7%AF%87-%E4%B8%BA%E5%95%A5%E9%9C%80%E8%A6%81_redis_%E7%BB%B4%E8%A1%A8\" title=\"2.\u80cc\u666f\u7bc7-\u4e3a\u5565\u9700\u8981 redis \u7ef4\u8868\">2.\u80cc\u666f\u7bc7-\u4e3a\u5565\u9700\u8981 redis \u7ef4\u8868<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91flink-sql-%e5%ae%9e%e8%b7%b52-%e8%87%aa%e5%ae%9a%e4%b9%89-redis-%e6%95%b0%e6%8d%ae%e7%bb%b4%e8%a1%a8\/#21%E5%95%A5%E6%98%AF%E7%BB%B4%E8%A1%A8%EF%BC%9F%E4%BA%8B%E5%AE%9E%E8%A1%A8%EF%BC%9F\" title=\"2.1.\u5565\u662f\u7ef4\u8868\uff1f\u4e8b\u5b9e\u8868\uff1f\">2.1.\u5565\u662f\u7ef4\u8868\uff1f\u4e8b\u5b9e\u8868\uff1f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91flink-sql-%e5%ae%9e%e8%b7%b52-%e8%87%aa%e5%ae%9a%e4%b9%89-redis-%e6%95%b0%e6%8d%ae%e7%bb%b4%e8%a1%a8\/#22%E4%B8%BA%E5%95%A5%E9%9C%80%E8%A6%81_redis_%E7%BB%B4%E8%A1%A8%EF%BC%9F\" title=\"2.2.\u4e3a\u5565\u9700\u8981 redis \u7ef4\u8868\uff1f\">2.2.\u4e3a\u5565\u9700\u8981 redis \u7ef4\u8868\uff1f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91flink-sql-%e5%ae%9e%e8%b7%b52-%e8%87%aa%e5%ae%9a%e4%b9%89-redis-%e6%95%b0%e6%8d%ae%e7%bb%b4%e8%a1%a8\/#3%E7%9B%AE%E6%A0%87%E7%AF%87-%E5%81%9A_redis_%E7%BB%B4%E8%A1%A8%E9%A2%84%E6%9C%9F%E6%95%88%E6%9E%9C%E6%98%AF%E4%BB%80%E4%B9%88\" title=\"3.\u76ee\u6807\u7bc7-\u505a redis \u7ef4\u8868\u9884\u671f\u6548\u679c\u662f\u4ec0\u4e48\">3.\u76ee\u6807\u7bc7-\u505a redis \u7ef4\u8868\u9884\u671f\u6548\u679c\u662f\u4ec0\u4e48<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91flink-sql-%e5%ae%9e%e8%b7%b52-%e8%87%aa%e5%ae%9a%e4%b9%89-redis-%e6%95%b0%e6%8d%ae%e7%bb%b4%e8%a1%a8\/#4%E9%9A%BE%E7%82%B9%E5%89%96%E6%9E%90%E7%AF%87-%E7%9B%AE%E5%89%8D%E6%9C%89%E5%93%AA%E4%BA%9B%E5%AE%9E%E7%8E%B0\" title=\"4.\u96be\u70b9\u5256\u6790\u7bc7-\u76ee\u524d\u6709\u54ea\u4e9b\u5b9e\u73b0\">4.\u96be\u70b9\u5256\u6790\u7bc7-\u76ee\u524d\u6709\u54ea\u4e9b\u5b9e\u73b0<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91flink-sql-%e5%ae%9e%e8%b7%b52-%e8%87%aa%e5%ae%9a%e4%b9%89-redis-%e6%95%b0%e6%8d%ae%e7%bb%b4%e8%a1%a8\/#5%E7%BB%B4%E8%A1%A8%E5%AE%9E%E7%8E%B0%E7%AF%87-%E7%BB%B4%E8%A1%A8%E5%AE%9E%E7%8E%B0%E7%9A%84%E8%BF%87%E7%A8%8B\" title=\"5.\u7ef4\u8868\u5b9e\u73b0\u7bc7-\u7ef4\u8868\u5b9e\u73b0\u7684\u8fc7\u7a0b\">5.\u7ef4\u8868\u5b9e\u73b0\u7bc7-\u7ef4\u8868\u5b9e\u73b0\u7684\u8fc7\u7a0b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91flink-sql-%e5%ae%9e%e8%b7%b52-%e8%87%aa%e5%ae%9a%e4%b9%89-redis-%e6%95%b0%e6%8d%ae%e7%bb%b4%e8%a1%a8\/#51flink_%E7%BB%B4%E8%A1%A8%E5%8E%9F%E7%90%86\" title=\"5.1.flink \u7ef4\u8868\u539f\u7406\">5.1.flink \u7ef4\u8868\u539f\u7406<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91flink-sql-%e5%ae%9e%e8%b7%b52-%e8%87%aa%e5%ae%9a%e4%b9%89-redis-%e6%95%b0%e6%8d%ae%e7%bb%b4%e8%a1%a8\/#52flink_%E7%BB%B4%E8%A1%A8%E5%AE%9E%E7%8E%B0%E6%96%B9%E6%A1%88\" title=\"5.2.flink \u7ef4\u8868\u5b9e\u73b0\u65b9\u6848\">5.2.flink \u7ef4\u8868\u5b9e\u73b0\u65b9\u6848<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91flink-sql-%e5%ae%9e%e8%b7%b52-%e8%87%aa%e5%ae%9a%e4%b9%89-redis-%e6%95%b0%e6%8d%ae%e7%bb%b4%e8%a1%a8\/#521%E5%A4%8D%E7%94%A8_bahir_connector\" title=\"5.2.1.\u590d\u7528 bahir connector\">5.2.1.\u590d\u7528 bahir connector<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91flink-sql-%e5%ae%9e%e8%b7%b52-%e8%87%aa%e5%ae%9a%e4%b9%89-redis-%e6%95%b0%e6%8d%ae%e7%bb%b4%e8%a1%a8\/#522%E5%A4%8D%E7%94%A8_format\" title=\"5.2.2.\u590d\u7528 format\">5.2.2.\u590d\u7528 format<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91flink-sql-%e5%ae%9e%e8%b7%b52-%e8%87%aa%e5%ae%9a%e4%b9%89-redis-%e6%95%b0%e6%8d%ae%e7%bb%b4%e8%a1%a8\/#523%E7%BB%B4%E8%A1%A8_local_cache\" title=\"5.2.3.\u7ef4\u8868 local cache\">5.2.3.\u7ef4\u8868 local cache<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91flink-sql-%e5%ae%9e%e8%b7%b52-%e8%87%aa%e5%ae%9a%e4%b9%89-redis-%e6%95%b0%e6%8d%ae%e7%bb%b4%e8%a1%a8\/#6%E6%80%BB%E7%BB%93%E4%B8%8E%E5%B1%95%E6%9C%9B%E7%AF%87\" title=\"6.\u603b\u7ed3\u4e0e\u5c55\u671b\u7bc7\">6.\u603b\u7ed3\u4e0e\u5c55\u671b\u7bc7<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91flink-sql-%e5%ae%9e%e8%b7%b52-%e8%87%aa%e5%ae%9a%e4%b9%89-redis-%e6%95%b0%e6%8d%ae%e7%bb%b4%e8%a1%a8\/#61%E6%80%BB%E7%BB%93\" title=\"6.1.\u603b\u7ed3\">6.1.\u603b\u7ed3<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91flink-sql-%e5%ae%9e%e8%b7%b52-%e8%87%aa%e5%ae%9a%e4%b9%89-redis-%e6%95%b0%e6%8d%ae%e7%bb%b4%e8%a1%a8\/#62%E5%B1%95%E6%9C%9B\" title=\"6.2.\u5c55\u671b\">6.2.\u5c55\u671b<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1Flink_sql_redis\"><\/span>1.Flink sql redis <span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u4e86 flink sql redis \u7ef4\u8868\u7684\u5b9e\u73b0\u8fc7\u7a0b\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u60f3\u5728\u672c\u5730\u6d4b\u8bd5\u4e0b\uff1a<\/p>\n\n\n\n<ol>\n<li>\u5728\u516c\u4f17\u53f7\u540e\u53f0\u56de\u590d<strong>flink sql \u77e5\u5176\u6240\u4ee5\u7136\uff08\u4e8c\uff09| sql \u81ea\u5b9a\u4e49 redis \u6570\u636e\u7ef4\u8868<\/strong>\u83b7\u53d6\u6e90\u7801\uff08\u6e90\u7801\u57fa\u4e8e 1.13.1 \u5b9e\u73b0\uff09<\/li>\n\n\n\n<li>\u5728\u4f60\u7684\u672c\u5730\u5b89\u88c5\u5e76\u6253\u5f00 redis-server\uff0c\u7136\u540e\u4f7f\u7528 redis-cli \u6267\u884c\u547d\u4ee4&nbsp;<code>set a \"{\\\"score\\\":3,\\\"name\\\":\\\"namehhh\\\",\\\"name1\\\":\\\"namehhh112\\\"}\"<\/code><\/li>\n\n\n\n<li>\u6267\u884c\u6e90\u7801\u5305\u4e2d\u7684&nbsp;<code>flink.examples.sql._03.source_sink.RedisLookupTest<\/code>&nbsp;\u6d4b\u8bd5\u7c7b\uff0c\u5c31\u53ef\u4ee5\u5728 console \u4e2d\u770b\u5230\u7ed3\u679c\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u5982\u679c\u60f3\u76f4\u63a5\u5728\u96c6\u7fa4\u73af\u5883\u4f7f\u7528\uff1a<\/p>\n\n\n\n<ol>\n<li>\u547d\u4ee4\u884c\u6267\u884c&nbsp;<code>mvn package -DskipTests=true<\/code>&nbsp;\u6253\u5305<\/li>\n\n\n\n<li>\u5c06\u751f\u6210\u7684\u5305&nbsp;<code>flink-examples-0.0.1-SNAPSHOT.jar<\/code>&nbsp;\u5f15\u5165 flink lib \u4e2d\u5373\u53ef\uff0c\u65e0\u9700\u5176\u5b83\u8bbe\u7f6e\u3002<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2%E8%83%8C%E6%99%AF%E7%AF%87-%E4%B8%BA%E5%95%A5%E9%9C%80%E8%A6%81_redis_%E7%BB%B4%E8%A1%A8\"><\/span>2.\u80cc\u666f\u7bc7-\u4e3a\u5565\u9700\u8981 redis \u7ef4\u8868<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"21%E5%95%A5%E6%98%AF%E7%BB%B4%E8%A1%A8%EF%BC%9F%E4%BA%8B%E5%AE%9E%E8%A1%A8%EF%BC%9F\"><\/span>2.1.\u5565\u662f\u7ef4\u8868\uff1f\u4e8b\u5b9e\u8868\uff1f<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Dimension Table \u6982\u5ff5\u591a\u51fa\u73b0\u4e8e\u6570\u636e\u4ed3\u5e93\u91cc\u9762\uff0c\u7ef4\u8868\u4e0e\u4e8b\u5b9e\u8868\u76f8\u4e92\u5bf9\u5e94\u3002<\/p>\n\n\n\n<p>\u7ed9\u4e24\u4e2a\u573a\u666f\u6765\u770b\u770b\uff1a<\/p>\n\n\n\n<p>\u6bd4\u5982\u9700\u8981\u7edf\u8ba1\u5206\u6027\u522b\u7684 DAU\uff1a<\/p>\n\n\n\n<ol>\n<li>\u5ba2\u6237\u7aef\u4e0a\u62a5\u7684\u65e5\u5fd7\u4e2d\uff08\u4e8b\u5b9e\u8868\uff09\u53ea\u6709\u8bbe\u5907 id\uff0c\u53ea\u7528\u8fd9\u4e2a\u4e8b\u5b9e\u8868\u662f\u6ca1\u6cd5\u7edf\u8ba1\u51fa\u5206\u6027\u522b\u7684 DAU \u7684\u3002<\/li>\n\n\n\n<li>\u8fd9\u65f6\u5019\u5c31\u9700\u8981\u4e00\u5f20\u5e26\u6709\u8bbe\u5907 id\u3001\u6027\u522b\u6620\u5c04\u7684\u8868\uff08\u8fd9\u5c31\u662f\u7ef4\u8868\uff09\u6765\u63d0\u4f9b\u6027\u522b\u6570\u636e\u3002<\/li>\n\n\n\n<li>\u7136\u540e\u4f7f\u7528\u4e8b\u5b9e\u8868\u53bb join \u8fd9\u5f20\u7ef4\u8868\u53bb\u83b7\u53d6\u5230\u6bcf\u4e00\u4e2a\u8bbe\u5907 id \u5bf9\u5e94\u7684\u6027\u522b\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u7edf\u8ba1\u51fa\u5206\u6027\u522b\u7684 DAU\u3002\u76f8\u5f53\u4e8e\u4e00\u4e2a\u6269\u5145\u7ef4\u5ea6\u7684\u64cd\u4f5c\u3002<\/li>\n<\/ol>\n\n\n\n<p><a href=\"https:\/\/blog.csdn.net\/weixin_47482194\/article\/details\/105855116?spm=1001.2014.3001.5501\">https:\/\/blog.csdn.net\/weixin_47482194\/article\/details\/105855116?spm=1001.2014.3001.5501<\/a><\/p>\n\n\n\n<p>\u6bd4\u5982\u76ee\u524d\u60f3\u8981\u7edf\u8ba1\u6574\u4f53\u9500\u552e\u989d\uff1a<\/p>\n\n\n\n<ol>\n<li>\u76ee\u524d\u5df2\u6709 \u201c\u9500\u552e\u7edf\u8ba1\u8868\u201d\uff0c\u662f\u4e00\u4e2a\u4e8b\u5b9e\u8868\uff0c\u5176\u4e2d\u6ca1\u6709\u5177\u4f53\u9500\u552e\u54c1\u9879\u7684\u91d1\u989d\u3002<\/li>\n\n\n\n<li>\u201c\u5546\u54c1\u4ef7\u683c\u8868\u201d \u53ef\u4ee5\u7528\u4e8e\u63d0\u4f9b\u5177\u4f53\u9500\u552e\u54c1\u9879\u7684\u91d1\u989d\uff0c\u8fd9\u5c31\u662f\u9500\u552e\u7edf\u8ba1\u7684\u4e00\u4e2a\u7ef4\u5ea6\u8868\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u4e8b\u5b9e\u6570\u636e\u548c\u7ef4\u5ea6\u6570\u636e\u7684\u8bc6\u522b\u5fc5\u987b\u4f9d\u636e\u5177\u4f53\u7684\u4e3b\u9898\u95ee\u9898\u800c\u5b9a\u3002\u201c\u4e8b\u5b9e\u8868\u201d \u7528\u6765\u5b58\u50a8\u4e8b\u5b9e\u7684\u5ea6\u91cf\u53ca\u6307\u5411\u5404\u4e2a\u7ef4\u7684\u5916\u952e\u503c\u3002\u7ef4\u8868\u7528\u6765\u4fdd\u5b58\u8be5\u7ef4\u7684\u5143\u6570\u636e\u3002<\/p>\n\n\n\n<p>\u53c2\u8003\uff1a<a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/blog.csdn.net\/lindan1984\/article\/details\/96566626\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/blog.csdn.net\/lindan1984\/article\/details\/96566626<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"22%E4%B8%BA%E5%95%A5%E9%9C%80%E8%A6%81_redis_%E7%BB%B4%E8%A1%A8%EF%BC%9F\"><\/span>2.2.\u4e3a\u5565\u9700\u8981 redis \u7ef4\u8868\uff1f<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u76ee\u524d\u5728\u5b9e\u65f6\u8ba1\u7b97\u7684\u573a\u666f\u4e2d\uff0c\u719f\u6089 datastream \u7684\u540c\u5b66\u5927\u591a\u6570\u90fd\u4f7f\u7528\u8fc7 mysql\\Hbase\\redis \u4f5c\u4e3a\u7ef4\u8868\u5f15\u64ce\u5b58\u50a8\u4e00\u4e9b\u7ef4\u5ea6\u6570\u636e\uff0c\u7136\u540e\u5728 datastream api \u4e2d\u8c03\u7528 mysql\\Hbase\\redis \u5ba2\u6237\u7aef\u53bb\u83b7\u53d6\u5230\u7ef4\u5ea6\u6570\u636e\u8fdb\u884c\u7ef4\u5ea6\u6269\u5145\u3002<\/p>\n\n\n\n<p>\u800c redis \u4f5c\u4e3a flink \u5b9e\u65f6\u573a\u666f\u4e2d\u6700\u5e38\u7528\u7684\u9ad8\u901f\u7ef4\u8868\u5f15\u64ce\uff0c\u5b98\u65b9\u662f\u6ca1\u6709\u63d0\u4f9b flink sql api \u7684 redis \u7ef4\u8868 connector \u7684\u3002\u5982\u4e0b\u56fe\uff0c\u57fa\u4e8e 1.13 \u7248\u672c\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/ci.apache.org\/projects\/flink\/flink-docs-release-1.13\/docs\/connectors\/table\/overview\/\">https:\/\/ci.apache.org\/projects\/flink\/flink-docs-release-1.13\/docs\/connectors\/table\/overview\/<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-93c0689f761a7a1f0440ce728b54fa24_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>1<\/p>\n\n\n\n<p>\u963f\u91cc\u4e91 flink \u662f\u63d0\u4f9b\u4e86\u8fd9\u4e2a\u80fd\u529b\u7684\u3002\u4f46\u662f\u8fd9\u4e2a\u9700\u8981\u4f7f\u7528\u963f\u91cc\u4e91\u7684\u4ea7\u54c1\u624d\u80fd\u4f7f\u7528\u3002\u6709\u94b1\u4eba\u53ef\u4ee5\u76f4\u63a5\u4e0a\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/www.alibabacloud.com\/help\/zh\/faq-detail\/122722.htm?spm=a2c63.q38357.a3.7.a1227a53TBMuSY\">https:\/\/www.alibabacloud.com\/help\/zh\/faq-detail\/122722.htm?spm=a2c63.q38357.a3.7.a1227a53TBMuSY<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-d1a8db7f95458e39499ebe1e844f0230_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>2<\/p>\n\n\n\n<p>\u56e0\u6b64\u672c\u6587\u5728\u4ecb\u7ecd\u600e\u6837\u81ea\u5b9a\u4e49\u4e00\u4e2a sql \u6570\u636e\u7ef4\u8868\u7684\u540c\u65f6\uff0c\u5b9e\u73b0\u4e00\u4e2a sql redis \u6765\u7ed9\u5927\u5bb6\u4f7f\u7528\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3%E7%9B%AE%E6%A0%87%E7%AF%87-%E5%81%9A_redis_%E7%BB%B4%E8%A1%A8%E9%A2%84%E6%9C%9F%E6%95%88%E6%9E%9C%E6%98%AF%E4%BB%80%E4%B9%88\"><\/span>3.\u76ee\u6807\u7bc7-\u505a redis \u7ef4\u8868\u9884\u671f\u6548\u679c\u662f\u4ec0\u4e48<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>redis \u4f5c\u4e3a\u7ef4\u8868\u5728 datastream \u4e2d\u7684\u6700\u5e38\u7528\u7684\u6570\u636e\u7ed3\u6784\u5c31\u662f kv\u3001hmap \u4e24\u79cd\u3002\u672c\u6587\u5b9e\u73b0\u4e3b\u8981\u5b9e\u73b0 kv \u7ed3\u6784\uff0cmap \u7ed3\u6784\u5927\u5bb6\u53ef\u4ee5\u62ff\u5230\u6e90\u7801\u4e4b\u540e\u8fdb\u884c\u81ea\u5b9a\u4e49\u5b9e\u73b0\u3002\u4e5f\u5c31\u591a\u52a0\u51e0\u884c\u4ee3\u7801\u5c31\u5b8c\u4e8b\u4e86\u3002<\/p>\n\n\n\n<p>\u9884\u671f\u6548\u679c\u5c31\u5982\u963f\u91cc\u4e91\u7684 flink redis\uff1a<\/p>\n\n\n\n<p>\u4e0b\u9762\u662f\u6211\u5728\u672c\u5730\u8dd1\u7684\u7ed3\u679c\uff0c\u5148\u770b\u770b redis \u4e2d\u5b58\u50a8\u7684\u6570\u636e\uff0c\u53ea\u6709\u8fd9\u4e00\u6761\u6570\u636e\uff0c\u662f json \u5b57\u7b26\u4e32\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic2.zhimg.com\/80\/v2-96694fb5cd60a61b472738bfb59f5dd5_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>9<\/p>\n\n\n\n<p>\u4e0b\u9762\u662f\u9884\u671f flink sql\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE dimTable (\n    name STRING,\n    name1 STRING,\n    score BIGINT  -- redis \u4e2d\u5b58\u50a8\u6570\u636e\u7684 schema\n) WITH (\n    'connector' = 'redis', -- \u6307\u5b9a connector \u662f redis \u7c7b\u578b\u7684\n    'hostname' = '127.0.0.1', -- redis server ip\n    'port' = '6379', -- redis server \u7aef\u53e3\n    'format' = 'json' -- \u6307\u5b9a format \u89e3\u6790\u683c\u5f0f\n    'lookup.cache.max-rows' = '500', -- guava local cache \u6700\u5927\u6761\u76ee\n    'lookup.cache.ttl' = '3600', -- guava local cache ttl\n    'lookup.max-retries' = '1' -- redis \u547d\u4ee4\u6267\u884c\u5931\u8d25\u540e\u91cd\u590d\u6b21\u6570\n)\n\nSELECT o.f0, o.f1, c.name, c.name1, c.score\nFROM leftTable AS o\n-- \u7ef4\u8868 join\nLEFT JOIN dimTable FOR SYSTEM_TIME AS OF o.proctime AS c\nON o.f0 = c.name\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic2.zhimg.com\/80\/v2-ac17ed67153aaac6a3e0cbe7b65faf95_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>10<\/p>\n\n\n\n<p>\u7ed3\u679c\u5982\u4e0b\uff0c\u540e\u9762\u4e09\u5217\u5c31\u5bf9\u5e94\u5230&nbsp;<code>c.name, c.name1, c.score<\/code>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>+I&#91;a, b, namehhh, namehhh112, 3]\n+I&#91;a, b, namehhh, namehhh112, 3]\n+I&#91;a, b, namehhh, namehhh112, 3]\n+I&#91;a, b, namehhh, namehhh112, 3]\n+I&#91;a, b, namehhh, namehhh112, 3]\n+I&#91;a, b, namehhh, namehhh112, 3]\n+I&#91;a, b, namehhh, namehhh112, 3]\n+I&#91;a, b, namehhh, namehhh112, 3]\n+I&#91;a, b, namehhh, namehhh112, 3]\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4%E9%9A%BE%E7%82%B9%E5%89%96%E6%9E%90%E7%AF%87-%E7%9B%AE%E5%89%8D%E6%9C%89%E5%93%AA%E4%BA%9B%E5%AE%9E%E7%8E%B0\"><\/span>4.\u96be\u70b9\u5256\u6790\u7bc7-\u76ee\u524d\u6709\u54ea\u4e9b\u5b9e\u73b0<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u76ee\u524d\u53ef\u4ee5\u4ece\u7f51\u4e0a\u641c\u5230\u7684\u5b9e\u73b0\u3001\u4ee5\u53ca\u53ef\u4ee5\u53c2\u8003\u7684\u5b9e\u73b0\u6709\u4ee5\u4e0b\u4e24\u4e2a\uff1a<\/p>\n\n\n\n<ol>\n<li><a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/github.com\/jeff-zou\/flink-connector-redis\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/jeff-zou\/flink-connector-redis<\/a>\u3002\u4f46\u662f\u5176\u6ca1\u6709\u5b9e\u73b0 flink sql redis \u7ef4\u8868\uff0c\u53ea\u5b9e\u73b0\u4e86 sink \u8868\uff0c\u5e76\u4e14\u4f7f\u7528\u8d77\u6765\u6709\u6bd4\u8f83\u591a\u7684\u9650\u5236\uff0c\u5305\u62ec\u9700\u8981\u5728\u5efa\u8868\u65f6\u5c31\u6307\u5b9a key-column\uff0cvalue-column \u7b49\uff0c\u5176\u5b9e\u535a\u4e3b\u89c9\u5f97\u6ca1\u5fc5\u8981\u6307\u5b9a\u8fd9\u4e9b\u5b57\u6bb5\uff0c\u8fd9\u4e9b\u90fd\u53ef\u4ee5\u52a8\u6001\u8c03\u6574\u3002\u5176\u5b9e\u73b0\u662f\u5bf9 apache-bahir-flink&nbsp;<a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/github.com\/apache\/bahir-flink\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/apache\/bahir-flink<\/a>&nbsp;\u7684\u4e8c\u6b21\u5f00\u53d1\uff0c\u4f46\u4e0e bahir \u539f\u751f\u5b9e\u73b0\u6709\u5272\u88c2\u611f\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u9879\u76ee\u51e0\u4e4e\u91cd\u65b0\u5b9e\u73b0\u4e86\u4e00\u904d\uff0c\u63a5\u53e3\u4e5f\u548c bahir \u4e0d\u540c\u3002<\/li>\n\n\n\n<li>\u963f\u91cc\u4e91\u5b9e\u73b0&nbsp;<a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/www.alibabacloud.com\/help\/zh\/faq-detail\/122722.htm%3Fspm%3Da2c63.q38357.a3.7.a1227a53TBMuSY\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.alibabacloud.com\/help\/zh\/faq-detail\/122722.htm?spm=a2c63.q38357.a3.7.a1227a53TBMuSY<\/a>\u3002\u53ef\u4ee5\u53c2\u8003\u7684\u53ea\u6709\u7528\u6cd5\u548c\u914d\u7f6e\u7b49\u3002\u4f46\u662f\u6709\u4e9b\u914d\u7f6e\u9879\u4e5f\u5c5e\u4e8e\u963f\u91cc\u81ea\u5b9a\u4e49\u7684\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u56e0\u6b64\u535a\u4e3b\u5728\u5b9e\u73b0\u65f6\uff0c\u5c31\u5b9a\u4e86\u4e00\u4e2a\u57fa\u8c03\u3002<\/p>\n\n\n\n<ol>\n<li>\u590d\u7528 connector\uff1a\u590d\u7528 bahir \u63d0\u4f9b\u7684 redis connnector<\/li>\n\n\n\n<li>\u590d\u7528 format\uff1a\u590d\u7528 flink \u76ee\u524d\u7684 format \u673a\u5236\uff0c\u76ee\u524d\u8fd9\u4e2a\u4e0a\u8ff0\u4e24\u4e2a\u5b9e\u73b0\u90fd\u6ca1\u6709\u505a\u5230<\/li>\n\n\n\n<li>\u7b80\u6d01\u6027\uff1a\u5b9e\u73b0 kv \u7ed3\u6784\u3002hget \u5c01\u88c5\u4e00\u90e8\u5206<\/li>\n\n\n\n<li>\u7ef4\u8868 local cache\uff1a\u4e3a\u907f\u514d\u9ad8\u9891\u7387\u8bbf\u95ee redis\uff0c\u7ef4\u8868\u52a0\u4e86 local cache \u4f5c\u4e3a\u7f13\u5b58<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5%E7%BB%B4%E8%A1%A8%E5%AE%9E%E7%8E%B0%E7%AF%87-%E7%BB%B4%E8%A1%A8%E5%AE%9E%E7%8E%B0%E7%9A%84%E8%BF%87%E7%A8%8B\"><\/span>5.\u7ef4\u8868\u5b9e\u73b0\u7bc7-\u7ef4\u8868\u5b9e\u73b0\u7684\u8fc7\u7a0b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5728\u5b9e\u73b0 redis \u7ef4\u8868\u4e4b\u524d\uff0c\u4e0d\u5f97\u4e0d\u8c08\u8c08 flink \u7ef4\u8868\u52a0\u8f7d\u548c\u4f7f\u7528\u673a\u5236\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"51flink_%E7%BB%B4%E8%A1%A8%E5%8E%9F%E7%90%86\"><\/span>5.1.flink \u7ef4\u8868\u539f\u7406<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5176\u5b9e\u4e0a\u8282\u5df2\u7ecf\u8be6\u7ec6\u63cf\u8ff0\u4e86 flink sql \u5bf9\u4e8e source\\sink \u7684\u52a0\u8f7d\u673a\u5236\uff0c\u7ef4\u8868\u5c5e\u4e8e source \u7684\u4e2d\u7684 lookup \u8868\uff0c\u5728\u5177\u4f53 flink \u7a0b\u5e8f\u8fd0\u884c\u7684\u8fc7\u7a0b\u4e4b\u4e2d\u53ef\u4ee5\u7b80\u5355\u7684\u7406\u89e3\u4e3a\u4e00\u4e2a map\uff0c\u5728 map \u4e2d\u8c03\u7528 redis-client \u63a5\u53e3\u8bbf\u95ee redis \u8fdb\u884c\u6269\u5145\u7ef4\u5ea6\u7684\u8fc7\u7a0b\u3002<\/p>\n\n\n\n<ol>\n<li>\u901a\u8fc7 SPI \u673a\u5236\u52a0\u8f7d\u6240\u6709\u7684 source\\sink\\format \u5de5\u5382&nbsp;<code>Factory<\/code><\/li>\n\n\n\n<li>\u8fc7\u6ee4\u51fa DynamicTableSourceFactory + connector \u6807\u8bc6\u7684 source \u5de5\u5382\u7c7b<\/li>\n\n\n\n<li>\u901a\u8fc7 source \u5de5\u5382\u7c7b\u521b\u5efa\u51fa\u5bf9\u5e94\u7684 source<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic3.zhimg.com\/80\/v2-6de17db7934b0704a4ab3c8a22ce458e_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>7<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-0ff07b9f716a2837463957ca525b2750_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>5<\/p>\n\n\n\n<p>\u5982\u56fe source \u548c sink \u662f\u901a\u8fc7&nbsp;<code>FactoryUtil.createTableSource<\/code>&nbsp;\u548c&nbsp;<code>FactoryUtil.createTableSink<\/code>&nbsp;\u521b\u5efa\u7684<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-36ed1ff9309ac6f5d78c93fc39eff95c_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>4<\/p>\n\n\n\n<p>\u6240\u6709\u901a\u8fc7 SPI \u7684 source\\sink\\formt \u63d2\u4ef6\u90fd\u7ee7\u627f\u81ea&nbsp;<code>Factory<\/code>\u3002<\/p>\n\n\n\n<p>\u6574\u4f53\u521b\u5efa source \u65b9\u6cd5\u7684\u8c03\u7528\u94fe\u5982\u4e0b\u56fe\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-44e172cd097a71662d9d310bdf158274_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>6<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"52flink_%E7%BB%B4%E8%A1%A8%E5%AE%9E%E7%8E%B0%E6%96%B9%E6%A1%88\"><\/span>5.2.flink \u7ef4\u8868\u5b9e\u73b0\u65b9\u6848<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5148\u770b\u4e0b\u535a\u4e3b\u7684\u6700\u7ec8\u5b9e\u73b0\u3002<\/p>\n\n\n\n<p>\u603b\u91cd\u8981\u7684\u4e09\u4e2a\u5b9e\u73b0\u7c7b\uff1a<\/p>\n\n\n\n<ol>\n<li><code>RedisDynamicTableFactory<\/code><\/li>\n\n\n\n<li><code>RedisDynamicTableSource<\/code><\/li>\n\n\n\n<li><code>RedisRowDataLookupFunction<\/code><\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic3.zhimg.com\/80\/v2-333797d1fc055e5c51d8767a00fa5aaa_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>8<\/p>\n\n\n\n<p>\u5177\u4f53\u6d41\u7a0b\uff1a<\/p>\n\n\n\n<ol>\n<li>\u5b9a\u4e49 SPI \u7684\u5de5\u5382\u7c7b&nbsp;<code>RedisDynamicTableFactory implements DynamicTableSourceFactory<\/code>\uff0c\u5e76\u4e14\u5728 resource\\META-INF \u4e0b\u521b\u5efa SPI \u7684\u63d2\u4ef6\u6587\u4ef6<\/li>\n\n\n\n<li>\u5b9e\u73b0 factoryIdentifier \u6807\u8bc6&nbsp;<code>redis<\/code><\/li>\n\n\n\n<li>\u5b9e\u73b0&nbsp;<code>RedisDynamicTableFactory#createDynamicTableSource<\/code>&nbsp;\u6765\u521b\u5efa\u5bf9\u5e94\u7684 source&nbsp;<code>RedisDynamicTableSource<\/code><\/li>\n\n\n\n<li>\u5b9a\u4e49&nbsp;<code>RedisDynamicTableSource implements LookupTableSource<\/code><\/li>\n\n\n\n<li>\u5b9e\u73b0&nbsp;<code>RedisDynamicTableFactory#getLookupRuntimeProvider<\/code>&nbsp;\u65b9\u6cd5\uff0c\u521b\u5efa\u5177\u4f53\u7684\u7ef4\u8868 UDF&nbsp;<code>TableFunction&lt;T&gt;<\/code>\uff0c\u5b9a\u4e49\u4e3a&nbsp;<code>RedisRowDataLookupFunction<\/code><\/li>\n\n\n\n<li>\u5b9e\u73b0&nbsp;<code>RedisRowDataLookupFunction<\/code>&nbsp;\u7684 eval \u65b9\u6cd5\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u5c31\u662f\u7528\u4e8e\u8bbf\u95ee redis \u6269\u5145\u7ef4\u5ea6\u7684\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u4ecb\u7ecd\u5b8c\u6d41\u7a0b\uff0c\u8fdb\u5165\u5177\u4f53\u5b9e\u73b0\u65b9\u6848\u7ec6\u8282\uff1a<\/p>\n\n\n\n<p><code>RedisDynamicTableFactory<\/code>&nbsp;\u4e3b\u8981\u521b\u5efa source \u7684\u903b\u8f91\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class RedisDynamicTableFactory implements DynamicTableSourceFactory {\n    ...\n\n    @Override\n    public String factoryIdentifier() {\n        \/\/ \u6807\u8bc6 redis\n        return \"redis\";\n    }\n\n    @Override\n    public DynamicTableSource createDynamicTableSource(Context context) {\n\n        \/\/ either implement your custom validation logic here ...\n        \/\/ or use the provided helper utility\n        final FactoryUtil.TableFactoryHelper helper = FactoryUtil.createTableFactoryHelper(this, context);\n\n        \/\/ discover a suitable decoding format\n        \/\/ format \u5b9e\u73b0\n        final DecodingFormat&lt;DeserializationSchema&lt;RowData&gt;&gt; decodingFormat = helper.discoverDecodingFormat(\n                DeserializationFormatFactory.class,\n                FactoryUtil.FORMAT);\n\n        \/\/ validate all options\n        \/\/ \u6240\u6709 option \u914d\u7f6e\u7684\u6821\u9a8c\uff0c\u6bd4\u5982 cache \u7c7b\u53c2\u6570\n        helper.validate();\n\n        \/\/ get the validated options\n        final ReadableConfig options = helper.getOptions();\n\n        final RedisLookupOptions redisLookupOptions = RedisOptions.getRedisLookupOptions(options);\n\n        TableSchema schema = context.getCatalogTable().getSchema();\n\n        \/\/ \u521b\u5efa RedisDynamicTableSource\n        return new RedisDynamicTableSource(\n                schema.toPhysicalRowDataType()\n                , decodingFormat\n                , redisLookupOptions);\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>resources\\META-INF \u6587\u4ef6\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-08a5b0c49af17c351c12af7e1d5c685c_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>13<\/p>\n\n\n\n<p><code>RedisDynamicTableSource<\/code>&nbsp;\u4e3b\u8981\u521b\u5efa table udf \u7684\u903b\u8f91\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class RedisDynamicTableSource implements LookupTableSource {\n    ...\n\n    @Override\n    public LookupRuntimeProvider getLookupRuntimeProvider(LookupContext context) {\n\n        \/\/ \u521d\u59cb\u5316 redis \u5ba2\u6237\u7aef\u914d\u7f6e\n        FlinkJedisConfigBase flinkJedisConfigBase = new FlinkJedisPoolConfig.Builder()\n                .setHost(this.redisLookupOptions.getHostname())\n                .setPort(this.redisLookupOptions.getPort())\n                .build();\n\n        \/\/ redis key\uff0cvalue \u5e8f\u5217\u5316\u5668\n        LookupRedisMapper lookupRedisMapper = new LookupRedisMapper(\n                this.createDeserialization(context, this.decodingFormat, createValueFormatProjection(this.physicalDataType)));\n\n        \/\/ \u521b\u5efa table udf\n        return TableFunctionProvider.of(new RedisRowDataLookupFunction(\n                flinkJedisConfigBase\n                , lookupRedisMapper\n                , this.redisLookupOptions));\n    }\n}\n<\/code><\/pre>\n\n\n\n<p><code>RedisRowDataLookupFunction<\/code>&nbsp;table udf \u6267\u884c\u7ef4\u8868\u5173\u8054\u7684\u4e3b\u8981\u6d41\u7a0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class RedisRowDataLookupFunction extends TableFunction&lt;RowData&gt; {\n    ...\n\n    \/**\n     * \u5177\u4f53 redis \u6267\u884c\u65b9\u6cd5\n     *\/\n    public void eval(Object... objects) throws IOException {\n\n        for (int retry = 0; retry &lt;= maxRetryTimes; retry++) {\n            try {\n                \/\/ fetch result\n                this.evaler.accept(objects);\n                break;\n            } catch (Exception e) {\n                LOG.error(String.format(\"HBase lookup error, retry times = %d\", retry), e);\n                if (retry &gt;= maxRetryTimes) {\n                    throw new RuntimeException(\"Execution of Redis lookup failed.\", e);\n                }\n                try {\n                    Thread.sleep(1000 * retry);\n                } catch (InterruptedException e1) {\n                    throw new RuntimeException(e1);\n                }\n            }\n        }\n    }\n\n\n    @Override\n    public void open(FunctionContext context) {\n        LOG.info(\"start open ...\");\n\n        \/\/ redis \u547d\u4ee4\u6267\u884c\u5668\uff0c\u521d\u59cb\u5316 redis \u94fe\u63a5\n        try {\n            this.redisCommandsContainer =\n                    RedisCommandsContainerBuilder\n                            .build(this.flinkJedisConfigBase);\n            this.redisCommandsContainer.open();\n        } catch (Exception e) {\n            LOG.error(\"Redis has not been properly initialized: \", e);\n            throw new RuntimeException(e);\n        }\n\n        \/\/ \u521d\u59cb\u5316 local cache\n        this.cache = cacheMaxSize &lt;= 0 || cacheExpireMs &lt;= 0 ? null : CacheBuilder.newBuilder()\n                .recordStats()\n                .expireAfterWrite(cacheExpireMs, TimeUnit.MILLISECONDS)\n                .maximumSize(cacheMaxSize)\n                .build();\n\n        if (cache != null) {\n            context.getMetricGroup()\n                    .gauge(\"lookupCacheHitRate\", (Gauge&lt;Double&gt;) () -&gt; cache.stats().hitRate());\n\n\n            this.evaler = in -&gt; {\n                RowData cacheRowData = cache.getIfPresent(in);\n                if (cacheRowData != null) {\n                    collect(cacheRowData);\n                } else {\n                    \/\/ fetch result\n                    byte&#91;] key = lookupRedisMapper.serialize(in);\n\n                    byte&#91;] value = null;\n\n                    switch (redisCommand) {\n                        case GET:\n                            value = this.redisCommandsContainer.get(key);\n                            break;\n                        case HGET:\n                            value = this.redisCommandsContainer.hget(key, this.additionalKey.getBytes());\n                            break;\n                        default:\n                            throw new IllegalArgumentException(\"Cannot process such data type: \" + redisCommand);\n                    }\n\n                    RowData rowData = this.lookupRedisMapper.deserialize(value);\n\n                    collect(rowData);\n\n                    cache.put(key, rowData);\n                }\n            };\n\n        }\n        ...\n    }\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"521%E5%A4%8D%E7%94%A8_bahir_connector\"><\/span>5.2.1.\u590d\u7528 bahir connector<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u5982\u56fe\u662f bahir redis connector \u7684\u5b9e\u73b0\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-18f5df327723c996c825130ef34ee230_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>11<\/p>\n\n\n\n<p>\u535a\u4e3b\u5728\u5b9e\u73b0\u8fc7\u7a0b\u4e2d\u5c06\u80fd\u590d\u7528\u7684\u90fd\u5c3d\u529b\u590d\u7528\u3002\u5982\u56fe\u662f\u6700\u7ec8\u5b9e\u73b0\u76ee\u5f55\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic3.zhimg.com\/80\/v2-0a792cfbb19a7c2075886b8aa7d2ae1e_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>12<\/p>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\u76ee\u5f55\u7ed3\u6784\u662f\u4e0e bahir redis connector \u4e00\u81f4\u7684\u3002<\/p>\n\n\n\n<p>\u5176\u4e2d&nbsp;<code>redis \u5ba2\u6237\u7aef\u53ca\u5176\u914d\u7f6e<\/code>&nbsp;\u662f\u76f4\u63a5\u590d\u7528\u4e86 bahir redis \u7684\u3002\u7531\u4e8e bahir redis \u57fa\u672c\u90fd\u662f sink \u5b9e\u73b0\uff0c\u67d0\u4e9b\u5b9e\u73b0\u6ca1\u6cd5\u7ee7\u627f\u590d\u7528\uff0c\u6240\u4ee5\u8fd9\u91cc\u6211\u5355\u72ec\u5f00\u8f9f\u4e86\u76ee\u5f55\uff0c<code>redis \u547d\u4ee4\u6267\u884c\u5668<\/code>&nbsp;\u548c&nbsp;<code>redis \u547d\u4ee4\u5b9a\u4e49\u5668<\/code>\uff0c\u4f46\u662f\u4e5f\u57fa\u672c\u548c bahir \u4e00\u81f4\u3002\u5982\u679c\u4f60\u60f3\u8981\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u8fdb\u884c\u4f7f\u7528\uff0c\u53ef\u4ee5\u76f4\u63a5\u5c06\u4e24\u90e8\u5206\u4ee3\u7801\u5408\u5e76\uff0c\u6210\u672c\u5f88\u4f4e\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"522%E5%A4%8D%E7%94%A8_format\"><\/span>5.2.2.\u590d\u7528 format<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u535a\u4e3b\u76f4\u63a5\u590d\u7528\u4e86 flink \u672c\u8eab\u81ea\u5e26\u7684 format \u673a\u5236\u6765\u4f5c\u4e3a\u7ef4\u8868\u53cd\u5e8f\u5217\u5316\u673a\u5236\u3002\u53c2\u8003 HBase connector \u5b9e\u73b0\u5c06 cache \u547d\u4e2d\u7387\u6dfb\u52a0\u5230 metric \u4e2d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class RedisDynamicTableFactory implements DynamicTableSourceFactory {\n    ...\n    @Override\n    public DynamicTableSource createDynamicTableSource(Context context) {\n        ...\n\n        \/\/ discover a suitable decoding format\n        \/\/ \u590d\u7528 format \u5b9e\u73b0\n        final DecodingFormat&lt;DeserializationSchema&lt;RowData&gt;&gt; decodingFormat = helper.discoverDecodingFormat(\n                DeserializationFormatFactory.class,\n                FactoryUtil.FORMAT);\n        ...\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>format \u540c\u6837\u4e5f\u662f SPI \u673a\u5236\u52a0\u8f7d\u3002<\/p>\n\n\n\n<p>\u6e90\u7801\u516c\u4f17\u53f7\u540e\u53f0\u56de\u590d<strong>flink sql \u77e5\u5176\u6240\u4ee5\u7136\uff08\u4e8c\uff09| sql \u81ea\u5b9a\u4e49 redis \u6570\u636e\u7ef4\u8868<\/strong>\u83b7\u53d6\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"523%E7%BB%B4%E8%A1%A8_local_cache\"><\/span>5.2.3.\u7ef4\u8868 local cache<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>local cache \u5728\u521d\u59cb\u5316\u65f6\u53ef\u4ee5\u6307\u5b9a cache \u5927\u5c0f\uff0c\u7f13\u5b58\u65f6\u957f\u7b49\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>this.evaler = in -&gt; {\n    RowData cacheRowData = cache.getIfPresent(in);\n    if (cacheRowData != null) {\n        collect(cacheRowData);\n    } else {\n        \/\/ fetch result\n        byte&#91;] key = lookupRedisMapper.serialize(in);\n\n        byte&#91;] value = null;\n\n        switch (redisCommand) {\n            case GET:\n                value = this.redisCommandsContainer.get(key);\n                break;\n            case HGET:\n                value = this.redisCommandsContainer.hget(key, this.additionalKey.getBytes());\n                break;\n            default:\n                throw new IllegalArgumentException(\"Cannot process such data type: \" + redisCommand);\n        }\n\n        RowData rowData = this.lookupRedisMapper.deserialize(value);\n\n        collect(rowData);\n\n        cache.put(key, rowData);\n    }\n};\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"6%E6%80%BB%E7%BB%93%E4%B8%8E%E5%B1%95%E6%9C%9B%E7%AF%87\"><\/span>6.\u603b\u7ed3\u4e0e\u5c55\u671b\u7bc7<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"61%E6%80%BB%E7%BB%93\"><\/span>6.1.\u603b\u7ed3<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u672c\u6587\u4e3b\u8981\u662f\u9488\u5bf9 flink sql redis \u7ef4\u8868\u8fdb\u884c\u4e86\u6269\u5c55\u4ee5\u53ca\u5b9e\u73b0\uff0c\u5e76\u4e14\u590d\u7528 bahir redis connector \u7684\u914d\u7f6e\uff0c\u5177\u6709\u826f\u597d\u7684\u6269\u5c55\u6027\u3002\u5982\u679c\u4f60\u6b63\u597d\u9700\u8981\u8fd9\u4e48\u4e00\u4e2a connector\uff0c\u76f4\u63a5\u516c\u4f17\u53f7\u540e\u53f0\u56de\u590d<strong>flink sql \u77e5\u5176\u6240\u4ee5\u7136\uff08\u4e8c\uff09| sql \u81ea\u5b9a\u4e49 redis \u6570\u636e\u7ef4\u8868<\/strong>\u83b7\u53d6\u6e90\u7801\u5427\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"62%E5%B1%95%E6%9C%9B\"><\/span>6.2.\u5c55\u671b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5f53\u7136\u4e0a\u8ff0\u53ea\u662f redis \u7ef4\u8868\u4e00\u4e2a\u57fa\u7840\u7684\u5b9e\u73b0\uff0c\u7528\u4e8e\u751f\u4ea7\u73af\u5883\u8fd8\u6709\u5f88\u591a\u65b9\u9762\u53ef\u4ee5\u53bb\u6269\u5c55\u7684\u3002<\/p>\n\n\n\n<ol>\n<li>jedis cluster \u7684\u6269\u5c55\uff1a\u76ee\u524d bahir datastream \u4e2d\u5df2\u7ecf\u5b9e\u73b0\u4e86\uff0c\u53ef\u4ee5\u76f4\u63a5\u53c2\u8003\uff0c\u6269\u5c55\u8d77\u6765\u975e\u5e38\u7b80\u5355<\/li>\n\n\n\n<li>aync lookup \u7ef4\u8868\u7684\u6269\u5c55\uff1a\u76ee\u524d hbase lookup \u8868\u5df2\u7ecf\u5b9e\u73b0\u4e86\uff0c\u53ef\u4ee5\u76f4\u63a5\u53c2\u8003\u5b9e\u73b0<\/li>\n\n\n\n<li>\u5f02\u5e38 AOP\uff0calert \u7b49<\/li>\n<\/ol>\n\n\n\n<p>\u8f6c\u81ea\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.zhihu.com\/people\/onemango\" target=\"_blank\">\u5927\u6570\u636e\u7f8a\u8bf4<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.Flink sql redis \u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u4e86 flink sql redis \u7ef4\u8868\u7684\u5b9e\u73b0\u8fc7\u7a0b\u3002&hellip; <a href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91flink-sql-%e5%ae%9e%e8%b7%b52-%e8%87%aa%e5%ae%9a%e4%b9%89-redis-%e6%95%b0%e6%8d%ae%e7%bb%b4%e8%a1%a8\/\" class=\"more-link read-more\" rel=\"bookmark\">\u7ee7\u7eed\u9605\u8bfb <span class=\"screen-reader-text\">\u00a0\u3010\u8fd0\u7ef4\u5de5\u5177\u3011Flink SQL\u00a0\u5b9e\u8df52 &#8211; \u00a0\u81ea\u5b9a\u4e49 redis \u6570\u636e\u7ef4\u8868<\/span><i class=\"fa fa-arrow-right\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[25],"views":989,"_links":{"self":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/1313"}],"collection":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/comments?post=1313"}],"version-history":[{"count":4,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/1313\/revisions"}],"predecessor-version":[{"id":1320,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/1313\/revisions\/1320"}],"wp:attachment":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/media?parent=1313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/categories?post=1313"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/tags?post=1313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}