{"id":3325,"date":"2025-03-24T08:46:26","date_gmt":"2025-03-23T23:46:26","guid":{"rendered":"https:\/\/dexall.co.jp\/articles\/?p=3325"},"modified":"2025-03-24T08:46:57","modified_gmt":"2025-03-23T23:46:57","slug":"%e3%80%90%e5%ae%9f%e8%b7%b5%e3%82%ac%e3%82%a4%e3%83%89%e3%80%91php%e3%82%a8%e3%83%b3%e3%82%b8%e3%83%8b%e3%82%a2%e3%81%ae%e3%81%9f%e3%82%81%e3%81%aeredis-pub-sub%e5%ae%8c%e5%85%a8%e8%a7%a3%e8%aa%ac-5","status":"publish","type":"post","link":"https:\/\/dexall.co.jp\/articles\/?p=3325","title":{"rendered":"\u3010\u5b9f\u8df5\u30ac\u30a4\u30c9\u3011PHP\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u305f\u3081\u306eRedis Pub\/Sub\u5b8c\u5168\u89e3\u8aac &#8211; 5\u3064\u306e\u5177\u4f53\u7684\u306a\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u3068\u5b9f\u88c5\u4f8b"},"content":{"rendered":"\n<div class=\"toc\"><br \/>\n<b>Warning<\/b>:  Undefined array key \"is_admin\" in <b>\/home\/xs392991\/dexall.co.jp\/public_html\/articles\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>116<\/b><br \/>\n<br \/>\n<b>Warning<\/b>:  Undefined array key \"is_category_top\" in <b>\/home\/xs392991\/dexall.co.jp\/public_html\/articles\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>121<\/b><br \/>\n<br \/>\n<b>Warning<\/b>:  Undefined array key \"is_top\" in <b>\/home\/xs392991\/dexall.co.jp\/public_html\/articles\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>128<\/b><br \/>\n    <div id=\"toc_container\" class=\"sgb-toc--bullets js-smooth-scroll\" data-dialog-title=\"\u76ee\u6b21\">\n      <p class=\"toc_title\">\u76ee\u6b21 <\/p>\n      <ul class=\"toc_list\">  <li class=\"first\">    <a href=\"#i-0\">Redis Pub\/Sub \u3068\u306f\uff1f\u57fa\u790e\u304b\u3089\u7406\u89e3\u3059\u308b\u4ed5\u7d44\u307f\u3068\u7279\u5fb4<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-1\">Pub\/Sub \u30d1\u30bf\u30fc\u30f3\u306e\u57fa\u672c\u6982\u5ff5\u3068\u91cd\u8981\u6027<\/a>      <\/li>      <li>        <a href=\"#i-4\">Redis \u304c Pub\/Sub \u306b\u9078\u3070\u308c\u308b3\u3064\u306e\u7406\u7531<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-8\">\u5f93\u6765\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u30f3\u30b0\u30b7\u30b9\u30c6\u30e0\u3068\u306e\u6bd4\u8f03<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-12\">PHP\u3067\u306eRedis Pub\/Sub\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u624b\u9806<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-13\">\u5fc5\u8981\u306a\u74b0\u5883\u3068PHP\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7<\/a>      <\/li>      <li>        <a href=\"#i-16\">\u57fa\u672c\u7684\u306aPublisher\u5b9f\u88c5\u306e\u30b9\u30c6\u30c3\u30d7<\/a>      <\/li>      <li>        <a href=\"#i-18\">\u52b9\u7387\u7684\u306aSubscriber\u5b9f\u88c5\u306e\u30dd\u30a4\u30f3\u30c8<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-21\">\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3068\u4fee\u5fa9\u51e6\u7406<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-25\">\u5b9f\u8df5\u3067\u6d3b\u304b\u305b\u308b5\u3064\u306e\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-26\">\u30c1\u30e3\u30c3\u30c8\u30b7\u30b9\u30c6\u30e0\u306e\u69cb\u7bc9<\/a>      <\/li>      <li>        <a href=\"#i-28\">\u30ad\u30e3\u30c3\u30b7\u30e5\u7121\u52b9\u5316\u306e\u81ea\u52d5\u901a\u77e5<\/a>      <\/li>      <li>        <a href=\"#i-30\">\u30b5\u30fc\u30d3\u30b9\u9593\u306e\u975e\u540c\u671f\u30de\u30a4\u30af\u30ed\u901a\u4fe1<\/a>      <\/li>      <li>        <a href=\"#i-32\">\u30a4\u30d9\u30f3\u30c8\u5206\u6790\u30b7\u30b9\u30c6\u30e0\u306e\u5b9f\u88c5<\/a>      <\/li>      <li>        <a href=\"#i-34\">\u30b2\u30fc\u30e0\u30b5\u30fc\u30d0\u30fc\u306e\u30a4\u30d9\u30f3\u30c8\u914d\u4fe1<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-36\">\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u5b9f\u88c5\u6642\u306e\u5171\u901a\u306e\u6ce8\u610f\u70b9<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-37\">Redis Pub\/Sub\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-38\">\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u306e\u6700\u9069\u5316\u30c6\u30af\u30cb\u30c3\u30af<\/a>      <\/li>      <li>        <a href=\"#i-41\">\u30b9\u30b1\u30fc\u30e9\u30d3\u30ea\u30c6\u30a3\u3092\u78ba\u4fdd\u3059\u308b\u305f\u3081\u306e\u8a2d\u8a08\u30d1\u30bf\u30fc\u30f3<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-44\">\u76e3\u8996\u3068\u904b\u7528\u306b\u5fc5\u8981\u306a\u30e1\u30c8\u30ea\u30af\u30b9<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-48\">\u672c\u756a\u74b0\u5883\u3067\u306e\u904b\u7528\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-49\">\u4fe1\u983c\u6027\u3092\u78ba\u4fdd\u3059\u308b\u305f\u3081\u306e\u5197\u9577\u5316\u8a2d\u8a08<\/a>      <\/li>      <li>        <a href=\"#i-52\">\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u5bfe\u7b56\u306e\u5b9f\u88c5\u65b9\u6cd5<\/a>      <\/li>      <li>        <a href=\"#i-55\">\u30c8\u30e9\u30d6\u30eb\u30b7\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0\u3068\u30c7\u30d0\u30c3\u30b0\u624b\u6cd5<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-58\">\u904b\u7528\u6642\u306e\u91cd\u8981\u30dd\u30a4\u30f3\u30c8<\/a>      <\/li>    <\/ul>  <\/li>  <li class=\"last\">    <a href=\"#i-59\">\u307e\u3068\u3081\uff1a\u52b9\u679c\u7684\u306aRedis Pub\/Sub\u6d3b\u7528\u306e\u30dd\u30a4\u30f3\u30c8<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-60\">\u5b9f\u8df5\u6642\u306e\u91cd\u8981\u306a\u610f\u601d\u6c7a\u5b9a\u30dd\u30a4\u30f3\u30c8<\/a>      <\/li>      <li>        <a href=\"#i-63\">\u3088\u304f\u3042\u308b\u5931\u6557\u30d1\u30bf\u30fc\u30f3\u3068\u5bfe\u7b56<\/a>      <\/li>      <li>        <a href=\"#i-66\">\u4eca\u5f8c\u306e\u5b66\u7fd2\u30ea\u30bd\u30fc\u30b9\u3068\u30b3\u30df\u30e5\u30cb\u30c6\u30a3\u60c5\u5831<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-69\">\u6700\u7d42\u30c1\u30a7\u30c3\u30af\u30ea\u30b9\u30c8<\/a>      <\/li>    <\/ul>  <\/li><\/ul>\n      <a href=\"#\" class=\"sgb-toc-button js-toc-button\" rel=\"nofollow\" data-open-dialog=\"true\"><i class=\"fa fa-list\"><\/i><span class=\"sgb-toc-button__text\">\u76ee\u6b21\u3078<\/span><\/a>\n    <\/div><\/div><h2 class=\"wp-block-heading\" id=\"i-0\">Redis Pub\/Sub \u3068\u306f\uff1f\u57fa\u790e\u304b\u3089\u7406\u89e3\u3059\u308b\u4ed5\u7d44\u307f\u3068\u7279\u5fb4<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-1\">Pub\/Sub \u30d1\u30bf\u30fc\u30f3\u306e\u57fa\u672c\u6982\u5ff5\u3068\u91cd\u8981\u6027<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Pub\/Sub\u30d1\u30bf\u30fc\u30f3\uff08Publish\/Subscribe\u30d1\u30bf\u30fc\u30f3\uff09\u306f\u3001\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u9001\u4fe1\u8005\uff08Publisher\uff09\u3068\u53d7\u4fe1\u8005\uff08Subscriber\uff09\u3092\u5206\u96e2\u3059\u308b\u975e\u540c\u671f\u901a\u4fe1\u30e2\u30c7\u30eb\u3067\u3059\u3002\u3053\u306e\u30d1\u30bf\u30fc\u30f3\u306e\u7279\u5fb4\u306f\u3001\u9001\u4fe1\u8005\u3068\u53d7\u4fe1\u8005\u304c\u4e92\u3044\u3092\u76f4\u63a5\u77e5\u308b\u5fc5\u8981\u304c\u306a\u304f\u3001\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u4ecb\u3057\u3066\u758e\u7d50\u5408\u306a\u901a\u4fe1\u3092\u5b9f\u73fe\u3067\u304d\u308b\u70b9\u306b\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-2\">Pub\/Sub\u30d1\u30bf\u30fc\u30f3\u306e\u4e3b\u8981\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Publisher\uff08\u767a\u884c\u8005\uff09<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u7279\u5b9a\u306e\u30c1\u30e3\u30cd\u30eb\u306b\u9001\u4fe1\u3059\u308b\u5f79\u5272<\/li>\n\n\n\n<li>\u9001\u4fe1\u3057\u305f\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u53d7\u3051\u53d6\u308b\u5074\u3092\u77e5\u308b\u5fc5\u8981\u304c\u306a\u3044<\/li>\n\n\n\n<li>\u8907\u6570\u306e\u30c1\u30e3\u30cd\u30eb\u306b\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u9001\u4fe1\u53ef\u80fd<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Subscriber\uff08\u8cfc\u8aad\u8005\uff09<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8208\u5473\u306e\u3042\u308b\u30c1\u30e3\u30cd\u30eb\u304b\u3089\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u53d7\u4fe1<\/li>\n\n\n\n<li>\u8907\u6570\u306e\u30c1\u30e3\u30cd\u30eb\u3092\u540c\u6642\u306b\u8cfc\u8aad\u53ef\u80fd<\/li>\n\n\n\n<li>\u52d5\u7684\u306a\u30c1\u30e3\u30cd\u30eb\u306e\u8cfc\u8aad\/\u89e3\u9664\u304c\u53ef\u80fd<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Channel\uff08\u30c1\u30e3\u30cd\u30eb\uff09<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u7d4c\u8def\u3068\u306a\u308b\u8ad6\u7406\u7684\u306a\u901a\u4fe1\u8def<\/li>\n\n\n\n<li>\u30c8\u30d4\u30c3\u30af\u30d9\u30fc\u30b9\u306e\u914d\u4fe1\u3092\u5b9f\u73fe<\/li>\n\n\n\n<li>\u4e00\u3064\u306e\u30c1\u30e3\u30cd\u30eb\u306b\u8907\u6570\u306eSubscriber\u304c\u5b58\u5728\u53ef\u80fd<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-3\">\u306a\u305cPub\/Sub\u30d1\u30bf\u30fc\u30f3\u304c\u91cd\u8981\u306a\u306e\u304b<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30b7\u30b9\u30c6\u30e0\u306e\u62e1\u5f35\u6027\u5411\u4e0a<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u9593\u306e\u758e\u7d50\u5408\u5316\u306b\u3088\u308a\u3001\u30b7\u30b9\u30c6\u30e0\u306e\u5909\u66f4\u3084\u62e1\u5f35\u304c\u5bb9\u6613<\/li>\n\n\n\n<li>\u65b0\u3057\u3044\u6a5f\u80fd\u306e\u8ffd\u52a0\u304cPublisher\/Subscriber\u53cc\u65b9\u306b\u5f71\u97ff\u3092\u4e0e\u3048\u306a\u3044<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u51e6\u7406\u306e\u5b9f\u73fe<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30a4\u30d9\u30f3\u30c8\u99c6\u52d5\u578b\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u306e\u57fa\u76e4\u3068\u3057\u3066\u6a5f\u80fd<\/li>\n\n\n\n<li>\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u5373\u6642\u914d\u4fe1\u306b\u3088\u308b\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u6027\u306e\u78ba\u4fdd<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u51e6\u7406\u306e\u52b9\u7387\u5316<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u975e\u540c\u671f\u901a\u4fe1\u306b\u3088\u308b\u51e6\u7406\u306e\u4e26\u5217\u5316<\/li>\n\n\n\n<li>\u30b7\u30b9\u30c6\u30e0\u30ea\u30bd\u30fc\u30b9\u306e\u52b9\u7387\u7684\u306a\u5229\u7528<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-4\">Redis \u304c Pub\/Sub \u306b\u9078\u3070\u308c\u308b3\u3064\u306e\u7406\u7531<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-5\">1. \u9ad8\u901f\u306a\u30e1\u30c3\u30bb\u30fc\u30b8\u30f3\u30b0\u51e6\u7406<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Redis Pub\/Sub\u306e\u6700\u5927\u306e\u7279\u5fb4\u306f\u3001\u30a4\u30f3\u30e1\u30e2\u30ea\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u3057\u3066\u306e\u7279\u6027\u3092\u6d3b\u304b\u3057\u305f\u9ad8\u901f\u306a\u30e1\u30c3\u30bb\u30fc\u30b8\u30f3\u30b0\u51e6\u7406\u3067\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30e1\u30e2\u30ea\u4e0a\u3067\u306e\u51e6\u7406\u306b\u3088\u308b\u4f4e\u30ec\u30a4\u30c6\u30f3\u30b7<\/li>\n\n\n\n<li>\u30b7\u30f3\u30d7\u30eb\u306a\u30d7\u30ed\u30c8\u30b3\u30eb\u306b\u3088\u308b\u30aa\u30fc\u30d0\u30fc\u30d8\u30c3\u30c9\u306e\u6700\u5c0f\u5316<\/li>\n\n\n\n<li>\u52b9\u7387\u7684\u306a\u30a4\u30d9\u30f3\u30c8\u99c6\u52d5\u578b\u306e\u5b9f\u88c5<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-6\">2. \u5bb9\u6613\u306a\u5c0e\u5165\u3068\u904b\u7528<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u591a\u304f\u306e\u958b\u767a\u8005\u304cRedis\u3092\u9078\u629e\u3059\u308b\u7406\u7531\u3068\u3057\u3066\u3001\u305d\u306e\u4f7f\u3044\u3084\u3059\u3055\u304c\u6319\u3052\u3089\u308c\u307e\u3059\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30b7\u30f3\u30d7\u30eb\u306a\u8a2d\u5b9a\u3068\u5c0e\u5165\u624b\u9806<\/li>\n\n\n\n<li>\u8c4a\u5bcc\u306a\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30e9\u30a4\u30d6\u30e9\u30ea<\/li>\n\n\n\n<li>\u5145\u5b9f\u3057\u305f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3068\u30b3\u30df\u30e5\u30cb\u30c6\u30a3\u30b5\u30dd\u30fc\u30c8<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-7\">3. \u30b9\u30b1\u30fc\u30e9\u30d3\u30ea\u30c6\u30a3\u3068\u4fe1\u983c\u6027<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Redis\u306f\u3001\u4ee5\u4e0b\u306e\u7279\u5fb4\u306b\u3088\u308a\u3001\u5927\u898f\u6a21\u30b7\u30b9\u30c6\u30e0\u3067\u3082\u5b89\u5b9a\u3057\u305f\u904b\u7528\u304c\u53ef\u80fd\u3067\u3059\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u306b\u3088\u308b\u6c34\u5e73\u30b9\u30b1\u30fc\u30ea\u30f3\u30b0<\/li>\n\n\n\n<li>\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306b\u3088\u308b\u53ef\u7528\u6027\u78ba\u4fdd<\/li>\n\n\n\n<li>\u81ea\u52d5\u30d5\u30a7\u30a4\u30eb\u30aa\u30fc\u30d0\u30fc\u6a5f\u80fd<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-8\">\u5f93\u6765\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u30f3\u30b0\u30b7\u30b9\u30c6\u30e0\u3068\u306e\u6bd4\u8f03<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-9\">1. RabbitMQ \u3068\u306e\u6bd4\u8f03<\/h4>\n\n\n<div id=\"id-5ced5b87-da27-4c69-a0c3-8b88bc5f8b0a\">\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u6a5f\u80fd<\/th><th>Redis Pub\/Sub<\/th><th>RabbitMQ<\/th><\/tr><\/thead><tbody><tr><td>\u30e1\u30c3\u30bb\u30fc\u30b8\u6c38\u7d9a\u5316<\/td><td>\u306a\u3057\uff08\u30a4\u30f3\u30e1\u30e2\u30ea\u306e\u307f\uff09<\/td><td>\u3042\u308a<\/td><\/tr><tr><td>\u914d\u4fe1\u4fdd\u8a3c<\/td><td>best-effort<\/td><td>\u4fdd\u8a3c\u3042\u308a<\/td><\/tr><tr><td>\u30ec\u30a4\u30c6\u30f3\u30b7<\/td><td>\u6975\u3081\u3066\u4f4e\u3044<\/td><td>\u4f4e\u3044<\/td><\/tr><tr><td>\u6a5f\u80fd\u306e\u8c4a\u5bcc\u3055<\/td><td>\u30b7\u30f3\u30d7\u30eb<\/td><td>\u591a\u6a5f\u80fd<\/td><\/tr><tr><td>\u30b9\u30b1\u30fc\u30e9\u30d3\u30ea\u30c6\u30a3<\/td><td>\u9ad8\u3044<\/td><td>\u4e2d\u7a0b\u5ea6<\/td><\/tr><\/tbody><\/table><\/figure>\n<\/div>\n\n\n<h4 class=\"wp-block-heading\" id=\"i-10\">2. Apache Kafka \u3068\u306e\u6bd4\u8f03<\/h4>\n\n\n<div id=\"id-b3257001-2952-4906-855c-37d96c3b41a4\">\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u6a5f\u80fd<\/th><th>Redis Pub\/Sub<\/th><th>Apache Kafka<\/th><\/tr><\/thead><tbody><tr><td>\u30e1\u30c3\u30bb\u30fc\u30b8\u4fdd\u6301<\/td><td>\u306a\u3057<\/td><td>\u3042\u308a\uff08\u9577\u671f\u4fdd\u5b58\u53ef\u80fd\uff09<\/td><\/tr><tr><td>\u30b9\u30eb\u30fc\u30d7\u30c3\u30c8<\/td><td>\u9ad8\u3044<\/td><td>\u6975\u3081\u3066\u9ad8\u3044<\/td><\/tr><tr><td>\u7528\u9014<\/td><td>\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u914d\u4fe1<\/td><td>\u30b9\u30c8\u30ea\u30fc\u30e0\u51e6\u7406<\/td><\/tr><tr><td>\u69cb\u6210\u306e\u8907\u96d1\u3055<\/td><td>\u30b7\u30f3\u30d7\u30eb<\/td><td>\u6bd4\u8f03\u7684\u8907\u96d1<\/td><\/tr><tr><td>\u904b\u7528\u30b3\u30b9\u30c8<\/td><td>\u4f4e\u3044<\/td><td>\u4e2d\u301c\u9ad8<\/td><\/tr><\/tbody><\/table><\/figure>\n<\/div>\n\n\n<h4 class=\"wp-block-heading\" id=\"i-11\">3. Redis Pub\/Sub\u306e\u9069\u7528\u30b7\u30fc\u30f3<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u9069\u306a\u4f7f\u7528\u30b1\u30fc\u30b9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u306e\u901a\u77e5\u30b7\u30b9\u30c6\u30e0<\/li>\n\n\n\n<li>\u30c1\u30e3\u30c3\u30c8\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3<\/li>\n\n\n\n<li>\u30b2\u30fc\u30e0\u306e\u30a4\u30d9\u30f3\u30c8\u914d\u4fe1<\/li>\n\n\n\n<li>\u30de\u30a4\u30af\u30ed\u30b5\u30fc\u30d3\u30b9\u9593\u306e\u8efd\u91cf\u306a\u901a\u4fe1<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u975e\u63a8\u5968\u306e\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30df\u30c3\u30b7\u30e7\u30f3\u30af\u30ea\u30c6\u30a3\u30ab\u30eb\u306a\u914d\u4fe1\u4fdd\u8a3c\u304c\u5fc5\u8981\u306a\u5834\u5408<\/li>\n\n\n\n<li>\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u6c38\u7d9a\u5316\u304c\u5fc5\u8981\u306a\u5834\u5408<\/li>\n\n\n\n<li>\u8907\u96d1\u306a\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u304c\u5fc5\u8981\u306a\u5834\u5408<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u306e\u3088\u3046\u306b\u3001Redis Pub\/Sub\u306f\u3001\u30b7\u30f3\u30d7\u30eb\u3055\u3068\u9ad8\u901f\u6027\u3092\u91cd\u8996\u3057\u305f\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30e1\u30c3\u30bb\u30fc\u30b8\u30f3\u30b0\u6a5f\u80fd\u3092\u63d0\u4f9b\u3057\u3001\u7279\u306b\u4f4e\u30ec\u30a4\u30c6\u30f3\u30b7\u304c\u8981\u6c42\u3055\u308c\u308b\u7528\u9014\u3067\u771f\u4fa1\u3092\u767a\u63ee\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-12\">PHP\u3067\u306eRedis Pub\/Sub\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u624b\u9806<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-13\">\u5fc5\u8981\u306a\u74b0\u5883\u3068PHP\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-14\">1. \u5fc5\u8981\u306a\u74b0\u5883<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Redis\u3092\u4f7f\u7528\u3059\u308b\u305f\u3081\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u74b0\u5883\u304c\u5fc5\u8981\u3067\u3059\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>PHP 7.4\u4ee5\u4e0a<\/li>\n\n\n\n<li>Redis \u30b5\u30fc\u30d0\u30fc\uff083.0\u4ee5\u4e0a\u63a8\u5968\uff09<\/li>\n\n\n\n<li>PHPRedis\u62e1\u5f35\u30e2\u30b8\u30e5\u30fc\u30eb<\/li>\n\n\n\n<li>Composer\uff08\u4f9d\u5b58\u95a2\u4fc2\u7ba1\u7406\u7528\uff09<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-15\">2. \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u624b\u9806<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Redis\u30b5\u30fc\u30d0\u30fc\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Ubuntu\/Debian \u306e\u5834\u5408\nsudo apt-get update\nsudo apt-get install redis-server\n\n# macOS \u306e\u5834\u5408\nbrew install redis<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>PHPRedis\u62e1\u5f35\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Ubuntu\/Debian \u306e\u5834\u5408\nsudo apt-get install php-redis\n\n# macOS \u306e\u5834\u5408\uff08PECL\u7d4c\u7531\uff09\npecl install redis<\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li>Composer\u3092\u4f7f\u7528\u3057\u305fPredis\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">composer require predis\/predis<\/pre>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li>Redis\u63a5\u7d9a\u78ba\u8a8d<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/\/ Redis\u63a5\u7d9a\u30c6\u30b9\u30c8\ntry {\n    $redis = new Redis();\n    $redis-&gt;connect('127.0.0.1', 6379);\n    echo \"Redis\u63a5\u7d9a\u6210\u529f\\n\";\n} catch (Exception $e) {\n    echo \"Redis\u63a5\u7d9a\u30a8\u30e9\u30fc: \" . $e-&gt;getMessage() . \"\\n\";\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-16\">\u57fa\u672c\u7684\u306aPublisher\u5b9f\u88c5\u306e\u30b9\u30c6\u30c3\u30d7<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-17\">1. \u30b7\u30f3\u30d7\u30eb\u306aPublisher\u5b9f\u88c5<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/\/ publisher.php\n\nclass MessagePublisher {\n    private $redis;\n    private $channel;\n\n    public function __construct(string $host = '127.0.0.1', int $port = 6379, string $channel = 'mychannel') {\n        $this-&gt;redis = new Redis();\n        $this-&gt;redis-&gt;connect($host, $port);\n        $this-&gt;channel = $channel;\n    }\n\n    public function publish(string $message): bool {\n        try {\n            \/\/ \u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u30d1\u30d6\u30ea\u30c3\u30b7\u30e5\n            $result = $this-&gt;redis-&gt;publish($this-&gt;channel, $message);\n            return $result &gt; 0;\n        } catch (Exception $e) {\n            error_log(\"Publish error: \" . $e-&gt;getMessage());\n            return false;\n        }\n    }\n\n    public function close(): void {\n        $this-&gt;redis-&gt;close();\n    }\n}\n\n\/\/ \u4f7f\u7528\u4f8b\n$publisher = new MessagePublisher();\n$publisher-&gt;publish('Hello, Redis Pub\/Sub!');\n$publisher-&gt;close();<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-18\">\u52b9\u7387\u7684\u306aSubscriber\u5b9f\u88c5\u306e\u30dd\u30a4\u30f3\u30c8<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-19\">1. \u57fa\u672c\u7684\u306aSubscriber\u5b9f\u88c5<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/\/ subscriber.php\n\nclass MessageSubscriber {\n    private $redis;\n    private $channels;\n\n    public function __construct(string $host = '127.0.0.1', int $port = 6379, array $channels = ['mychannel']) {\n        $this-&gt;redis = new Redis();\n        $this-&gt;redis-&gt;connect($host, $port);\n        $this-&gt;channels = $channels;\n    }\n\n    public function subscribe(callable $callback): void {\n        try {\n            \/\/ \u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u3092\u6307\u5b9a\u3057\u3066\u30b5\u30d6\u30b9\u30af\u30e9\u30a4\u30d6\n            $this-&gt;redis-&gt;subscribe($this-&gt;channels, function($redis, $channel, $message) use ($callback) {\n                $callback($channel, $message);\n            });\n        } catch (Exception $e) {\n            error_log(\"Subscribe error: \" . $e-&gt;getMessage());\n            throw $e;\n        }\n    }\n\n    public function close(): void {\n        $this-&gt;redis-&gt;close();\n    }\n}\n\n\/\/ \u4f7f\u7528\u4f8b\n$subscriber = new MessageSubscriber();\n$subscriber-&gt;subscribe(function($channel, $message) {\n    echo \"Received message from {$channel}: {$message}\\n\";\n});<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-20\">2. \u30d1\u30bf\u30fc\u30f3\u30d9\u30fc\u30b9\u306e\u30b5\u30d6\u30b9\u30af\u30e9\u30a4\u30d6<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/\/ pattern_subscriber.php\n\nclass PatternSubscriber {\n    private $redis;\n    private $pattern;\n\n    public function __construct(string $pattern = 'channel.*') {\n        $this-&gt;redis = new Redis();\n        $this-&gt;redis-&gt;connect('127.0.0.1', 6379);\n        $this-&gt;pattern = $pattern;\n    }\n\n    public function psubscribe(callable $callback): void {\n        try {\n            $this-&gt;redis-&gt;psubscribe([$this-&gt;pattern], function($redis, $pattern, $channel, $message) use ($callback) {\n                $callback($pattern, $channel, $message);\n            });\n        } catch (Exception $e) {\n            error_log(\"Pattern subscribe error: \" . $e-&gt;getMessage());\n            throw $e;\n        }\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-21\">\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3068\u4fee\u5fa9\u51e6\u7406<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-22\">1. \u63a5\u7d9a\u30a8\u30e9\u30fc\u306e\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/\/ error_handling.php\n\nclass RedisPubSubHandler {\n    private $redis;\n    private $retryAttempts;\n    private $retryDelay; \/\/ \u30df\u30ea\u79d2\n\n    public function __construct(int $retryAttempts = 3, int $retryDelay = 1000) {\n        $this-&gt;retryAttempts = $retryAttempts;\n        $this-&gt;retryDelay = $retryDelay;\n        $this-&gt;initializeConnection();\n    }\n\n    private function initializeConnection(): void {\n        $attempts = 0;\n        while ($attempts &lt; $this-&gt;retryAttempts) {\n            try {\n                $this-&gt;redis = new Redis();\n                $this-&gt;redis-&gt;connect('127.0.0.1', 6379);\n                return;\n            } catch (Exception $e) {\n                $attempts++;\n                if ($attempts &gt;= $this-&gt;retryAttempts) {\n                    throw new Exception(\"Failed to connect after {$this-&gt;retryAttempts} attempts\");\n                }\n                usleep($this-&gt;retryDelay * 1000); \/\/ \u30de\u30a4\u30af\u30ed\u79d2\u306b\u5909\u63db\n            }\n        }\n    }\n\n    public function reconnect(): bool {\n        try {\n            if ($this-&gt;redis-&gt;ping() !== true) {\n                $this-&gt;initializeConnection();\n            }\n            return true;\n        } catch (Exception $e) {\n            error_log(\"Reconnection failed: \" . $e-&gt;getMessage());\n            return false;\n        }\n    }\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-23\">2. \u30e1\u30c3\u30bb\u30fc\u30b8\u51e6\u7406\u306e\u4f8b\u5916\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/\/ message_handler.php\n\nclass MessageHandler {\n    private $maxRetries = 3;\n    private $publisher;\n\n    public function __construct(MessagePublisher $publisher) {\n        $this-&gt;publisher = $publisher;\n    }\n\n    public function processMessage(string $message): bool {\n        $retries = 0;\n        while ($retries &lt; $this-&gt;maxRetries) {\n            try {\n                return $this-&gt;publisher-&gt;publish($message);\n            } catch (Exception $e) {\n                $retries++;\n                error_log(\"Attempt {$retries}: Failed to process message - \" . $e-&gt;getMessage());\n                if ($retries &gt;= $this-&gt;maxRetries) {\n                    throw new Exception(\"Failed to process message after {$this-&gt;maxRetries} attempts\");\n                }\n                sleep(1); \/\/ 1\u79d2\u5f85\u6a5f\n            }\n        }\n        return false;\n    }\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-24\">\u5b9f\u88c5\u6642\u306e\u91cd\u8981\u306a\u30dd\u30a4\u30f3\u30c8<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u63a5\u7d9a\u7ba1\u7406<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u63a5\u7d9a\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u306e\u9069\u5207\u306a\u8a2d\u5b9a<\/li>\n\n\n\n<li>\u81ea\u52d5\u518d\u63a5\u7d9a\u6a5f\u80fd\u306e\u5b9f\u88c5<\/li>\n\n\n\n<li>\u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u30d7\u30fc\u30eb\u306e\u4f7f\u7528\uff08\u9ad8\u8ca0\u8377\u74b0\u5883\u306e\u5834\u5408\uff09<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30a8\u30e9\u30fc\u691c\u51fa<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Redis\u30b5\u30fc\u30d0\u30fc\u306e\u6b7b\u6d3b\u76e3\u8996<\/li>\n\n\n\n<li>\u30e1\u30c3\u30bb\u30fc\u30b8\u914d\u4fe1\u306e\u78ba\u8a8d\u6a5f\u80fd<\/li>\n\n\n\n<li>\u30a8\u30e9\u30fc\u30ed\u30b0\u306e\u9069\u5207\u306a\u8a18\u9332<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6700\u9069\u5316<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30d0\u30c3\u30c1\u51e6\u7406\u306e\u6d3b\u7528<\/li>\n\n\n\n<li>\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u306e\u76e3\u8996<\/li>\n\n\n\n<li>\u9069\u5207\u306a\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u5024\u306e\u8a2d\u5b9a<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u308c\u3089\u306e\u5b9f\u88c5\u306b\u3088\u308a\u3001\u4fe1\u983c\u6027\u306e\u9ad8\u3044Pub\/Sub\u30b7\u30b9\u30c6\u30e0\u3092\u69cb\u7bc9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-25\">\u5b9f\u8df5\u3067\u6d3b\u304b\u305b\u308b5\u3064\u306e\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-26\">\u30c1\u30e3\u30c3\u30c8\u30b7\u30b9\u30c6\u30e0\u306e\u69cb\u7bc9<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30c1\u30e3\u30c3\u30c8\u306f\u3001Redis Pub\/Sub\u306e\u7279\u6027\u3092\u6d3b\u304b\u305b\u308b\u4ee3\u8868\u7684\u306a\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/\/ chat_system.php\n\nclass ChatRoom {\n    private $redis;\n    private $roomId;\n\n    public function __construct(string $roomId) {\n        $this-&gt;redis = new Redis();\n        $this-&gt;redis-&gt;connect('127.0.0.1', 6379);\n        $this-&gt;roomId = $roomId;\n    }\n\n    public function sendMessage(string $userId, string $message): void {\n        $chatMessage = [\n            'userId' =&gt; $userId,\n            'message' =&gt; $message,\n            'timestamp' =&gt; time()\n        ];\n\n        $this-&gt;redis-&gt;publish(\n            \"chatroom.{$this-&gt;roomId}\",\n            json_encode($chatMessage)\n        );\n    }\n\n    public function subscribe(callable $callback): void {\n        $this-&gt;redis-&gt;subscribe(\n            [\"chatroom.{$this-&gt;roomId}\"],\n            function($redis, $channel, $message) use ($callback) {\n                $callback(json_decode($message, true));\n            }\n        );\n    }\n}\n\n\/\/ \u4f7f\u7528\u4f8b\n$chatRoom = new ChatRoom('room1');\n\n\/\/ \u30e1\u30c3\u30bb\u30fc\u30b8\u9001\u4fe1\n$chatRoom-&gt;sendMessage('user123', '\u3053\u3093\u306b\u3061\u306f\uff01');\n\n\/\/ \u30e1\u30c3\u30bb\u30fc\u30b8\u53d7\u4fe1\n$chatRoom-&gt;subscribe(function($message) {\n    echo \"{$message['userId']}: {$message['message']}\\n\";\n});<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-27\">\u5b9f\u88c5\u306e\u30dd\u30a4\u30f3\u30c8<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30e6\u30fc\u30b6\u30fc\u3054\u3068\u306e\u63a5\u7d9a\u7ba1\u7406<\/li>\n\n\n\n<li>\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u7d71\u4e00<\/li>\n\n\n\n<li>\u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7\u306e\u4ed8\u4e0e<\/li>\n\n\n\n<li>\u30a8\u30e9\u30fc\u6642\u306e\u518d\u63a5\u7d9a\u51e6\u7406<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-28\">\u30ad\u30e3\u30c3\u30b7\u30e5\u7121\u52b9\u5316\u306e\u81ea\u52d5\u901a\u77e5<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5206\u6563\u30b7\u30b9\u30c6\u30e0\u3067\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u6574\u5408\u6027\u3092\u4fdd\u3064\u305f\u3081\u306b\u3001Pub\/Sub\u3092\u6d3b\u7528\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/\/ cache_invalidator.php\n\nclass CacheInvalidator {\n    private $redis;\n    private $prefix = 'cache_invalidation';\n\n    public function __construct() {\n        $this-&gt;redis = new Redis();\n        $this-&gt;redis-&gt;connect('127.0.0.1', 6379);\n    }\n\n    public function invalidateCache(string $cacheKey): void {\n        $invalidationMessage = [\n            'key' =&gt; $cacheKey,\n            'timestamp' =&gt; microtime(true)\n        ];\n\n        $this-&gt;redis-&gt;publish(\n            \"{$this-&gt;prefix}.invalidate\",\n            json_encode($invalidationMessage)\n        );\n    }\n\n    public function listenForInvalidation(callable $callback): void {\n        $this-&gt;redis-&gt;subscribe(\n            [\"{$this-&gt;prefix}.invalidate\"],\n            function($redis, $channel, $message) use ($callback) {\n                $data = json_decode($message, true);\n                $callback($data['key'], $data['timestamp']);\n            }\n        );\n    }\n}\n\n\/\/ \u30ad\u30e3\u30c3\u30b7\u30e5\u30de\u30cd\u30fc\u30b8\u30e3\u30fc\u306e\u5b9f\u88c5\nclass CacheManager {\n    private $localCache = [];\n    private $invalidator;\n\n    public function __construct() {\n        $this-&gt;invalidator = new CacheInvalidator();\n        $this-&gt;startInvalidationListener();\n    }\n\n    private function startInvalidationListener(): void {\n        $this-&gt;invalidator-&gt;listenForInvalidation(\n            function($key, $timestamp) {\n                unset($this-&gt;localCache[$key]);\n                error_log(\"Cache invalidated for key: {$key}\");\n            }\n        );\n    }\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-29\">\u5b9f\u88c5\u306e\u30dd\u30a4\u30f3\u30c8<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7\u306b\u3088\u308b\u9806\u5e8f\u5236\u5fa1<\/li>\n\n\n\n<li>\u7121\u52b9\u5316\u306e\u5373\u6642\u53cd\u6620<\/li>\n\n\n\n<li>\u30c7\u30c3\u30c9\u30ed\u30c3\u30af\u9632\u6b62<\/li>\n\n\n\n<li>\u969c\u5bb3\u6642\u306e\u30d5\u30a9\u30fc\u30eb\u30d0\u30c3\u30af\u51e6\u7406<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-30\">\u30b5\u30fc\u30d3\u30b9\u9593\u306e\u975e\u540c\u671f\u30de\u30a4\u30af\u30ed\u901a\u4fe1<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u30de\u30a4\u30af\u30ed\u30b5\u30fc\u30d3\u30b9\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u3067\u306e\u8efd\u91cf\u306a\u901a\u4fe1\u624b\u6bb5\u3068\u3057\u3066\u6d3b\u7528\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/\/ microservice_communicator.php\n\nclass ServiceCommunicator {\n    private $redis;\n    private $serviceName;\n    private $messageHandlers = [];\n\n    public function __construct(string $serviceName) {\n        $this-&gt;redis = new Redis();\n        $this-&gt;redis-&gt;connect('127.0.0.1', 6379);\n        $this-&gt;serviceName = $serviceName;\n    }\n\n    public function registerHandler(string $eventType, callable $handler): void {\n        $this-&gt;messageHandlers[$eventType] = $handler;\n    }\n\n    public function sendEvent(string $targetService, string $eventType, array $data): void {\n        $event = [\n            'source' =&gt; $this-&gt;serviceName,\n            'type' =&gt; $eventType,\n            'data' =&gt; $data,\n            'id' =&gt; uniqid(),\n            'timestamp' =&gt; microtime(true)\n        ];\n\n        $this-&gt;redis-&gt;publish(\n            \"service.{$targetService}\",\n            json_encode($event)\n        );\n    }\n\n    public function startListening(): void {\n        $this-&gt;redis-&gt;subscribe(\n            [\"service.{$this-&gt;serviceName}\"],\n            function($redis, $channel, $message) {\n                $event = json_decode($message, true);\n                if (isset($this-&gt;messageHandlers[$event['type']])) {\n                    $this-&gt;messageHandlers[$event['type']]($event);\n                }\n            }\n        );\n    }\n}\n\n\/\/ \u4f7f\u7528\u4f8b\n$orderService = new ServiceCommunicator('order_service');\n$orderService-&gt;registerHandler('payment_completed', function($event) {\n    \/\/ \u6ce8\u6587\u30b9\u30c6\u30fc\u30bf\u30b9\u306e\u66f4\u65b0\u51e6\u7406\n    updateOrderStatus($event['data']['orderId'], 'paid');\n});<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-31\">\u5b9f\u88c5\u306e\u30dd\u30a4\u30f3\u30c8<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30a4\u30d9\u30f3\u30c8\u306e\u4e00\u610f\u6027\u78ba\u4fdd<\/li>\n\n\n\n<li>\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u51aa\u7b49\u6027<\/li>\n\n\n\n<li>\u30b5\u30fc\u30d3\u30b9\u9593\u306e\u4f9d\u5b58\u95a2\u4fc2\u7ba1\u7406<\/li>\n\n\n\n<li>\u30a8\u30e9\u30fc\u767a\u751f\u6642\u306e\u4ee3\u66ff\u51e6\u7406<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-32\">\u30a4\u30d9\u30f3\u30c8\u5206\u6790\u30b7\u30b9\u30c6\u30e0\u306e\u5b9f\u88c5<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u30e6\u30fc\u30b6\u30fc\u30a2\u30af\u30b7\u30e7\u30f3\u306e\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u5206\u6790\u3092\u5b9f\u73fe\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/\/ event_analyzer.php\n\nclass EventAnalyzer {\n    private $redis;\n    private $eventBuffer = [];\n    private $bufferSize = 100;\n\n    public function __construct() {\n        $this-&gt;redis = new Redis();\n        $this-&gt;redis-&gt;connect('127.0.0.1', 6379);\n    }\n\n    public function trackEvent(string $eventType, array $eventData): void {\n        $event = [\n            'type' =&gt; $eventType,\n            'data' =&gt; $eventData,\n            'timestamp' =&gt; microtime(true)\n        ];\n\n        $this-&gt;redis-&gt;publish('analytics.events', json_encode($event));\n    }\n\n    public function startAnalysis(): void {\n        $this-&gt;redis-&gt;subscribe(['analytics.events'], function($redis, $channel, $message) {\n            $event = json_decode($message, true);\n            $this-&gt;processEvent($event);\n        });\n    }\n\n    private function processEvent(array $event): void {\n        $this-&gt;eventBuffer[] = $event;\n\n        if (count($this-&gt;eventBuffer) &gt;= $this-&gt;bufferSize) {\n            $this-&gt;analyzeBuffer();\n            $this-&gt;eventBuffer = [];\n        }\n    }\n\n    private function analyzeBuffer(): void {\n        \/\/ \u30a4\u30d9\u30f3\u30c8\u306e\u96c6\u8a08\u3068\u5206\u6790\n        $analysis = [\n            'event_counts' =&gt; [],\n            'time_range' =&gt; [\n                'start' =&gt; PHP_FLOAT_MAX,\n                'end' =&gt; 0\n            ]\n        ];\n\n        foreach ($this-&gt;eventBuffer as $event) {\n            $type = $event['type'];\n            $analysis['event_counts'][$type] = ($analysis['event_counts'][$type] ?? 0) + 1;\n\n            $analysis['time_range']['start'] = min($analysis['time_range']['start'], $event['timestamp']);\n            $analysis['time_range']['end'] = max($analysis['time_range']['end'], $event['timestamp']);\n        }\n\n        \/\/ \u5206\u6790\u7d50\u679c\u306e\u4fdd\u5b58\u3084\u901a\u77e5\n        $this-&gt;saveAnalysisResults($analysis);\n    }\n\n    private function saveAnalysisResults(array $analysis): void {\n        \/\/ \u5206\u6790\u7d50\u679c\u306e\u6c38\u7d9a\u5316\u51e6\u7406\n    }\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-33\">\u5b9f\u88c5\u306e\u30dd\u30a4\u30f3\u30c8<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30d0\u30c3\u30d5\u30a1\u30ea\u30f3\u30b0\u306b\u3088\u308b\u52b9\u7387\u5316<\/li>\n\n\n\n<li>\u30a4\u30d9\u30f3\u30c8\u306e\u6642\u7cfb\u5217\u7ba1\u7406<\/li>\n\n\n\n<li>\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u306e\u5236\u5fa1<\/li>\n\n\n\n<li>\u30b9\u30b1\u30fc\u30e9\u30d6\u30eb\u306a\u8a2d\u8a08<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-34\">\u30b2\u30fc\u30e0\u30b5\u30fc\u30d0\u30fc\u306e\u30a4\u30d9\u30f3\u30c8\u914d\u4fe1<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u30de\u30eb\u30c1\u30d7\u30ec\u30a4\u30e4\u30fc\u30b2\u30fc\u30e0\u3067\u306e\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30a4\u30d9\u30f3\u30c8\u914d\u4fe1\u3092\u5b9f\u73fe\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/\/ game_event_broadcaster.php\n\nclass GameEventBroadcaster {\n    private $redis;\n    private $gameId;\n\n    public function __construct(string $gameId) {\n        $this-&gt;redis = new Redis();\n        $this-&gt;redis-&gt;connect('127.0.0.1', 6379);\n        $this-&gt;gameId = $gameId;\n    }\n\n    public function broadcastGameEvent(string $eventType, array $eventData): void {\n        $gameEvent = [\n            'type' =&gt; $eventType,\n            'data' =&gt; $eventData,\n            'gameId' =&gt; $this-&gt;gameId,\n            'sequence' =&gt; $this-&gt;getNextSequence(),\n            'timestamp' =&gt; microtime(true)\n        ];\n\n        $this-&gt;redis-&gt;publish(\n            \"game.{$this-&gt;gameId}.events\",\n            json_encode($gameEvent)\n        );\n    }\n\n    public function subscribeToGameEvents(callable $callback): void {\n        $this-&gt;redis-&gt;subscribe(\n            [\"game.{$this-&gt;gameId}.events\"],\n            function($redis, $channel, $message) use ($callback) {\n                $event = json_decode($message, true);\n                $callback($event);\n            }\n        );\n    }\n\n    private function getNextSequence(): int {\n        return $this-&gt;redis-&gt;incr(\"game:{$this-&gt;gameId}:sequence\");\n    }\n}\n\n\/\/ \u30b2\u30fc\u30e0\u30a4\u30d9\u30f3\u30c8\u30cf\u30f3\u30c9\u30e9\u30fc\u306e\u5b9f\u88c5\nclass GameEventHandler {\n    private $broadcaster;\n    private $gameState;\n\n    public function __construct(string $gameId) {\n        $this-&gt;broadcaster = new GameEventBroadcaster($gameId);\n        $this-&gt;gameState = [];\n    }\n\n    public function handlePlayerAction(string $playerId, array $action): void {\n        \/\/ \u30a2\u30af\u30b7\u30e7\u30f3\u306e\u691c\u8a3c\n        if ($this-&gt;validateAction($action)) {\n            \/\/ \u30b2\u30fc\u30e0\u72b6\u614b\u306e\u66f4\u65b0\n            $this-&gt;updateGameState($playerId, $action);\n\n            \/\/ \u30a4\u30d9\u30f3\u30c8\u306e\u30d6\u30ed\u30fc\u30c9\u30ad\u30e3\u30b9\u30c8\n            $this-&gt;broadcaster-&gt;broadcastGameEvent('player_action', [\n                'playerId' =&gt; $playerId,\n                'action' =&gt; $action,\n                'gameState' =&gt; $this-&gt;gameState\n            ]);\n        }\n    }\n\n    private function validateAction(array $action): bool {\n        \/\/ \u30a2\u30af\u30b7\u30e7\u30f3\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30ed\u30b8\u30c3\u30af\n        return true;\n    }\n\n    private function updateGameState(string $playerId, array $action): void {\n        \/\/ \u30b2\u30fc\u30e0\u72b6\u614b\u306e\u66f4\u65b0\u30ed\u30b8\u30c3\u30af\n    }\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-35\">\u5b9f\u88c5\u306e\u30dd\u30a4\u30f3\u30c8<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30b7\u30fc\u30b1\u30f3\u30b9\u756a\u53f7\u306b\u3088\u308b\u9806\u5e8f\u4fdd\u8a3c<\/li>\n\n\n\n<li>\u4f4e\u30ec\u30a4\u30c6\u30f3\u30b7\u306e\u7dad\u6301<\/li>\n\n\n\n<li>\u72b6\u614b\u306e\u6574\u5408\u6027\u78ba\u4fdd<\/li>\n\n\n\n<li>\u30b9\u30b1\u30fc\u30e9\u30d6\u30eb\u306a\u8a2d\u8a08<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-36\">\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u5b9f\u88c5\u6642\u306e\u5171\u901a\u306e\u6ce8\u610f\u70b9<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30b9\u30b1\u30fc\u30e9\u30d3\u30ea\u30c6\u30a3\u306e\u8003\u616e<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6c34\u5e73\u30b9\u30b1\u30fc\u30ea\u30f3\u30b0\u3078\u306e\u5bfe\u5fdc<\/li>\n\n\n\n<li>\u8ca0\u8377\u5206\u6563\u306e\u5b9f\u88c5<\/li>\n\n\n\n<li>\u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u30d7\u30fc\u30eb\u306e\u9069\u5207\u306a\u8a2d\u5b9a<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u63a5\u7d9a\u65ad\u306e\u691c\u77e5\u3068\u518d\u63a5\u7d9a<\/li>\n\n\n\n<li>\u30e1\u30c3\u30bb\u30fc\u30b8\u640d\u5931\u306e\u5bfe\u7b56<\/li>\n\n\n\n<li>\u30c7\u30c3\u30c9\u30ec\u30bf\u30fc\u51e6\u7406\u306e\u5b9f\u88c5<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30e2\u30cb\u30bf\u30ea\u30f3\u30b0\u3068\u30ed\u30ae\u30f3\u30b0<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30e1\u30c8\u30ea\u30af\u30b9\u306e\u53ce\u96c6<\/li>\n\n\n\n<li>\u30a8\u30e9\u30fc\u30ed\u30b0\u306e\u9069\u5207\u306a\u8a18\u9332<\/li>\n\n\n\n<li>\u30b7\u30b9\u30c6\u30e0\u72b6\u614b\u306e\u53ef\u8996\u5316<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u5bfe\u7b56<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30c1\u30e3\u30cd\u30eb\u30a2\u30af\u30bb\u30b9\u306e\u5236\u5fa1<\/li>\n\n\n\n<li>\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u691c\u8a3c<\/li>\n\n\n\n<li>DoS\u653b\u6483\u5bfe\u7b56<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-37\">Redis Pub\/Sub\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-38\">\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u306e\u6700\u9069\u5316\u30c6\u30af\u30cb\u30c3\u30af<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Redis Pub\/Sub\u306e\u30e1\u30e2\u30ea\u4f7f\u7528\u3092\u6700\u9069\u5316\u3059\u308b\u3053\u3068\u306f\u3001\u30b7\u30b9\u30c6\u30e0\u306e\u5b89\u5b9a\u6027\u3068\u52b9\u7387\u6027\u3092\u78ba\u4fdd\u3059\u308b\u4e0a\u3067\u91cd\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-39\">1. \u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u306e\u76e3\u8996<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/\/ memory_monitor.php\n\nclass RedisMemoryMonitor {\n    private $redis;\n    private $warningThreshold;  \/\/ \u30e1\u30e2\u30ea\u4f7f\u7528\u7387\u306e\u8b66\u544a\u3057\u304d\u3044\u5024\uff08%\uff09\n\n    public function __construct(float $warningThreshold = 80.0) {\n        $this-&gt;redis = new Redis();\n        $this-&gt;redis-&gt;connect('127.0.0.1', 6379);\n        $this-&gt;warningThreshold = $warningThreshold;\n    }\n\n    public function checkMemoryUsage(): array {\n        $info = $this-&gt;redis-&gt;info('memory');\n        $usedMemory = $info['used_memory'];\n        $maxMemory = $info['maxmemory'] ?: PHP_INT_MAX;\n\n        $usagePercent = ($usedMemory \/ $maxMemory) * 100;\n\n        return [\n            'used_memory' =&gt; $this-&gt;formatBytes($usedMemory),\n            'max_memory' =&gt; $this-&gt;formatBytes($maxMemory),\n            'usage_percent' =&gt; round($usagePercent, 2),\n            'warning' =&gt; $usagePercent &gt; $this-&gt;warningThreshold\n        ];\n    }\n\n    private function formatBytes(int $bytes): string {\n        $units = ['B', 'KB', 'MB', 'GB'];\n        $index = 0;\n        while ($bytes &gt;= 1024 &amp;&amp; $index &lt; count($units) - 1) {\n            $bytes \/= 1024;\n            $index++;\n        }\n        return round($bytes, 2) . ' ' . $units[$index];\n    }\n\n    public function getSubscriberCount(): array {\n        $pubsubInfo = $this-&gt;redis-&gt;pubsub('NUMSUB');\n        $channelStats = [];\n\n        for ($i = 0; $i &lt; count($pubsubInfo); $i += 2) {\n            $channelStats[$pubsubInfo[$i]] = $pubsubInfo[$i + 1];\n        }\n\n        return $channelStats;\n    }\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-40\">2. \u30e1\u30e2\u30ea\u6700\u9069\u5316\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30e1\u30c3\u30bb\u30fc\u30b8\u30b5\u30a4\u30ba\u306e\u5236\u5fa1<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class MessageOptimizer {\n    private const MAX_MESSAGE_SIZE = 1024 * 10; \/\/ 10KB\n\n    public static function optimizeMessage(array $message): string {\n        \/\/ \u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u5727\u7e2e\n        $jsonMessage = json_encode($message);\n        if (strlen($jsonMessage) &gt; self::MAX_MESSAGE_SIZE) {\n            \/\/ \u5927\u304d\u306a\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u5834\u5408\u306f\u8981\u7d04\u60c5\u5831\u306e\u307f\u3092\u9001\u4fe1\n            return json_encode([\n                'type' =&gt; 'summary',\n                'original_size' =&gt; strlen($jsonMessage),\n                'summary' =&gt; substr($message['content'], 0, 100) . '...',\n                'timestamp' =&gt; $message['timestamp']\n            ]);\n        }\n        return $jsonMessage;\n    }\n}<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>\u30c1\u30e3\u30cd\u30eb\u7ba1\u7406\u306e\u6700\u9069\u5316<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class ChannelManager {\n    private $redis;\n    private $channelPrefix;\n    private $maxChannels = 1000;\n\n    public function __construct(string $channelPrefix) {\n        $this-&gt;redis = new Redis();\n        $this-&gt;redis-&gt;connect('127.0.0.1', 6379);\n        $this-&gt;channelPrefix = $channelPrefix;\n    }\n\n    public function cleanupUnusedChannels(): array {\n        $channels = $this-&gt;redis-&gt;pubsub('CHANNELS', \"{$this-&gt;channelPrefix}:*\");\n        $cleanupCount = 0;\n\n        foreach ($channels as $channel) {\n            $subscriberCount = $this-&gt;redis-&gt;pubsub('NUMSUB', $channel)[1];\n            if ($subscriberCount === 0) {\n                \/\/ \u672a\u4f7f\u7528\u30c1\u30e3\u30cd\u30eb\u306e\u60c5\u5831\u3092\u30af\u30ea\u30fc\u30f3\u30a2\u30c3\u30d7\n                $this-&gt;redis-&gt;del(\"channel_info:{$channel}\");\n                $cleanupCount++;\n            }\n        }\n\n        return [\n            'total_channels' =&gt; count($channels),\n            'cleaned_channels' =&gt; $cleanupCount\n        ];\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-41\">\u30b9\u30b1\u30fc\u30e9\u30d3\u30ea\u30c6\u30a3\u3092\u78ba\u4fdd\u3059\u308b\u305f\u3081\u306e\u8a2d\u8a08\u30d1\u30bf\u30fc\u30f3<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-42\">1. \u30b7\u30e3\u30fc\u30c7\u30a3\u30f3\u30b0\u30d1\u30bf\u30fc\u30f3<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class ShardedPublisher {\n    private $redis;\n    private $shardCount;\n\n    public function __construct(int $shardCount = 10) {\n        $this-&gt;redis = new Redis();\n        $this-&gt;redis-&gt;connect('127.0.0.1', 6379);\n        $this-&gt;shardCount = $shardCount;\n    }\n\n    public function publish(string $channel, array $message): void {\n        \/\/ \u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u30b7\u30e3\u30fc\u30c7\u30a3\u30f3\u30b0\n        $shardId = $this-&gt;getShardId($message);\n        $shardedChannel = \"{$channel}:shard:{$shardId}\";\n\n        $this-&gt;redis-&gt;publish($shardedChannel, json_encode($message));\n    }\n\n    private function getShardId(array $message): int {\n        \/\/ \u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u7279\u6027\u306b\u57fa\u3065\u3044\u3066\u30b7\u30e3\u30fc\u30c9\u3092\u6c7a\u5b9a\n        $key = $message['user_id'] ?? $message['id'] ?? uniqid();\n        return crc32($key) % $this-&gt;shardCount;\n    }\n}\n\nclass ShardedSubscriber {\n    private $redis;\n    private $shardCount;\n    private $handlers = [];\n\n    public function __construct(int $shardCount = 10) {\n        $this-&gt;redis = new Redis();\n        $this-&gt;redis-&gt;connect('127.0.0.1', 6379);\n        $this-&gt;shardCount = $shardCount;\n    }\n\n    public function subscribe(string $baseChannel, callable $handler): void {\n        $channels = [];\n        for ($i = 0; $i &lt; $this-&gt;shardCount; $i++) {\n            $channels[] = \"{$baseChannel}:shard:{$i}\";\n        }\n\n        $this-&gt;redis-&gt;subscribe($channels, function($redis, $channel, $message) use ($handler) {\n            $handler(json_decode($message, true));\n        });\n    }\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-43\">2. \u30d0\u30c3\u30d5\u30a1\u30ea\u30f3\u30b0\u30d1\u30bf\u30fc\u30f3<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class MessageBuffer {\n    private $buffer = [];\n    private $maxSize;\n    private $flushInterval;\n    private $lastFlush;\n    private $publisher;\n\n    public function __construct(int $maxSize = 100, int $flushInterval = 1000) {\n        $this-&gt;maxSize = $maxSize;\n        $this-&gt;flushInterval = $flushInterval;\n        $this-&gt;lastFlush = microtime(true) * 1000;\n        $this-&gt;publisher = new Redis();\n        $this-&gt;publisher-&gt;connect('127.0.0.1', 6379);\n    }\n\n    public function addMessage(string $channel, array $message): void {\n        $this-&gt;buffer[] = [\n            'channel' =&gt; $channel,\n            'message' =&gt; $message\n        ];\n\n        if ($this-&gt;shouldFlush()) {\n            $this-&gt;flush();\n        }\n    }\n\n    private function shouldFlush(): bool {\n        $currentTime = microtime(true) * 1000;\n        return count($this-&gt;buffer) &gt;= $this-&gt;maxSize ||\n               ($currentTime - $this-&gt;lastFlush) &gt;= $this-&gt;flushInterval;\n    }\n\n    private function flush(): void {\n        if (empty($this-&gt;buffer)) {\n            return;\n        }\n\n        \/\/ \u30d0\u30c3\u30c1\u51e6\u7406\u3067\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u9001\u4fe1\n        $pipeline = $this-&gt;publisher-&gt;multi(Redis::PIPELINE);\n        foreach ($this-&gt;buffer as $item) {\n            $pipeline-&gt;publish($item['channel'], json_encode($item['message']));\n        }\n        $pipeline-&gt;exec();\n\n        $this-&gt;buffer = [];\n        $this-&gt;lastFlush = microtime(true) * 1000;\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-44\">\u76e3\u8996\u3068\u904b\u7528\u306b\u5fc5\u8981\u306a\u30e1\u30c8\u30ea\u30af\u30b9<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-45\">1. \u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30e1\u30c8\u30ea\u30af\u30b9\u306e\u53ce\u96c6<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class PubSubMetricsCollector {\n    private $redis;\n    private $metricsKey;\n\n    public function __construct(string $metricsKey = 'pubsub:metrics') {\n        $this-&gt;redis = new Redis();\n        $this-&gt;redis-&gt;connect('127.0.0.1', 6379);\n        $this-&gt;metricsKey = $metricsKey;\n    }\n\n    public function collectMetrics(): array {\n        $metrics = [\n            'timestamp' =&gt; time(),\n            'pub_sub_patterns' =&gt; $this-&gt;redis-&gt;pubsub('NUMPAT'),\n            'channels' =&gt; $this-&gt;getChannelMetrics(),\n            'memory' =&gt; $this-&gt;getMemoryMetrics(),\n            'clients' =&gt; $this-&gt;getClientMetrics()\n        ];\n\n        \/\/ \u30e1\u30c8\u30ea\u30af\u30b9\u306e\u4fdd\u5b58\n        $this-&gt;redis-&gt;hSet(\n            $this-&gt;metricsKey,\n            (string)$metrics['timestamp'],\n            json_encode($metrics)\n        );\n\n        \/\/ \u53e4\u3044\u30e1\u30c8\u30ea\u30af\u30b9\u306e\u524a\u9664\uff0824\u6642\u9593\u4ee5\u4e0a\u524d\uff09\n        $this-&gt;redis-&gt;zRemRangeByScore(\n            $this-&gt;metricsKey,\n            0,\n            time() - 86400\n        );\n\n        return $metrics;\n    }\n\n    private function getChannelMetrics(): array {\n        $channels = $this-&gt;redis-&gt;pubsub('CHANNELS');\n        $metrics = [];\n\n        foreach ($channels as $channel) {\n            $subscribers = $this-&gt;redis-&gt;pubsub('NUMSUB', $channel);\n            $metrics[$channel] = [\n                'subscribers' =&gt; $subscribers[1],\n                'messages_per_second' =&gt; $this-&gt;getChannelMessageRate($channel)\n            ];\n        }\n\n        return $metrics;\n    }\n\n    private function getMemoryMetrics(): array {\n        $info = $this-&gt;redis-&gt;info('memory');\n        return [\n            'used_memory' =&gt; $info['used_memory'],\n            'used_memory_peak' =&gt; $info['used_memory_peak'],\n            'fragmentation_ratio' =&gt; $info['mem_fragmentation_ratio']\n        ];\n    }\n\n    private function getClientMetrics(): array {\n        $info = $this-&gt;redis-&gt;info('clients');\n        return [\n            'connected_clients' =&gt; $info['connected_clients'],\n            'blocked_clients' =&gt; $info['blocked_clients']\n        ];\n    }\n\n    private function getChannelMessageRate(string $channel): float {\n        \/\/ 1\u79d2\u9593\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u30ec\u30fc\u30c8\u3092\u8a08\u7b97\n        $samples = 10;\n        $totalMessages = 0;\n\n        for ($i = 0; $i &lt; $samples; $i++) {\n            $before = $this-&gt;getChannelMessageCount($channel);\n            usleep(100000); \/\/ 100ms\n            $after = $this-&gt;getChannelMessageCount($channel);\n            $totalMessages += ($after - $before);\n        }\n\n        return $totalMessages \/ ($samples * 0.1);\n    }\n\n    private function getChannelMessageCount(string $channel): int {\n        \/\/ \u30c1\u30e3\u30cd\u30eb\u3054\u3068\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u30ab\u30a6\u30f3\u30c8\u53d6\u5f97\n        return (int)$this-&gt;redis-&gt;get(\"channel:{$channel}:message_count\");\n    }\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-46\">2. \u30a2\u30e9\u30fc\u30c8\u8a2d\u5b9a\u306e\u5b9f\u88c5\u4f8b<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class PubSubAlertManager {\n    private $metricsCollector;\n    private $notificationHandlers = [];\n    private $thresholds = [\n        'memory_usage' =&gt; 80,  \/\/ \u30e1\u30e2\u30ea\u4f7f\u7528\u7387\uff08%\uff09\n        'subscriber_count' =&gt; 1000,  \/\/ \u30b5\u30d6\u30b9\u30af\u30e9\u30a4\u30d0\u30fc\u6570\n        'message_rate' =&gt; 10000  \/\/ \u30e1\u30c3\u30bb\u30fc\u30b8\/\u79d2\n    ];\n\n    public function __construct(PubSubMetricsCollector $metricsCollector) {\n        $this-&gt;metricsCollector = $metricsCollector;\n    }\n\n    public function addNotificationHandler(callable $handler): void {\n        $this-&gt;notificationHandlers[] = $handler;\n    }\n\n    public function checkAlerts(): void {\n        $metrics = $this-&gt;metricsCollector-&gt;collectMetrics();\n\n        \/\/ \u30e1\u30e2\u30ea\u4f7f\u7528\u7387\u30c1\u30a7\u30c3\u30af\n        $memoryUsage = ($metrics['memory']['used_memory'] \/ $metrics['memory']['used_memory_peak']) * 100;\n        if ($memoryUsage &gt; $this-&gt;thresholds['memory_usage']) {\n            $this-&gt;notify('HIGH_MEMORY_USAGE', [\n                'current' =&gt; $memoryUsage,\n                'threshold' =&gt; $this-&gt;thresholds['memory_usage']\n            ]);\n        }\n\n        \/\/ \u305d\u306e\u4ed6\u306e\u30e1\u30c8\u30ea\u30af\u30b9\u30c1\u30a7\u30c3\u30af\n        foreach ($metrics['channels'] as $channel =&gt; $channelMetrics) {\n            if ($channelMetrics['subscribers'] &gt; $this-&gt;thresholds['subscriber_count']) {\n                $this-&gt;notify('HIGH_SUBSCRIBER_COUNT', [\n                    'channel' =&gt; $channel,\n                    'count' =&gt; $channelMetrics['subscribers']\n                ]);\n            }\n\n            if ($channelMetrics['messages_per_second'] &gt; $this-&gt;thresholds['message_rate']) {\n                $this-&gt;notify('HIGH_MESSAGE_RATE', [\n                    'channel' =&gt; $channel,\n                    'rate' =&gt; $channelMetrics['messages_per_second']\n                ]);\n            }\n        }\n    }\n\n    private function notify(string $alertType, array $data): void {\n        foreach ($this-&gt;notificationHandlers as $handler) {\n            $handler($alertType, $data);\n        }\n    }\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-47\">\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30e1\u30e2\u30ea\u7ba1\u7406<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9069\u5207\u306amaxmemory\u306e\u8a2d\u5b9a<\/li>\n\n\n\n<li>\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u306e\u5b9a\u671f\u7684\u306a\u30e2\u30cb\u30bf\u30ea\u30f3\u30b0<\/li>\n\n\n\n<li>\u672a\u4f7f\u7528\u30c1\u30e3\u30cd\u30eb\u306e\u30af\u30ea\u30fc\u30f3\u30a2\u30c3\u30d7<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30b9\u30b1\u30fc\u30ea\u30f3\u30b0\u6226\u7565<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6c34\u5e73\u30b9\u30b1\u30fc\u30ea\u30f3\u30b0\u306e\u5b9f\u88c5<\/li>\n\n\n\n<li>\u30b7\u30e3\u30fc\u30c7\u30a3\u30f3\u30b0\u306b\u3088\u308b\u8ca0\u8377\u5206\u6563<\/li>\n\n\n\n<li>\u30d0\u30c3\u30d5\u30a1\u30ea\u30f3\u30b0\u306b\u3088\u308b\u52b9\u7387\u5316<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u76e3\u8996\u4f53\u5236<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30e1\u30c8\u30ea\u30af\u30b9\u306e\u53ce\u96c6<\/li>\n\n\n\n<li>\u30a2\u30e9\u30fc\u30c8\u3057\u304d\u3044\u5024\u306e\u9069\u5207\u306a\u8a2d\u5b9a<\/li>\n\n\n\n<li>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6307\u6a19\u306e\u53ef\u8996\u5316<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0\u306e\u30dd\u30a4\u30f3\u30c8<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30c1\u30e3\u30cd\u30eb\u6570\u306e\u6700\u9069\u5316<\/li>\n\n\n\n<li>\u30e1\u30c3\u30bb\u30fc\u30b8\u30b5\u30a4\u30ba\u306e\u5236\u5fa1<\/li>\n\n\n\n<li>\u63a5\u7d9a\u30d7\u30fc\u30eb\u306e\u9069\u5207\u306a\u7ba1\u7406<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-48\">\u672c\u756a\u74b0\u5883\u3067\u306e\u904b\u7528\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-49\">\u4fe1\u983c\u6027\u3092\u78ba\u4fdd\u3059\u308b\u305f\u3081\u306e\u5197\u9577\u5316\u8a2d\u8a08<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-50\">1. Sentinel\u3092\u4f7f\u7528\u3057\u305f\u9ad8\u53ef\u7528\u6027\u306e\u5b9f\u73fe<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/\/ sentinel_connection.php\n\nclass SentinelConnection {\n    private $sentinels;\n    private $masterName;\n    private $currentMaster;\n    private $redis;\n\n    public function __construct(array $sentinels, string $masterName) {\n        $this-&gt;sentinels = $sentinels;\n        $this-&gt;masterName = $masterName;\n        $this-&gt;connectToMaster();\n    }\n\n    private function connectToMaster(): void {\n        foreach ($this-&gt;sentinels as $sentinel) {\n            try {\n                $sentinelClient = new Redis();\n                $sentinelClient-&gt;connect($sentinel['host'], $sentinel['port']);\n\n                \/\/ \u30de\u30b9\u30bf\u30fc\u306e\u60c5\u5831\u3092\u53d6\u5f97\n                $masterInfo = $sentinelClient-&gt;rawCommand(\n                    'SENTINEL', 'get-master-addr-by-name',\n                    $this-&gt;masterName\n                );\n\n                if ($masterInfo) {\n                    $this-&gt;redis = new Redis();\n                    $this-&gt;redis-&gt;connect($masterInfo[0], (int)$masterInfo[1]);\n                    $this-&gt;currentMaster = [\n                        'host' =&gt; $masterInfo[0],\n                        'port' =&gt; (int)$masterInfo[1]\n                    ];\n                    return;\n                }\n            } catch (Exception $e) {\n                error_log(\"Sentinel connection error: \" . $e-&gt;getMessage());\n                continue;\n            }\n        }\n        throw new Exception(\"Could not connect to Redis master\");\n    }\n\n    public function reconnectIfNeeded(): void {\n        try {\n            if (!$this-&gt;redis-&gt;ping()) {\n                $this-&gt;connectToMaster();\n            }\n        } catch (Exception $e) {\n            $this-&gt;connectToMaster();\n        }\n    }\n\n    public function getRedis(): Redis {\n        $this-&gt;reconnectIfNeeded();\n        return $this-&gt;redis;\n    }\n}\n\n\/\/ \u4f7f\u7528\u4f8b\n$sentinels = [\n    ['host' =&gt; '192.168.1.10', 'port' =&gt; 26379],\n    ['host' =&gt; '192.168.1.11', 'port' =&gt; 26379],\n    ['host' =&gt; '192.168.1.12', 'port' =&gt; 26379]\n];\n\n$connection = new SentinelConnection($sentinels, 'mymaster');\n$redis = $connection-&gt;getRedis();<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-51\">2. \u30af\u30e9\u30b9\u30bf\u69cb\u6210\u3067\u306e\u904b\u7528<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/\/ cluster_connection.php\n\nclass ClusterConnection {\n    private $nodes;\n    private $options;\n    private $cluster;\n\n    public function __construct(array $nodes, array $options = []) {\n        $this-&gt;nodes = $nodes;\n        $this-&gt;options = array_merge([\n            'timeout' =&gt; 1.0,\n            'read_timeout' =&gt; 1.0,\n            'persistent' =&gt; false\n        ], $options);\n\n        $this-&gt;connect();\n    }\n\n    private function connect(): void {\n        $this-&gt;cluster = new RedisCluster(\n            null,\n            array_map(function($node) {\n                return \"{$node['host']}:{$node['port']}\";\n            }, $this-&gt;nodes),\n            $this-&gt;options['timeout'],\n            $this-&gt;options['read_timeout'],\n            $this-&gt;options['persistent']\n        );\n    }\n\n    public function getCluster(): RedisCluster {\n        return $this-&gt;cluster;\n    }\n\n    public function publishToCluster(string $channel, string $message): int {\n        $totalReceivers = 0;\n\n        \/\/ \u5168\u30ce\u30fc\u30c9\u306b\u30d1\u30d6\u30ea\u30c3\u30b7\u30e5\n        foreach ($this-&gt;nodes as $node) {\n            try {\n                $redis = new Redis();\n                $redis-&gt;connect($node['host'], $node['port']);\n                $receivers = $redis-&gt;publish($channel, $message);\n                $totalReceivers += $receivers;\n                $redis-&gt;close();\n            } catch (Exception $e) {\n                error_log(\"Failed to publish to node {$node['host']}:{$node['port']}: \" . $e-&gt;getMessage());\n            }\n        }\n\n        return $totalReceivers;\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-52\">\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u5bfe\u7b56\u306e\u5b9f\u88c5\u65b9\u6cd5<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-53\">1. \u8a8d\u8a3c\u3068\u8a8d\u53ef\u306e\u5b9f\u88c5<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/\/ secure_pubsub.php\n\nclass SecurePubSub {\n    private $redis;\n    private $encryptionKey;\n\n    public function __construct(string $host, int $port, string $password, string $encryptionKey) {\n        $this-&gt;redis = new Redis();\n        $this-&gt;redis-&gt;connect($host, $port);\n\n        \/\/ Redis\u8a8d\u8a3c\n        if (!$this-&gt;redis-&gt;auth($password)) {\n            throw new Exception('Redis authentication failed');\n        }\n\n        $this-&gt;encryptionKey = $encryptionKey;\n    }\n\n    public function securePublish(string $channel, array $message): int {\n        \/\/ \u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u6697\u53f7\u5316\n        $encryptedMessage = $this-&gt;encryptMessage(json_encode($message));\n\n        \/\/ \u96fb\u5b50\u7f72\u540d\u306e\u4ed8\u52a0\n        $signature = $this-&gt;generateSignature($encryptedMessage);\n\n        $fullMessage = json_encode([\n            'data' =&gt; $encryptedMessage,\n            'signature' =&gt; $signature,\n            'timestamp' =&gt; time()\n        ]);\n\n        return $this-&gt;redis-&gt;publish($channel, $fullMessage);\n    }\n\n    public function secureSubscribe(string $channel, callable $callback): void {\n        $this-&gt;redis-&gt;subscribe([$channel], function($redis, $channel, $message) use ($callback) {\n            try {\n                $decoded = json_decode($message, true);\n\n                \/\/ \u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u691c\u8a3c\n                if (!$this-&gt;verifySignature($decoded['data'], $decoded['signature'])) {\n                    throw new Exception('Invalid message signature');\n                }\n\n                \/\/ \u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7\u306e\u691c\u8a3c\uff085\u5206\u4ee5\u4e0a\u53e4\u3044\u30e1\u30c3\u30bb\u30fc\u30b8\u306f\u62d2\u5426\uff09\n                if (time() - $decoded['timestamp'] &gt; 300) {\n                    throw new Exception('Message too old');\n                }\n\n                \/\/ \u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u5fa9\u53f7\u5316\n                $decryptedMessage = $this-&gt;decryptMessage($decoded['data']);\n                $callback($channel, json_decode($decryptedMessage, true));\n\n            } catch (Exception $e) {\n                error_log(\"Secure subscribe error: \" . $e-&gt;getMessage());\n            }\n        });\n    }\n\n    private function encryptMessage(string $message): string {\n        $iv = random_bytes(16);\n        $encrypted = openssl_encrypt(\n            $message,\n            'AES-256-CBC',\n            $this-&gt;encryptionKey,\n            OPENSSL_RAW_DATA,\n            $iv\n        );\n\n        return base64_encode($iv . $encrypted);\n    }\n\n    private function decryptMessage(string $encryptedMessage): string {\n        $decoded = base64_decode($encryptedMessage);\n        $iv = substr($decoded, 0, 16);\n        $encrypted = substr($decoded, 16);\n\n        return openssl_decrypt(\n            $encrypted,\n            'AES-256-CBC',\n            $this-&gt;encryptionKey,\n            OPENSSL_RAW_DATA,\n            $iv\n        );\n    }\n\n    private function generateSignature(string $message): string {\n        return hash_hmac('sha256', $message, $this-&gt;encryptionKey);\n    }\n\n    private function verifySignature(string $message, string $signature): bool {\n        return hash_equals(\n            $this-&gt;generateSignature($message),\n            $signature\n        );\n    }\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-54\">2. \u30a2\u30af\u30bb\u30b9\u5236\u5fa1\u306e\u5b9f\u88c5<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/\/ access_control.php\n\nclass PubSubAccessControl {\n    private $redis;\n    private $aclPrefix = 'pubsub:acl:';\n\n    public function __construct(Redis $redis) {\n        $this-&gt;redis = $redis;\n    }\n\n    public function grantAccess(string $userId, string $channel, array $permissions): void {\n        $aclKey = $this-&gt;aclPrefix . $channel;\n        $this-&gt;redis-&gt;hSet($aclKey, $userId, json_encode($permissions));\n    }\n\n    public function checkAccess(string $userId, string $channel, string $action): bool {\n        $aclKey = $this-&gt;aclPrefix . $channel;\n        $permissions = $this-&gt;redis-&gt;hGet($aclKey, $userId);\n\n        if (!$permissions) {\n            return false;\n        }\n\n        $perms = json_decode($permissions, true);\n        return in_array($action, $perms);\n    }\n\n    public function revokeAccess(string $userId, string $channel): void {\n        $aclKey = $this-&gt;aclPrefix . $channel;\n        $this-&gt;redis-&gt;hDel($aclKey, $userId);\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-55\">\u30c8\u30e9\u30d6\u30eb\u30b7\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0\u3068\u30c7\u30d0\u30c3\u30b0\u624b\u6cd5<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-56\">1. \u30ed\u30ae\u30f3\u30b0\u30b7\u30b9\u30c6\u30e0\u306e\u5b9f\u88c5<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/\/ pubsub_logger.php\n\nclass PubSubLogger {\n    private $redis;\n    private $logKey = 'pubsub:logs';\n    private $maxLogs = 1000;\n\n    public function __construct(Redis $redis) {\n        $this-&gt;redis = $redis;\n    }\n\n    public function logEvent(string $eventType, array $data): void {\n        $logEntry = [\n            'timestamp' =&gt; microtime(true),\n            'type' =&gt; $eventType,\n            'data' =&gt; $data\n        ];\n\n        \/\/ \u30ed\u30b0\u306e\u30c8\u30ea\u30df\u30f3\u30b0\uff08\u53e4\u3044\u30ed\u30b0\u3092\u524a\u9664\uff09\n        $this-&gt;redis-&gt;zAdd(\n            $this-&gt;logKey,\n            $logEntry['timestamp'],\n            json_encode($logEntry)\n        );\n\n        $this-&gt;redis-&gt;zRemRangeByRank(\n            $this-&gt;logKey,\n            0,\n            -($this-&gt;maxLogs + 1)\n        );\n    }\n\n    public function getLogs(int $limit = 100, ?float $startTime = null, ?float $endTime = null): array {\n        $options = [];\n\n        if ($startTime !== null) {\n            $options['min'] = $startTime;\n        }\n\n        if ($endTime !== null) {\n            $options['max'] = $endTime;\n        }\n\n        $options['limit'] = [0, $limit];\n\n        $logs = $this-&gt;redis-&gt;zRevRangeByScore(\n            $this-&gt;logKey,\n            $options['max'] ?? '+inf',\n            $options['min'] ?? '-inf',\n            ['limit' =&gt; [$options['limit'][0], $options['limit'][1]]]\n        );\n\n        return array_map(function($log) {\n            return json_decode($log, true);\n        }, $logs);\n    }\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-57\">2. \u30c7\u30d0\u30c3\u30b0\u30c4\u30fc\u30eb\u306e\u5b9f\u88c5<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/\/ pubsub_debugger.php\n\nclass PubSubDebugger {\n    private $redis;\n    private $logger;\n\n    public function __construct(Redis $redis, PubSubLogger $logger) {\n        $this-&gt;redis = $redis;\n        $this-&gt;logger = $logger;\n    }\n\n    public function startDebugging(string $channel): void {\n        $this-&gt;redis-&gt;subscribe([$channel], function($redis, $channel, $message) {\n            $this-&gt;debugMessage($channel, $message);\n        });\n    }\n\n    private function debugMessage(string $channel, string $message): void {\n        try {\n            $decoded = json_decode($message, true);\n\n            $debugInfo = [\n                'channel' =&gt; $channel,\n                'message_size' =&gt; strlen($message),\n                'is_json' =&gt; $decoded !== null,\n                'timestamp' =&gt; microtime(true),\n                'subscriber_count' =&gt; $this-&gt;getSubscriberCount($channel)\n            ];\n\n            if ($decoded) {\n                $debugInfo['message_structure'] = $this-&gt;analyzeStructure($decoded);\n            }\n\n            $this-&gt;logger-&gt;logEvent('debug', $debugInfo);\n\n        } catch (Exception $e) {\n            $this-&gt;logger-&gt;logEvent('error', [\n                'error' =&gt; $e-&gt;getMessage(),\n                'channel' =&gt; $channel,\n                'message' =&gt; $message\n            ]);\n        }\n    }\n\n    private function getSubscriberCount(string $channel): int {\n        $result = $this-&gt;redis-&gt;pubsub('numsub', $channel);\n        return (int)($result[1] ?? 0);\n    }\n\n    private function analyzeStructure(array $data, int $depth = 0): array {\n        if ($depth &gt; 5) {\n            return ['max_depth_reached' =&gt; true];\n        }\n\n        $structure = [];\n\n        foreach ($data as $key =&gt; $value) {\n            if (is_array($value)) {\n                $structure[$key] = $this-&gt;analyzeStructure($value, $depth + 1);\n            } else {\n                $structure[$key] = gettype($value);\n            }\n        }\n\n        return $structure;\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-58\">\u904b\u7528\u6642\u306e\u91cd\u8981\u30dd\u30a4\u30f3\u30c8<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u76e3\u8996\u3068\u30a2\u30e9\u30fc\u30c8<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30b7\u30b9\u30c6\u30e0\u30e1\u30c8\u30ea\u30af\u30b9\u306e\u7d99\u7d9a\u7684\u306a\u76e3\u8996<\/li>\n\n\n\n<li>\u7570\u5e38\u691c\u77e5\u306e\u81ea\u52d5\u5316<\/li>\n\n\n\n<li>\u30a4\u30f3\u30b7\u30c7\u30f3\u30c8\u5bfe\u5fdc\u30d5\u30ed\u30fc\u306e\u6574\u5099<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3068\u5fa9\u65e7<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5b9a\u671f\u7684\u306a\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u306e\u5b9f\u65bd<\/li>\n\n\n\n<li>\u5fa9\u65e7\u624b\u9806\u306e\u6587\u66f8\u5316<\/li>\n\n\n\n<li>\u969c\u5bb3\u8a13\u7df4\u306e\u5b9f\u65bd<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u7ba1\u7406<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30a2\u30af\u30bb\u30b9\u6a29\u9650\u306e\u5b9a\u671f\u7684\u306a\u898b\u76f4\u3057<\/li>\n\n\n\n<li>\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u30d1\u30c3\u30c1\u306e\u9069\u7528<\/li>\n\n\n\n<li>\u901a\u4fe1\u306e\u6697\u53f7\u5316<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u7ba1\u7406<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30ea\u30bd\u30fc\u30b9\u4f7f\u7528\u7387\u306e\u76e3\u8996<\/li>\n\n\n\n<li>\u30dc\u30c8\u30eb\u30cd\u30c3\u30af\u306e\u7279\u5b9a\u3068\u5bfe\u5fdc<\/li>\n\n\n\n<li>\u30ad\u30e3\u30d1\u30b7\u30c6\u30a3\u30d7\u30e9\u30f3\u30cb\u30f3\u30b0<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-59\">\u307e\u3068\u3081\uff1a\u52b9\u679c\u7684\u306aRedis Pub\/Sub\u6d3b\u7528\u306e\u30dd\u30a4\u30f3\u30c8<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-60\">\u5b9f\u8df5\u6642\u306e\u91cd\u8981\u306a\u610f\u601d\u6c7a\u5b9a\u30dd\u30a4\u30f3\u30c8<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-61\">1. \u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u9078\u5b9a\u306e\u5224\u65ad\u57fa\u6e96<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Redis Pub\/Sub\u306e\u63a1\u7528\u3092\u691c\u8a0e\u3059\u308b\u969b\u306e\u4e3b\u8981\u306a\u5224\u65ad\u30dd\u30a4\u30f3\u30c8\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u9069\u5207\u306a\u4f7f\u7528\u30b7\u30fc\u30f3<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u6027\u304c\u91cd\u8981\u306a\u5834\u9762<\/li>\n\n\n\n<li>\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u6c38\u7d9a\u5316\u304c\u4e0d\u8981\u306a\u5834\u9762<\/li>\n\n\n\n<li>\u8efd\u91cf\u306a\u901a\u4fe1\u304c\u5fc5\u8981\u306a\u5834\u9762<\/li>\n\n\n\n<li>\u30b9\u30b1\u30fc\u30e9\u30d3\u30ea\u30c6\u30a3\u304c\u91cd\u8981\u306a\u5834\u9762<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4e0d\u9069\u5207\u306a\u4f7f\u7528\u30b7\u30fc\u30f3<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u78ba\u5b9f\u306a\u30e1\u30c3\u30bb\u30fc\u30b8\u914d\u4fe1\u304c\u5fc5\u8981\u306a\u5834\u9762<\/li>\n\n\n\n<li>\u8907\u96d1\u306a\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u304c\u5fc5\u8981\u306a\u5834\u9762<\/li>\n\n\n\n<li>\u9577\u671f\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u4fdd\u5b58\u304c\u5fc5\u8981\u306a\u5834\u9762<\/li>\n\n\n\n<li>\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u51e6\u7406\u304c\u5fc5\u8981\u306a\u5834\u9762<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30b7\u30b9\u30c6\u30e0\u8981\u4ef6\u3068\u306e\u9069\u5408\u6027\u30c1\u30a7\u30c3\u30af\u30ea\u30b9\u30c8<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>[ ] \u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u914d\u4fe1\u4fdd\u8a3c\u30ec\u30d9\u30eb<\/li>\n\n\n\n<li>[ ] \u30b9\u30b1\u30fc\u30e9\u30d3\u30ea\u30c6\u30a3\u8981\u4ef6<\/li>\n\n\n\n<li>[ ] \u30ec\u30a4\u30c6\u30f3\u30b7\u8981\u4ef6<\/li>\n\n\n\n<li>[ ] \u904b\u7528\u30b3\u30b9\u30c8\u8981\u4ef6<\/li>\n\n\n\n<li>[ ] \u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u8981\u4ef6<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-62\">2. \u5b9f\u88c5\u65b9\u5f0f\u306e\u9078\u629e<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u30b7\u30b9\u30c6\u30e0\u898f\u6a21\u3084\u8981\u4ef6\u306b\u5fdc\u3058\u305f\u5b9f\u88c5\u65b9\u5f0f\u306e\u9078\u629e\u30ac\u30a4\u30c9\uff1a<\/p>\n\n\n<div id=\"id-2b773b36-16bc-49c6-8f64-2fa18016fd13\">\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u898f\u6a21\/\u8981\u4ef6<\/th><th>\u63a8\u5968\u5b9f\u88c5\u65b9\u5f0f<\/th><th>\u4e3b\u306a\u5229\u70b9<\/th><th>\u8003\u616e\u70b9<\/th><\/tr><\/thead><tbody><tr><td>\u5c0f\u898f\u6a21\u30b7\u30b9\u30c6\u30e0<\/td><td>\u30b7\u30f3\u30d7\u30eb\u306a\u5358\u4e00\u69cb\u6210<\/td><td>\u5c0e\u5165\u304c\u5bb9\u6613\u3001\u904b\u7528\u30b3\u30b9\u30c8\u304c\u4f4e\u3044<\/td><td>\u30b9\u30b1\u30fc\u30e9\u30d3\u30ea\u30c6\u30a3\u306b\u5236\u9650<\/td><\/tr><tr><td>\u4e2d\u898f\u6a21\u30b7\u30b9\u30c6\u30e0<\/td><td>Sentinel\u306b\u3088\u308b\u5197\u9577\u5316<\/td><td>\u9ad8\u53ef\u7528\u6027\u3001\u904b\u7528\u306e\u81ea\u52d5\u5316<\/td><td>\u69cb\u6210\u306e\u8907\u96d1\u5316<\/td><\/tr><tr><td>\u5927\u898f\u6a21\u30b7\u30b9\u30c6\u30e0<\/td><td>\u30af\u30e9\u30b9\u30bf\u69cb\u6210<\/td><td>\u9ad8\u3044\u30b9\u30b1\u30fc\u30e9\u30d3\u30ea\u30c6\u30a3<\/td><td>\u904b\u7528\u30b3\u30b9\u30c8\u306e\u5897\u52a0<\/td><\/tr><\/tbody><\/table><\/figure>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"i-63\">\u3088\u304f\u3042\u308b\u5931\u6557\u30d1\u30bf\u30fc\u30f3\u3068\u5bfe\u7b56<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-64\">1. \u30b7\u30b9\u30c6\u30e0\u8a2d\u8a08\u6642\u306e\u5931\u6557<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30e1\u30c3\u30bb\u30fc\u30b8\u6c38\u7d9a\u5316\u306e\u8aa4\u3063\u305f\u671f\u5f85<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   \/\/ \u8aa4\u3063\u305f\u5b9f\u88c5\u4f8b\n   class MessageStore {\n       private $redis;\n\n       public function storeMessage($message) {\n           \/\/ \u6c38\u7d9a\u5316\u3092\u671f\u5f85\u3057\u305f\u5b9f\u88c5\uff08\u8aa4\u308a\uff09\n           $this-&gt;redis-&gt;publish('channel', $message);\n           \/\/ \u30e1\u30c3\u30bb\u30fc\u30b8\u306f\u914d\u4fe1\u5f8c\u306b\u6d88\u5931\u3057\u307e\u3059\n       }\n   }\n\n   \/\/ \u6b63\u3057\u3044\u5b9f\u88c5\u4f8b\n   class MessageStore {\n       private $redis;\n\n       public function storeMessage($message) {\n           \/\/ \u6c38\u7d9a\u5316\u304c\u5fc5\u8981\u306a\u5834\u5408\u306f\u5225\u9014\u4fdd\u5b58\n           $messageId = uniqid();\n           $this-&gt;redis-&gt;set(\"message:{$messageId}\", $message);\n           $this-&gt;redis-&gt;publish('channel', $messageId);\n       }\n   }<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>\u63a5\u7d9a\u7ba1\u7406\u306e\u4e0d\u5099<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   \/\/ \u8aa4\u3063\u305f\u5b9f\u88c5\u4f8b\n   class PoorSubscriber {\n       public function subscribe($channel) {\n           $redis = new Redis();\n           $redis-&gt;connect('localhost', 6379);\n           \/\/ \u63a5\u7d9a\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u306a\u3057\n           $redis-&gt;subscribe([$channel], function($msg) {});\n       }\n   }\n\n   \/\/ \u6b63\u3057\u3044\u5b9f\u88c5\u4f8b\n   class RobustSubscriber {\n       private $redis;\n       private $retryAttempts = 3;\n\n       public function subscribe($channel) {\n           for ($i = 0; $i &lt; $this-&gt;retryAttempts; $i++) {\n               try {\n                   $this-&gt;redis = new Redis();\n                   $this-&gt;redis-&gt;connect('localhost', 6379);\n                   $this-&gt;redis-&gt;subscribe([$channel], function($msg) {});\n                   break;\n               } catch (Exception $e) {\n                   if ($i === $this-&gt;retryAttempts - 1) {\n                       throw $e;\n                   }\n                   sleep(1);\n               }\n           }\n       }\n   }<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-65\">2. \u904b\u7528\u6642\u306e\u5931\u6557<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30e1\u30e2\u30ea\u7ba1\u7406\u306e\u4e0d\u5099<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   \/\/ \u30e1\u30e2\u30ea\u76e3\u8996\u306e\u5b9f\u88c5\u4f8b\n   class MemoryMonitor {\n       private $redis;\n       private $warningThreshold = 80; \/\/ %\n\n       public function checkMemoryUsage() {\n           $info = $this-&gt;redis-&gt;info('memory');\n           $usedPercent = ($info['used_memory'] \/ $info['maxmemory']) * 100;\n\n           if ($usedPercent &gt; $this-&gt;warningThreshold) {\n               $this-&gt;sendAlert(\"Memory usage critical: {$usedPercent}%\");\n               $this-&gt;cleanupUnusedChannels();\n           }\n       }\n   }<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u306e\u4e0d\u8db3<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   \/\/ \u5305\u62ec\u7684\u306a\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u306e\u5b9f\u88c5\u4f8b\n   class ErrorHandler {\n       private $logger;\n\n       public function handlePubSubError($error, $context) {\n           $this-&gt;logger-&gt;error(\"PubSub Error: {$error-&gt;getMessage()}\", [\n               'context' =&gt; $context,\n               'stack_trace' =&gt; $error-&gt;getTraceAsString()\n           ]);\n\n           if ($this-&gt;isRecoverable($error)) {\n               $this-&gt;attemptRecovery($context);\n           } else {\n               $this-&gt;notifyAdmin($error);\n           }\n       }\n   }<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-66\">\u4eca\u5f8c\u306e\u5b66\u7fd2\u30ea\u30bd\u30fc\u30b9\u3068\u30b3\u30df\u30e5\u30cb\u30c6\u30a3\u60c5\u5831<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-67\">1. \u63a8\u5968\u5b66\u7fd2\u30ea\u30bd\u30fc\u30b9<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Redis\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8: https:\/\/redis.io\/docs<\/li>\n\n\n\n<li>PHPRedis\u62e1\u5f35\u30e2\u30b8\u30e5\u30fc\u30eb: https:\/\/github.com\/phpredis\/phpredis<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u66f8\u7c4d\u3068\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Redis\u958b\u767a\u30ac\u30a4\u30c9<\/li>\n\n\n\n<li>PHP\u306b\u3088\u308b\u30b9\u30b1\u30fc\u30e9\u30d6\u30eb\u306aWeb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u958b\u767a<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30aa\u30f3\u30e9\u30a4\u30f3\u30ea\u30bd\u30fc\u30b9<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Redis\u30e6\u30fc\u30b6\u30fc\u30b0\u30eb\u30fc\u30d7<\/li>\n\n\n\n<li>Stack Overflow: Redis\u95a2\u9023\u30bf\u30b0<\/li>\n\n\n\n<li>GitHub: Redis\u95a2\u9023\u30d7\u30ed\u30b8\u30a7\u30af\u30c8<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-68\">2. \u30b3\u30df\u30e5\u30cb\u30c6\u30a3\u3068\u60c5\u5831\u4ea4\u63db<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30b3\u30df\u30e5\u30cb\u30c6\u30a3\u53c2\u52a0<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Redis Meetup<\/li>\n\n\n\n<li>PHP\u30ab\u30f3\u30d5\u30a1\u30ec\u30f3\u30b9<\/li>\n\n\n\n<li>\u30c6\u30c3\u30af\u30d6\u30ed\u30b0\u57f7\u7b46<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u6700\u65b0\u60c5\u5831\u306e\u30ad\u30e3\u30c3\u30c1\u30a2\u30c3\u30d7<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Redis Release Notes<\/li>\n\n\n\n<li>\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u30a2\u30c9\u30d0\u30a4\u30b6\u30ea<\/li>\n\n\n\n<li>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6539\u5584\u4e8b\u4f8b<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-69\">\u6700\u7d42\u30c1\u30a7\u30c3\u30af\u30ea\u30b9\u30c8<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b9f\u904b\u7528\u524d\u306e\u78ba\u8a8d\u9805\u76ee\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u57fa\u672c\u8a2d\u8a08<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>[ ] \u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u3068\u306e\u9069\u5408\u6027\u78ba\u8a8d<\/li>\n\n\n\n<li>[ ] \u30b9\u30b1\u30fc\u30e9\u30d3\u30ea\u30c6\u30a3\u8981\u4ef6\u306e\u78ba\u8a8d<\/li>\n\n\n\n<li>[ ] \u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u8981\u4ef6\u306e\u78ba\u8a8d<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5b9f\u88c5<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>[ ] \u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u306e\u5b9f\u88c5<\/li>\n\n\n\n<li>[ ] \u76e3\u8996\u306e\u5b9f\u88c5<\/li>\n\n\n\n<li>[ ] \u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u5bfe\u7b56\u306e\u5b9f\u88c5<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u904b\u7528\u6e96\u5099<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>[ ] \u904b\u7528\u624b\u9806\u306e\u6574\u5099<\/li>\n\n\n\n<li>[ ] \u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u4f53\u5236\u306e\u78ba\u7acb<\/li>\n\n\n\n<li>[ ] \u30a4\u30f3\u30b7\u30c7\u30f3\u30c8\u5bfe\u5fdc\u30d5\u30ed\u30fc\u306e\u6574\u5099<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u308c\u3089\u306e\u5b9f\u8df5\u7684\u77e5\u8b58\u3068\u6ce8\u610f\u70b9\u3092\u8e0f\u307e\u3048\u308b\u3053\u3068\u3067\u3001Redis Pub\/Sub\u3092\u52b9\u679c\u7684\u306b\u6d3b\u7528\u3057\u305f\u30b7\u30b9\u30c6\u30e0\u69cb\u7bc9\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Warning: Undefined array key &#8220;is_admin&#8221; in \/home\/xs392991\/dexall.co.jp\/public_html\/articles\/wp-content\/themes\/ &#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-3325","post","type-post","status-publish","format-standard","category-php","nothumb"],"_links":{"self":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts\/3325","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3325"}],"version-history":[{"count":2,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts\/3325\/revisions"}],"predecessor-version":[{"id":3327,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts\/3325\/revisions\/3327"}],"wp:attachment":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3325"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}