{"id":201664,"date":"2025-05-10T09:35:31","date_gmt":"2025-05-10T01:35:31","guid":{"rendered":"https:\/\/server.hk\/cnblog\/201664\/"},"modified":"2025-05-10T09:35:31","modified_gmt":"2025-05-10T01:35:31","slug":"%e5%83%8fflink%e4%b8%80%e6%a0%b7%e4%bd%bf%e7%94%a8redis","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/201664\/","title":{"rendered":"\u50cfFlink\u4e00\u6837\u4f7f\u7528Redis"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u50cfFlink\u4e00\u6837\u4f7f\u7528Redis<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f\u9700\u8981\u6709\u601d\u8003\uff0c\u6709\u521b\u65b0\u7684\u5de5\u4f5c\uff0c\u8bed\u6cd5\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\u5219\u662f\u4f9d\u9760\u4eba\u7684\u601d\u7ef4\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u575a\u6301\u5b66\u4e60\u548c\u66f4\u65b0\u81ea\u5df1\u7684\u77e5\u8bc6\u3002\u4eca\u5929golang\u5b66\u4e60\u7f51\u5c31\u6574\u7406\u5206\u4eab\u300a\u50cfFlink\u4e00\u6837\u4f7f\u7528Redis\u300b\uff0c\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ecRedis\u3001NoSQL\u3001flink\uff0c\u5982\u679c\u4f60\u5bf9\u6570\u636e\u5e93\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7golang\u5b66\u4e60\u7f51\uff0c\u5728\u8fd9\u53ef\u4ee5\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5f00\u53d1\u80fd\u529b\u7684\u63d0\u5347\u3002<\/p>\n<p>Apache Flink\u548c Redis \u662f\u4e24\u4e2a\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u4e00\u8d77\u4f7f\u7528\u6765\u6784\u5efa\u53ef\u4ee5\u5904\u7406\u5927\u91cf\u6570\u636e\u7684\u5b9e\u65f6\u6570\u636e\u5904\u7406\u7ba1\u9053\u3002Flink \u4e3a\u5904\u7406\u6570\u636e\u6d41\u63d0\u4f9b\u4e86\u4e00\u4e2a\u9ad8\u5ea6\u53ef\u6269\u5c55\u548c\u5bb9\u9519\u7684\u5e73\u53f0\uff0c\u800c Redis \u63d0\u4f9b\u4e86\u4e00\u4e2a\u9ad8\u6027\u80fd\u7684\u5185\u5b58\u6570\u636e\u5e93\uff0c\u53ef\u7528\u4e8e\u5b58\u50a8\u548c\u67e5\u8be2\u6570\u636e\u3002\u5728\u672c\u6587\u4e2d\uff0c\u5c06\u63a2\u8ba8\u5982\u4f55\u4f7f\u7528 Flink \u6765\u4f7f\u7528\u5f02\u6b65\u51fd\u6570\u8c03\u7528 Redis\uff0c\u5e76\u5c55\u793a\u5982\u4f55\u4f7f\u7528\u5b83\u4ee5\u975e\u963b\u585e\u65b9\u5f0f\u5c06\u6570\u636e\u63a8\u9001\u5230 Redis\u3002<\/p>\n<h2><span style=\"color: #ffffff\"><span style=\"background-color: #ef7060\">Redis\u7684\u6545\u4e8b<\/span><\/span><\/h2>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230414\/16814412096438c1b96fb9a.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p>\u201cRedis\uff1a\u4e0d\u4ec5\u4ec5\u662f\u4e00\u4e2a\u7f13\u5b58<\/p>\n<p>Redis \u662f\u4e00\u79cd\u529f\u80fd\u5f3a\u5927\u7684 NoSQL \u5185\u5b58\u6570\u636e\u7ed3\u6784\u5b58\u50a8\uff0c\u5df2\u6210\u4e3a\u5f00\u53d1\u4eba\u5458\u7684\u9996\u9009\u5de5\u5177\u3002\u867d\u7136\u5b83\u901a\u5e38\u88ab\u8ba4\u4e3a\u53ea\u662f\u4e00\u4e2a\u7f13\u5b58\uff0c\u4f46 Redis \u8fdc\u4e0d\u6b62\u4e8e\u6b64\u3002\u5b83\u53ef\u4ee5\u4f5c\u4e3a\u6570\u636e\u5e93\u3001\u6d88\u606f\u4ee3\u7406\u548c\u7f13\u5b58\u4e09\u8005\u5408\u4e00\u3002<\/p>\n<p>Redis \u7684\u4f18\u52bf\u4e4b\u4e00\u662f\u5b83\u7684\u591a\u529f\u80fd\u6027\u3002\u5b83\u652f\u6301\u5404\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u5305\u62ec\u5b57\u7b26\u4e32\u3001\u5217\u8868\u3001\u96c6\u5408\u3001\u6709\u5e8f\u96c6\u5408\u3001\u54c8\u5e0c\u3001\u6d41\u3001HyperLogLogs \u548c\u4f4d\u56fe\u3002Redis \u8fd8\u63d0\u4f9b\u5730\u7406\u7a7a\u95f4\u7d22\u5f15\u548c\u534a\u5f84\u67e5\u8be2\uff0c\u4f7f\u5176\u6210\u4e3a\u57fa\u4e8e\u4f4d\u7f6e\u7684\u5e94\u7528\u7a0b\u5e8f\u7684\u5b9d\u8d35\u5de5\u5177\u3002<\/p>\n<p>Redis \u7684\u529f\u80fd\u8d85\u51fa\u4e86\u5b83\u7684\u6570\u636e\u6a21\u578b\u3002\u5b83\u5177\u6709\u5185\u7f6e\u7684\u590d\u5236\u3001Lua \u811a\u672c\u548c\u4e8b\u52a1\uff0c\u5e76\u4e14\u53ef\u4ee5\u4f7f\u7528 Redis Cluster \u81ea\u52a8\u5206\u533a\u6570\u636e\u3002\u6b64\u5916\uff0cRedis \u901a\u8fc7 Redis Sentinel \u63d0\u4f9b\u9ad8\u53ef\u7528\u6027\u3002<\/p>\n<p>\u6ce8\u610f\uff1a\u5728\u672c\u6587\u4e2d\uff0c\u5c06\u66f4\u591a\u5730\u5173\u6ce8Redis\u96c6\u7fa4\u6a21\u5f0f<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230414\/16814412096438c1b9d6e75.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p>Redis \u96c6\u7fa4\u4f7f\u7528\u5e26\u54c8\u5e0c\u69fd\u7684\u7b97\u6cd5\u5206\u7247\u6765\u786e\u5b9a\u54ea\u4e2a\u5206\u7247\u62e5\u6709\u7ed9\u5b9a\u7684\u952e\u5e76\u7b80\u5316\u6dfb\u52a0\u65b0\u5b9e\u4f8b\u7684\u8fc7\u7a0b\u3002\u540c\u65f6\uff0c\u5b83\u4f7f\u7528 Gossiping \u6765\u786e\u5b9a\u96c6\u7fa4\u7684\u5065\u5eb7\u72b6\u51b5\uff0c\u5982\u679c\u4e3b\u8282\u70b9\u6ca1\u6709\u54cd\u5e94\uff0c\u53ef\u4ee5\u63d0\u5347\u8f85\u52a9\u8282\u70b9\u4ee5\u4fdd\u6301\u96c6\u7fa4\u5065\u5eb7\u3002\u5fc5\u987b\u6709\u5947\u6570\u4e2a\u4e3b\u8282\u70b9\u548c\u4e24\u4e2a\u526f\u672c\u624d\u80fd\u8fdb\u884c\u7a33\u5065\u8bbe\u7f6e\uff0c\u4ee5\u907f\u514d\u8111\u88c2\u73b0\u8c61\uff08\u96c6\u7fa4\u65e0\u6cd5\u51b3\u5b9a\u63d0\u5347\u8c01\u5e76\u6700\u7ec8\u505a\u51fa\u5206\u88c2\u51b3\u5b9a\uff09<\/p>\n<p>\u4e3a\u4e86\u4e0e Redis \u96c6\u7fa4\u5bf9\u8bdd\uff0c\u5c06\u4f7f\u7528lettuce\u548c Redis Async Java \u5ba2\u6237\u7aef\u3002<\/p>\n<h2><span style=\"color: #ffffff\"><span style=\"background-color: #ef7060\">Flink \u7684\u6545\u4e8b<\/span><\/span><\/h2>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230414\/16814412106438c1ba415ca.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p>Apache Flink \u662f\u4e00\u4e2a\u5f00\u6e90\u3001\u7edf\u4e00\u7684\u6d41\u5904\u7406\u548c\u6279\u5904\u7406\u6846\u67b6\uff0c\u65e8\u5728\u5904\u7406\u5b9e\u65f6\u3001\u9ad8\u541e\u5410\u91cf\u548c\u5bb9\u9519\u6570\u636e\u5904\u7406\u3002\u5b83\u5efa\u7acb\u5728 Apache Gelly \u6846\u67b6\u4e4b\u4e0a\uff0c\u65e8\u5728\u652f\u6301\u6709\u754c\u548c\u65e0\u754c\u6d41\u4e0a\u7684\u590d\u6742\u4e8b\u4ef6\u5904\u7406\u548c\u6709\u72b6\u6001\u8ba1\u7b97\uff0c\u5b83\u7684\u5feb\u901f\u4e4b\u5904\u5728\u4e8e\u5176\u5229\u7528\u5185\u5b58\u4e2d\u6027\u80fd\u548c\u5f02\u6b65\u68c0\u67e5\u672c\u5730\u72b6\u6001\u3002<\/p>\n<h2><span style=\"color: #ffffff\"><span style=\"background-color: #ef7060\">\u6545\u4e8b\u7684\u4e3b\u4eba\u516c<\/span><\/span><\/h2>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230414\/16814412106438c1baa9758.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p>\u4e0e\u6570\u636e\u5e93\u7684\u5f02\u6b65\u4ea4\u4e92\u662f\u6d41\u5904\u7406\u5e94\u7528\u7a0b\u5e8f\u7684\u6e38\u620f\u89c4\u5219\u6539\u53d8\u8005\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u6cd5\uff0c\u5355\u4e2a\u51fd\u6570\u5b9e\u4f8b\u53ef\u4ee5\u540c\u65f6\u5904\u7406\u591a\u4e2a\u8bf7\u6c42\uff0c\u4ece\u800c\u5141\u8bb8\u5e76\u53d1\u54cd\u5e94\u5e76\u663e\u7740\u63d0\u9ad8\u541e\u5410\u91cf\u3002\u901a\u8fc7\u5c06\u7b49\u5f85\u65f6\u95f4\u4e0e\u5176\u4ed6\u8bf7\u6c42\u548c\u54cd\u5e94\u91cd\u53e0\uff0c\u5904\u7406\u7ba1\u9053\u53d8\u5f97\u66f4\u52a0\u9ad8\u6548\u3002<\/p>\n<p>\u6211\u4eec\u5c06\u4ee5\u7535\u5546\u6570\u636e\u4e3a\u4f8b\uff0c\u8ba1\u7b9724\u5c0f\u65f6\u6ed1\u52a8\u7a97\u53e3\u4e2d\u6bcf\u4e2a\u54c1\u7c7b\u7684\u9500\u552e\u989d\uff0c\u6ed1\u52a8\u65f6\u95f4\u4e3a30\u79d2\uff0c\u4e0b\u6c89\u5230Redis\uff0c\u4ee5\u4fbf\u66f4\u5feb\u5730\u67e5\u627e\u4e0b\u6e38\u670d\u52a1\u3002<\/p>\n<p>\u5145\u8db3\u7684\u6570\u636e\u96c6<\/p>\n<p>Category<span>,<\/span> <span style=\"color: #22863a\">TimeStamp<\/span><br \/>Electronics<span>,<\/span><span style=\"color: #005cc5\">1679832334<\/span><br \/>Furniture<span>,<\/span><span style=\"color: #005cc5\">1679832336<\/span><br \/>Fashion<span>,<\/span><span style=\"color: #005cc5\">1679832378<\/span><br \/>Food<span>,<\/span><span style=\"color: #005cc5\">16798323536<\/span><\/p>\n<p>Flink Kafka \u6d88\u8d39\u8005\u7c7b<\/p>\n<p>package Aysnc_kafka_redis<span>;<\/span><\/p>\n<p>import AsyncIO<span style=\"color: #005cc5\">.RedisSink<\/span><span>;<\/span><br \/>import akka<span style=\"color: #005cc5\">.japi<\/span><span style=\"color: #005cc5\">.tuple<\/span><span style=\"color: #005cc5\">.Tuple3<\/span><span>;<\/span><br \/>import deserializer<span style=\"color: #005cc5\">.Ecommdeserialize<\/span><span>;<\/span><br \/>import model<span style=\"color: #005cc5\">.Ecomm<\/span><span>;<\/span><br \/>import org<span style=\"color: #005cc5\">.apache<\/span><span style=\"color: #005cc5\">.flink<\/span><span style=\"color: #005cc5\">.api<\/span><span style=\"color: #005cc5\">.common<\/span><span style=\"color: #005cc5\">.eventtime<\/span><span style=\"color: #005cc5\">.WatermarkStrategy<\/span><span>;<\/span><br \/>import org<span style=\"color: #005cc5\">.apache<\/span><span style=\"color: #005cc5\">.flink<\/span><span style=\"color: #005cc5\">.connector<\/span><span style=\"color: #005cc5\">.kafka<\/span><span style=\"color: #005cc5\">.source<\/span><span style=\"color: #005cc5\">.KafkaSource<\/span><span>;<\/span><br \/>import org<span style=\"color: #005cc5\">.apache<\/span><span style=\"color: #005cc5\">.flink<\/span><span style=\"color: #005cc5\">.connector<\/span><span style=\"color: #005cc5\">.kafka<\/span><span style=\"color: #005cc5\">.source<\/span><span style=\"color: #005cc5\">.enumerator<\/span><span style=\"color: #005cc5\">.initializer<\/span><span style=\"color: #005cc5\">.OffsetsInitializer<\/span><span>;<\/span><br \/>import org<span style=\"color: #005cc5\">.apache<\/span><span style=\"color: #005cc5\">.flink<\/span><span style=\"color: #005cc5\">.streaming<\/span><span style=\"color: #005cc5\">.api<\/span><span style=\"color: #005cc5\">.datastream<\/span><span style=\"color: #005cc5\">.AsyncDataStream<\/span><span>;<\/span><br \/>import org<span style=\"color: #005cc5\">.apache<\/span><span style=\"color: #005cc5\">.flink<\/span><span style=\"color: #005cc5\">.streaming<\/span><span style=\"color: #005cc5\">.api<\/span><span style=\"color: #005cc5\">.datastream<\/span><span style=\"color: #005cc5\">.DataStream<\/span><span>;<\/span><br \/>import org<span style=\"color: #005cc5\">.apache<\/span><span style=\"color: #005cc5\">.flink<\/span><span style=\"color: #005cc5\">.streaming<\/span><span style=\"color: #005cc5\">.api<\/span><span style=\"color: #005cc5\">.datastream<\/span><span style=\"color: #005cc5\">.SingleOutputStreamOperator<\/span><span>;<\/span><br \/>import org<span style=\"color: #005cc5\">.apache<\/span><span style=\"color: #005cc5\">.flink<\/span><span style=\"color: #005cc5\">.streaming<\/span><span style=\"color: #005cc5\">.api<\/span><span style=\"color: #005cc5\">.environment<\/span><span style=\"color: #005cc5\">.StreamExecutionEnvironment<\/span><span>;<\/span><br \/>import org<span style=\"color: #005cc5\">.apache<\/span><span style=\"color: #005cc5\">.flink<\/span><span style=\"color: #005cc5\">.streaming<\/span><span style=\"color: #005cc5\">.api<\/span><span style=\"color: #005cc5\">.functions<\/span><span style=\"color: #005cc5\">.timestamps<\/span><span style=\"color: #005cc5\">.BoundedOutOfOrdernessTimestampExtractor<\/span><span>;<\/span><br \/>import org<span style=\"color: #005cc5\">.apache<\/span><span style=\"color: #005cc5\">.flink<\/span><span style=\"color: #005cc5\">.streaming<\/span><span style=\"color: #005cc5\">.api<\/span><span style=\"color: #005cc5\">.functions<\/span><span style=\"color: #005cc5\">.windowing<\/span><span style=\"color: #005cc5\">.WindowFunction<\/span><span>;<\/span><br \/>import org<span style=\"color: #005cc5\">.apache<\/span><span style=\"color: #005cc5\">.flink<\/span><span style=\"color: #005cc5\">.streaming<\/span><span style=\"color: #005cc5\">.api<\/span><span style=\"color: #005cc5\">.windowing<\/span><span style=\"color: #005cc5\">.assigners<\/span><span style=\"color: #005cc5\">.TumblingEventTimeWindows<\/span><span>;<\/span><br \/>import org<span style=\"color: #005cc5\">.apache<\/span><span style=\"color: #005cc5\">.flink<\/span><span style=\"color: #005cc5\">.streaming<\/span><span style=\"color: #005cc5\">.api<\/span><span style=\"color: #005cc5\">.windowing<\/span><span style=\"color: #005cc5\">.time<\/span><span style=\"color: #005cc5\">.Time<\/span><span>;<\/span><br \/>import org<span style=\"color: #005cc5\">.apache<\/span><span style=\"color: #005cc5\">.flink<\/span><span style=\"color: #005cc5\">.streaming<\/span><span style=\"color: #005cc5\">.api<\/span><span style=\"color: #005cc5\">.windowing<\/span><span style=\"color: #005cc5\">.windows<\/span><span style=\"color: #005cc5\">.TimeWindow<\/span><span>;<\/span><br \/>import org<span style=\"color: #005cc5\">.apache<\/span><span style=\"color: #005cc5\">.flink<\/span><span style=\"color: #005cc5\">.util<\/span><span style=\"color: #005cc5\">.Collector<\/span><span>;<\/span><br \/>import java<span style=\"color: #005cc5\">.util<\/span><span style=\"color: #005cc5\">.concurrent<\/span><span style=\"color: #005cc5\">.TimeUnit<\/span><span>;<\/span><\/p>\n<p>public class FlinkAsyncRedis <span style=\"color: #997\">{<\/span><\/p>\n<p> public static void main<span style=\"color: #997\">(<\/span>String<span style=\"color: #997\">[<\/span><span style=\"color: #997\">]<\/span> args<span style=\"color: #997\">)<\/span> throws Exception <span style=\"color: #997\">{<\/span><\/p>\n<p> final StreamExecutionEnvironment env <span style=\"color: #d73a49\">=<\/span> StreamExecutionEnvironment<span style=\"color: #005cc5\">.getExecutionEnvironment<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/> Ecommdeserialize jsonde <span style=\"color: #d73a49\">=<\/span> new Ecommdeserialize<span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span>;<\/span> <\/p>\n<p> KafkaSource<span style=\"color: #d73a49\">Ecomm<span style=\"color: #d73a49\">&gt;<\/span> source <span style=\"color: #d73a49\">=<\/span> KafkaSource.<span style=\"color: #d73a49\">Ecomm<span style=\"color: #d73a49\">&gt;<\/span>builder<span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><br \/><span style=\"color: #005cc5\">.setTopics<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;{dummytopic}&#8221;<\/span><span style=\"color: #997\">)<\/span><br \/><span style=\"color: #005cc5\">.setBootstrapServers<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;{dummybootstrap}&#8221;<\/span><span style=\"color: #997\">)<\/span><br \/><span style=\"color: #005cc5\">.setGroupId<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;test_flink&#8221;<\/span><span style=\"color: #997\">)<\/span><br \/><span style=\"color: #005cc5\">.setStartingOffsets<\/span><span style=\"color: #997\">(<\/span>OffsetsInitializer<span style=\"color: #005cc5\">.earliest<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span style=\"color: #997\">)<\/span><br \/><span style=\"color: #005cc5\">.setValueOnlyDeserializer<\/span><span style=\"color: #997\">(<\/span>jsonde<span style=\"color: #997\">)<\/span><br \/><span style=\"color: #005cc5\">.build<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><\/p>\n<p> DataStream<span style=\"color: #d73a49\">Ecomm<span style=\"color: #d73a49\">&gt;<\/span> orderData <span style=\"color: #d73a49\">=<\/span> env<span style=\"color: #005cc5\">.fromSource<\/span><span style=\"color: #997\">(<\/span>source<span>,<\/span> WatermarkStrategy<span style=\"color: #005cc5\">.noWatermarks<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span>,<\/span> <span style=\"color: #690\">&#8220;Kafka Source&#8221;<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><\/p>\n<p> orderData<span style=\"color: #005cc5\">.assignTimestampsAndWatermarks<\/span><span style=\"color: #997\">(<\/span>new BoundedOutOfOrdernessTimestampExtractor<span style=\"color: #d73a49\">Ecomm<span style=\"color: #d73a49\">&gt;<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #22863a\">Time<\/span><span style=\"color: #005cc5\">.seconds<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #005cc5\">10<\/span><span style=\"color: #997\">)<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> @Override<br \/> public <span style=\"color: #22863a\">long<\/span> extractTimestamp<span style=\"color: #997\">(<\/span>Ecomm element<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> return element<span style=\"color: #005cc5\">.getEventTimestamp<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span>;<\/span> <span style=\"color: #d73a49\">\/\/<\/span> extract watermark column <span style=\"color: #d73a49\">from<\/span> stream<br \/><span style=\"color: #997\">}<\/span><br \/><span style=\"color: #997\">}<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><\/p>\n<p> SingleOutputStreamOperator<span style=\"color: #d73a49\">Tuple3<span style=\"color: #d73a49\">String<span>,<\/span> <span style=\"color: #22863a\">Long<\/span><span>,<\/span> <span style=\"color: #22863a\">Long<\/span><span style=\"color: #d73a49\">&gt;&gt;<\/span> aggregatedData <span style=\"color: #d73a49\">=<\/span> orderData<span style=\"color: #005cc5\">.keyBy<\/span><span style=\"color: #997\">(<\/span>Ecomm<span>::<\/span>getCategory<span style=\"color: #997\">)<\/span><br \/><span style=\"color: #005cc5\">.window<\/span><span style=\"color: #997\">(<\/span>SlidingEventTimeWindows<span style=\"color: #005cc5\">.of<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #22863a\">Time<\/span><span style=\"color: #005cc5\">.hours<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #005cc5\">24<\/span><span style=\"color: #997\">)<\/span><span>,<\/span><span style=\"color: #22863a\">Time<\/span><span style=\"color: #005cc5\">.seconds<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #005cc5\">30<\/span><span style=\"color: #997\">)<\/span><span style=\"color: #997\">)<\/span><span style=\"color: #997\">)<\/span><br \/><span style=\"color: #005cc5\">.apply<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #997\">(<\/span>WindowFunction<span style=\"color: #d73a49\">Ecomm<span>,<\/span> Tuple3<span style=\"color: #d73a49\">String<span>,<\/span> <span style=\"color: #22863a\">Long<\/span><span>,<\/span> <span style=\"color: #22863a\">Long<\/span><span style=\"color: #d73a49\">&gt;<\/span><span>,<\/span> String<span>,<\/span> TimeWindow<span style=\"color: #d73a49\">&gt;<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #997\">(<\/span>key<span>,<\/span> window<span>,<\/span> input<span>,<\/span> out<span style=\"color: #997\">)<\/span> <span style=\"color: #d73a49\">-&gt;<\/span> <span style=\"color: #997\">{<\/span><br \/><span style=\"color: #22863a\">long<\/span> <span style=\"color: #d73a49\">count<\/span> <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #005cc5\">0<\/span><span>;<\/span><br \/> for <span style=\"color: #997\">(<\/span>Ecomm event <span>:<\/span> input<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/><span style=\"color: #d73a49\">count<\/span><span style=\"color: #d73a49\">++<\/span><span>;<\/span> <span style=\"color: #d73a49\">\/\/<\/span> increment the <span style=\"color: #d73a49\">count<\/span> for each event <span style=\"color: #d73a49\">in<\/span> the window<br \/><span style=\"color: #997\">}<\/span><br \/> out<span style=\"color: #005cc5\">.collect<\/span><span style=\"color: #997\">(<\/span>new Tuple3<span style=\"color: #d73a49\"><\/span><span style=\"color: #997\">(<\/span>key<span>,<\/span> window<span style=\"color: #005cc5\">.getEnd<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span>,<\/span> <span style=\"color: #d73a49\">count<\/span><span style=\"color: #997\">)<\/span><span style=\"color: #997\">)<\/span><span>;<\/span> <span style=\"color: #d73a49\">\/\/<\/span> output the category<span>,<\/span> window end <span style=\"color: #22863a\">time<\/span><span>,<\/span> <span style=\"color: #d73a49\">and<\/span> <span style=\"color: #d73a49\">count<\/span><br \/><span style=\"color: #997\">}<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><\/p>\n<p><span style=\"color: #d73a49\">\/\/<\/span> calling async I<span style=\"color: #d73a49\">\/<\/span><span style=\"color: #005cc5\">0<\/span> operator to sink data to redis <span style=\"color: #d73a49\">in<\/span> UnOrdered way<br \/> SingleOutputStreamOperator<span style=\"color: #d73a49\">String<span style=\"color: #d73a49\">&gt;<\/span> sinkResults <span style=\"color: #d73a49\">=<\/span> AsyncDataStream<span style=\"color: #005cc5\">.unorderedWait<\/span><span style=\"color: #997\">(<\/span>aggregatedData<span>,<\/span>new RedisSink<span style=\"color: #997\">(<\/span><br \/><span style=\"color: #690\">&#8220;{redisClusterUrl}&#8221;<\/span><span style=\"color: #997\">)<\/span><span>,<\/span><br \/><span style=\"color: #005cc5\">1000<\/span><span>,<\/span> <span style=\"color: #d73a49\">\/\/<\/span> the timeout defines how <span style=\"color: #22863a\">long<\/span> an asynchronous operation take before it <span style=\"color: #d73a49\">is<\/span> finally considered failed<br \/> TimeUnit<span style=\"color: #005cc5\">.MILLISECONDS<\/span><span>,<\/span><br \/><span style=\"color: #005cc5\">100<\/span><span style=\"color: #997\">)<\/span><span>;<\/span> <span style=\"color: #d73a49\">\/\/<\/span>capacity This parameter defines how many asynchronous requests may be <span style=\"color: #d73a49\">in<\/span> progress at the same <span style=\"color: #22863a\">time<\/span>.<\/p>\n<p> sinkResults<span style=\"color: #005cc5\">.print<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span>;<\/span> <span style=\"color: #d73a49\">\/\/<\/span> print out the redis <span style=\"color: #d73a49\">set<\/span> response stored <span style=\"color: #d73a49\">in<\/span> the future for every key<\/p>\n<p> env<span style=\"color: #005cc5\">.execute<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;RedisAsyncSink&#8221;<\/span><span style=\"color: #997\">)<\/span><span>;<\/span> <span style=\"color: #d73a49\">\/\/<\/span> you will be able to see your job running <span style=\"color: #d73a49\">on<\/span> cluster <span style=\"color: #d73a49\">by<\/span> this name<\/p>\n<p><span style=\"color: #997\">}<\/span><\/p>\n<p><span style=\"color: #997\">}<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<p>Redis \u8bbe\u7f6e\u952e\u5f02\u6b65 I\/0 \u8fd0\u7b97\u7b26<\/p>\n<p>package AsyncIO<span>;<\/span><\/p>\n<p>import akka<span style=\"color: #005cc5\">.japi<\/span><span style=\"color: #005cc5\">.tuple<\/span><span style=\"color: #005cc5\">.Tuple3<\/span><span>;<\/span><br \/>import io<span style=\"color: #005cc5\">.lettuce<\/span><span style=\"color: #005cc5\">.core<\/span><span style=\"color: #005cc5\">.RedisFuture<\/span><span>;<\/span><br \/>import io<span style=\"color: #005cc5\">.lettuce<\/span><span style=\"color: #005cc5\">.core<\/span><span style=\"color: #005cc5\">.cluster<\/span><span style=\"color: #005cc5\">.RedisClusterClient<\/span><span>;<\/span><br \/>import io<span style=\"color: #005cc5\">.lettuce<\/span><span style=\"color: #005cc5\">.core<\/span><span style=\"color: #005cc5\">.cluster<\/span><span style=\"color: #005cc5\">.api<\/span><span style=\"color: #005cc5\">.StatefulRedisClusterConnection<\/span><span>;<\/span><br \/>import io<span style=\"color: #005cc5\">.lettuce<\/span><span style=\"color: #005cc5\">.core<\/span><span style=\"color: #005cc5\">.cluster<\/span><span style=\"color: #005cc5\">.api<\/span><span style=\"color: #005cc5\">.async<\/span><span style=\"color: #005cc5\">.RedisAdvancedClusterAsyncCommands<\/span><span>;<\/span><br \/>import lombok<span style=\"color: #005cc5\">.AllArgsConstructor<\/span><span>;<\/span><br \/>import org<span style=\"color: #005cc5\">.apache<\/span><span style=\"color: #005cc5\">.flink<\/span><span style=\"color: #005cc5\">.api<\/span><span style=\"color: #005cc5\">.java<\/span><span style=\"color: #005cc5\">.tuple<\/span><span style=\"color: #005cc5\">.Tuple2<\/span><span>;<\/span><br \/>import org<span style=\"color: #005cc5\">.apache<\/span><span style=\"color: #005cc5\">.flink<\/span><span style=\"color: #005cc5\">.configuration<\/span><span style=\"color: #005cc5\">.Configuration<\/span><span>;<\/span><br \/>import org<span style=\"color: #005cc5\">.apache<\/span><span style=\"color: #005cc5\">.flink<\/span><span style=\"color: #005cc5\">.streaming<\/span><span style=\"color: #005cc5\">.api<\/span><span style=\"color: #005cc5\">.functions<\/span><span style=\"color: #005cc5\">.async<\/span><span style=\"color: #005cc5\">.ResultFuture<\/span><span>;<\/span><br \/>import org<span style=\"color: #005cc5\">.apache<\/span><span style=\"color: #005cc5\">.flink<\/span><span style=\"color: #005cc5\">.streaming<\/span><span style=\"color: #005cc5\">.api<\/span><span style=\"color: #005cc5\">.functions<\/span><span style=\"color: #005cc5\">.async<\/span><span style=\"color: #005cc5\">.RichAsyncFunction<\/span><span>;<\/span><br \/>import scala<span style=\"color: #005cc5\">.collection<\/span><span style=\"color: #005cc5\">.immutable<\/span><span style=\"color: #005cc5\">.List<\/span><span>;<\/span><\/p>\n<p>import java<span style=\"color: #005cc5\">.util<\/span><span style=\"color: #005cc5\">.ArrayList<\/span><span>;<\/span><br \/>import java<span style=\"color: #005cc5\">.util<\/span><span style=\"color: #005cc5\">.Collections<\/span><span>;<\/span><\/p>\n<p>@AllArgsConstructor<br \/>public class RedisSink extends RichAsyncFunction<span style=\"color: #d73a49\">Tuple3<span style=\"color: #d73a49\">String<span>,<\/span> <span style=\"color: #22863a\">Long<\/span><span>,<\/span> <span style=\"color: #22863a\">Long<\/span><span style=\"color: #d73a49\">&gt;<\/span><span>,<\/span> String<span style=\"color: #d73a49\">&gt;<\/span> <span style=\"color: #997\">{<\/span><\/p>\n<p> String redisUrl<span>;<\/span><\/p>\n<p> public RedisSink<span style=\"color: #997\">(<\/span>String redisUrl<span style=\"color: #997\">)<\/span><span style=\"color: #997\">{<\/span><br \/> this<span style=\"color: #005cc5\">.redisUrl<\/span><span style=\"color: #d73a49\">=<\/span>redisUrl<span>;<\/span><br \/><span style=\"color: #997\">}<\/span><\/p>\n<p> private transient RedisClusterClient client <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #905\">null<\/span><span>;<\/span><br \/> private transient StatefulRedisClusterConnection<span style=\"color: #d73a49\">String<span>,<\/span> String<span style=\"color: #d73a49\">&gt;<\/span> clusterConnection <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #905\">null<\/span><span>;<\/span><br \/> private transient RedisAdvancedClusterAsyncCommands<span style=\"color: #d73a49\">String<span>,<\/span> String<span style=\"color: #d73a49\">&gt;<\/span> asyncCall <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #905\">null<\/span><span>;<\/span><\/p>\n<p><span style=\"color: #d73a49\">\/\/<\/span> method executes any operator<span style=\"color: #d73a49\">&#8211;<\/span>specific initialization <br \/> @Override<br \/> public void open<span style=\"color: #997\">(<\/span>Configuration parameters<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> if <span style=\"color: #997\">(<\/span>client <span style=\"color: #d73a49\">==<\/span> <span style=\"color: #905\">null<\/span> <span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> client <span style=\"color: #d73a49\">=<\/span> RedisClusterClient<span style=\"color: #005cc5\">.create<\/span><span style=\"color: #997\">(<\/span>redisUrl<span style=\"color: #997\">)<\/span><span>;<\/span><br \/><span style=\"color: #997\">}<\/span><br \/> if <span style=\"color: #997\">(<\/span>clusterConnection <span style=\"color: #d73a49\">==<\/span> <span style=\"color: #905\">null<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> clusterConnection <span style=\"color: #d73a49\">=<\/span> client<span style=\"color: #005cc5\">.connect<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/><span style=\"color: #997\">}<\/span><br \/> if <span style=\"color: #997\">(<\/span>asyncCall <span style=\"color: #d73a49\">==<\/span> <span style=\"color: #905\">null<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> asyncCall <span style=\"color: #d73a49\">=<\/span> clusterConnection<span style=\"color: #005cc5\">.async<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/><span style=\"color: #997\">}<\/span><br \/><span style=\"color: #997\">}<\/span><\/p>\n<p><span style=\"color: #d73a49\">\/\/<\/span> core logic to <span style=\"color: #d73a49\">set<\/span> key <span style=\"color: #d73a49\">in<\/span> redis using async connection <span style=\"color: #d73a49\">and<\/span> return result of the call via ResultFuture<br \/> @Override<br \/> public void asyncInvoke<span style=\"color: #997\">(<\/span>Tuple3<span style=\"color: #d73a49\">String<span>,<\/span> <span style=\"color: #22863a\">Long<\/span><span>,<\/span> <span style=\"color: #22863a\">Long<\/span><span style=\"color: #d73a49\">&gt;<\/span> stream<span>,<\/span> ResultFuture<span style=\"color: #d73a49\">String<span style=\"color: #d73a49\">&gt;<\/span> resultFuture<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><\/p>\n<p> String productKey <span style=\"color: #d73a49\">=<\/span> stream<span style=\"color: #005cc5\">.t1<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/> System<span style=\"color: #005cc5\">.out<\/span><span style=\"color: #005cc5\">.println<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;RedisKey:&#8221;<\/span> <span style=\"color: #d73a49\">+<\/span> productKey<span style=\"color: #997\">)<\/span><span>;<\/span> <span style=\"color: #d73a49\">\/\/<\/span>for logging<br \/> String <span style=\"color: #d73a49\">count<\/span> <span style=\"color: #d73a49\">=<\/span> stream<span style=\"color: #005cc5\">.t3<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span style=\"color: #005cc5\">.toString<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/> System<span style=\"color: #005cc5\">.out<\/span><span style=\"color: #005cc5\">.println<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;Redisvalue:&#8221;<\/span> <span style=\"color: #d73a49\">+<\/span> <span style=\"color: #d73a49\">count<\/span><span style=\"color: #997\">)<\/span><span>;<\/span> <span style=\"color: #d73a49\">\/\/<\/span>for logging<br \/> RedisFuture<span style=\"color: #d73a49\">String<span style=\"color: #d73a49\">&gt;<\/span> setResult <span style=\"color: #d73a49\">=<\/span> asyncCall<span style=\"color: #005cc5\">.set<\/span><span style=\"color: #997\">(<\/span>productKey<span>,<\/span><span style=\"color: #d73a49\">count<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><\/p>\n<p> setResult<span style=\"color: #005cc5\">.whenComplete<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #997\">(<\/span>result<span>,<\/span> throwable<span style=\"color: #997\">)<\/span> <span style=\"color: #d73a49\">-&gt;<\/span> <span style=\"color: #997\">{<\/span>if<span style=\"color: #997\">(<\/span>throwable<span style=\"color: #d73a49\">!=<\/span><span style=\"color: #905\">null<\/span><span style=\"color: #997\">)<\/span><span style=\"color: #997\">{<\/span><br \/> System<span style=\"color: #005cc5\">.out<\/span><span style=\"color: #005cc5\">.println<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;Callback from redis failed:&#8221;<\/span> <span style=\"color: #d73a49\">+<\/span> throwable<span style=\"color: #997\">)<\/span><span>;<\/span><br \/> resultFuture<span style=\"color: #005cc5\">.complete<\/span><span style=\"color: #997\">(<\/span>new ArrayList<span style=\"color: #d73a49\"><\/span><span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/><span style=\"color: #997\">}<\/span><br \/> else<span style=\"color: #997\">{<\/span><br \/> resultFuture<span style=\"color: #005cc5\">.complete<\/span><span style=\"color: #997\">(<\/span>new ArrayList<span style=\"color: #997\">(<\/span>Collections<span style=\"color: #005cc5\">.singleton<\/span><span style=\"color: #997\">(<\/span>result<span style=\"color: #997\">)<\/span><span style=\"color: #997\">)<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/><span style=\"color: #997\">}<\/span><span style=\"color: #997\">}<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/><span style=\"color: #997\">}<\/span><\/p>\n<p><span style=\"color: #d73a49\">\/\/<\/span> method closes what was opened during initialization to free any resources <br \/><span style=\"color: #d73a49\">\/\/<\/span> held <span style=\"color: #d73a49\">by<\/span> the operator <span style=\"color: #997\">(<\/span>e<span style=\"color: #005cc5\">.g<\/span>. open network connections<span>,<\/span> io streams<span style=\"color: #997\">)<\/span><br \/> @Override<br \/> public void close<span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span> throws Exception <span style=\"color: #997\">{<\/span><br \/> client<span style=\"color: #005cc5\">.close<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span>;<\/span><br \/><span style=\"color: #997\">}<\/span><\/p>\n<p><span style=\"color: #997\">}<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<h2><span style=\"color: #ffffff\"><span style=\"background-color: #ef7060\">\u7528\u4f8b\uff1a<\/span><\/span><\/h2>\n<ul>\n<li>\u6570\u636e\u79d1\u5b66\u6a21\u578b\u53ef\u4ee5\u4f7f\u7528\u6d41\u5f0f\u4f20\u8f93\u5230 Redis \u7684\u6570\u636e\u6765\u67e5\u627e\u548c\u751f\u6210\u66f4\u591a\u5728\u9500\u552e\u5b63\u8282\u7ecf\u5e38\u9500\u552e\u7684\u7c7b\u522b\u7684\u4ea7\u54c1\u3002<\/li>\n<li>\u5b83\u53ef\u7528\u4e8e\u5728\u7f51\u9875\u4e0a\u5c55\u793a\u56fe\u8868\u548c\u6570\u5b57\u4f5c\u4e3a\u9500\u552e\u7edf\u8ba1\u6570\u636e\uff0c\u4ee5\u5728\u7528\u6237\u4e2d\u4ea7\u751f\u79ef\u6781\u8d2d\u4e70\u7684\u52a8\u529b\u3002<\/li>\n<\/ul>\n<h2><span style=\"color: #ffffff\"><span style=\"background-color: #ef7060\">\u8981\u70b9\uff1a<\/span><\/span><\/h2>\n<ul>\n<li>Flink \u4e3a\u5904\u7406\u6570\u636e\u6d41\u63d0\u4f9b\u4e86\u4e00\u4e2a\u9ad8\u5ea6\u53ef\u6269\u5c55\u548c\u5bb9\u9519\u7684\u5e73\u53f0\uff0c\u800c Redis \u63d0\u4f9b\u4e86\u4e00\u4e2a\u9ad8\u6027\u80fd\u7684\u5185\u5b58\u6570\u636e\u5e93\uff0c\u53ef\u7528\u4e8e\u5b58\u50a8\u548c\u67e5\u8be2\u6570\u636e\u3002<\/li>\n<li>\u5f02\u6b65\u7f16\u7a0b\u53ef\u7528\u4e8e\u901a\u8fc7\u5141\u8bb8\u5bf9\u5916\u90e8\u7cfb\u7edf\uff08\u5982 Redis\uff09\u8fdb\u884c\u975e\u963b\u585e\u8c03\u7528\u6765\u63d0\u9ad8\u6570\u636e\u5904\u7406\u7ba1\u9053\u7684\u6027\u80fd\u3002<\/li>\n<li>\u4e24\u8005\u7684\u7ed3\u5408\u53ef\u80fd\u6709\u52a9\u4e8e\u5e26\u6765\u5b9e\u65f6\u6570\u636e\u51b3\u7b56\u6587\u5316\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301golang\u5b66\u4e60\u7f51\uff01\u66f4\u591a\u5173\u4e8e\u6570\u636e\u5e93\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8golang\u5b66\u4e60\u7f51\u516c\u4f17\u53f7\u3002<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u50cfFlink\u4e00\u6837\u4f7f\u7528Redis &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-201664","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201664","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"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=201664"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201664\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=201664"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=201664"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=201664"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}