{"id":3334,"date":"2025-03-24T08:46:25","date_gmt":"2025-03-23T23:46:25","guid":{"rendered":"https:\/\/dexall.co.jp\/articles\/?p=3334"},"modified":"2025-03-24T08:46:56","modified_gmt":"2025-03-23T23:46:56","slug":"%e3%80%90php%e3%82%a8%e3%83%b3%e3%82%b8%e3%83%8b%e3%82%a2%e5%90%91%e3%81%91%e3%80%91redis%e3%81%aeset%e3%82%b3%e3%83%9e%e3%83%b3%e3%83%89%e3%82%92%e5%ae%8c%e5%85%a8%e7%90%86%e8%a7%a3%ef%bc%81%e5%ae%9f","status":"publish","type":"post","link":"https:\/\/dexall.co.jp\/articles\/?p=3334","title":{"rendered":"\u3010PHP\u30a8\u30f3\u30b8\u30cb\u30a2\u5411\u3051\u3011Redis\u306eset\u30b3\u30de\u30f3\u30c9\u3092\u5b8c\u5168\u7406\u89e3\uff01\u5b9f\u88c5\u4f8b\u3068\u904b\u7528\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9"},"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\u306eset\u30b3\u30de\u30f3\u30c9\u3068\u306f<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-1\">\u30ad\u30fc\u3068\u5024\u306e\u30da\u30a2\u3092\u4fdd\u5b58\u3059\u308b\u57fa\u672c\u7684\u306a\u30c7\u30fc\u30bf\u69cb\u9020<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-2\">\u4ed6\u306eRedis\u30c7\u30fc\u30bf\u578b\u3068\u306e\u9055\u3044\u3068\u7279\u5fb4<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-3\">PHP\u3067\u306eRedis set\u30b3\u30de\u30f3\u30c9\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-4\">PHP-Redis\u30a8\u30af\u30b9\u30c6\u30f3\u30b7\u30e7\u30f3\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3068\u8a2d\u5b9a<\/a>      <\/li>      <li>        <a href=\"#i-5\">\u57fa\u672c\u7684\u306aset\/get\u30aa\u30da\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u5b9f\u88c5\u4f8b<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-6\">\u6709\u52b9\u671f\u9650\uff08TTL\uff09\u306e\u8a2d\u5b9a\u65b9\u6cd5<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-7\">\u5b9f\u8df5\u7684\u306aRedis set\u306e\u6d3b\u7528\u30d1\u30bf\u30fc\u30f3<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-8\">\u30bb\u30c3\u30b7\u30e7\u30f3\u7ba1\u7406\u3067\u306e\u5229\u7528\u65b9\u6cd5<\/a>      <\/li>      <li>        <a href=\"#i-9\">\u30ad\u30e3\u30c3\u30b7\u30e5\u30b7\u30b9\u30c6\u30e0\u3068\u3057\u3066\u306e\u5b9f\u88c5\u4f8b<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-10\">\u5206\u6563\u30ed\u30c3\u30af\u306e\u5b9f\u73fe\u65b9\u6cd5<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-11\">Redis set\u30b3\u30de\u30f3\u30c9\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-12\">\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u306e\u6700\u9069\u5316\u624b\u6cd5<\/a>      <\/li>      <li>        <a href=\"#i-13\">\u5927\u91cf\u30c7\u30fc\u30bf\u51e6\u7406\u6642\u306e\u6ce8\u610f\u70b9<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-14\">\u30e2\u30cb\u30bf\u30ea\u30f3\u30b0\u3068\u76e3\u8996\u306e\u5b9f\u73fe<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-15\">\u904b\u7528\u74b0\u5883\u3067\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-16\">\u30ad\u30fc\u8a2d\u8a08\u306e\u30ac\u30a4\u30c9\u30e9\u30a4\u30f3<\/a>      <\/li>      <li>        <a href=\"#i-17\">\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3068\u5fa9\u65e7\u6226\u7565<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-18\">\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u5bfe\u7b56\u306e\u5b9f\u73fe<\/a>      <\/li>    <\/ul>  <\/li>  <li class=\"last\">    <a href=\"#i-19\">\u3088\u304f\u3042\u308b\u30c8\u30e9\u30d6\u30eb\u3068\u305d\u306e\u89e3\u6c7a\u65b9\u6cd5<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-20\">\u30e1\u30e2\u30ea\u306e\u554f\u984c\u3068\u5bfe\u51e6\u6cd5<\/a>      <\/li>      <li>        <a href=\"#i-21\">\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u4f4e\u4e0b\u6642\u306e\u8a3a\u65ad\u3068\u6539\u5584<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-22\">\u8907\u6570\u30b5\u30fc\u30d0\u30fc\u74b0\u5883\u3067\u306e\u6574\u5408\u6027\u78ba\u4fdd\u95a2\u9023<\/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\u306eset\u30b3\u30de\u30f3\u30c9\u3068\u306f<\/h2>\n\n\n\n<p>Redis\u306f\u9ad8\u6027\u80fd\u306a\u30a4\u30f3\u30e1\u30e2\u30ea\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u3057\u3066\u5e83\u304f\u5229\u7528\u3055\u308c\u3066\u304a\u308a\u3001\u305d\u306e\u4e2d\u3067\u3082set\u30b3\u30de\u30f3\u30c9\u306f\u6700\u3082\u57fa\u672c\u7684\u304b\u3064\u91cd\u8981\u306a\u30b3\u30de\u30f3\u30c9\u306e1\u3064\u3067\u3059\u3002\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001set\u30b3\u30de\u30f3\u30c9\u306e\u57fa\u672c\u7684\u306a\u6982\u5ff5\u3068\u7279\u5fb4\u306b\u3064\u3044\u3066\u8a73\u3057\u304f\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-1\">\u30ad\u30fc\u3068\u5024\u306e\u30da\u30a2\u3092\u4fdd\u5b58\u3059\u308b\u57fa\u672c\u7684\u306a\u30c7\u30fc\u30bf\u69cb\u9020<\/h3>\n\n\n\n<p>Redis\u306eset\u30b3\u30de\u30f3\u30c9\u306f\u3001\u30ad\u30fc\u3068\u5024\u306e\u30da\u30a2\u3092\u30e1\u30e2\u30ea\u4e0a\u306b\u4fdd\u5b58\u3059\u308b\u305f\u3081\u306e\u6700\u3082\u57fa\u672c\u7684\u306a\u64cd\u4f5c\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u7279\u5fb4\u304c\u3042\u308a\u307e\u3059\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30b7\u30f3\u30d7\u30eb\u306a\u69cb\u9020<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30ad\u30fc\uff1a\u4e00\u610f\u306e\u8b58\u5225\u5b50\u3068\u3057\u3066\u6a5f\u80fd<\/li>\n\n\n\n<li>\u5024\uff1a\u4efb\u610f\u306e\u30d0\u30a4\u30ca\u30ea\u30c7\u30fc\u30bf\uff08\u6587\u5b57\u5217\u3001\u6570\u5024\u3001\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u3055\u308c\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306a\u3069\uff09<\/li>\n\n\n\n<li>\u6700\u5927\u5024\u30b5\u30a4\u30ba\uff1a512MB\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\u8a2d\u5b9a\uff09<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u4e3b\u8981\u306a\u30aa\u30d7\u30b7\u30e7\u30f3<\/strong><\/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=\"\">   SET key value [EX seconds] [PX milliseconds] [NX|XX]<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>EX seconds<\/code>: \u6709\u52b9\u671f\u9650\u3092\u79d2\u5358\u4f4d\u3067\u8a2d\u5b9a<\/li>\n\n\n\n<li><code>PX milliseconds<\/code>: \u6709\u52b9\u671f\u9650\u3092\u30df\u30ea\u79d2\u5358\u4f4d\u3067\u8a2d\u5b9a<\/li>\n\n\n\n<li><code>NX<\/code>: \u30ad\u30fc\u304c\u5b58\u5728\u3057\u306a\u3044\u5834\u5408\u306e\u307f\u8a2d\u5b9a<\/li>\n\n\n\n<li><code>XX<\/code>: \u30ad\u30fc\u304c\u65e2\u306b\u5b58\u5728\u3059\u308b\u5834\u5408\u306e\u307f\u8a2d\u5b9a<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30a2\u30c8\u30df\u30c3\u30af\u6027\u306e\u4fdd\u8a3c<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>set\u30b3\u30de\u30f3\u30c9\u306f\u5358\u4e00\u306e\u30a2\u30c8\u30df\u30c3\u30af\u306a\u64cd\u4f5c\u3068\u3057\u3066\u5b9f\u884c<\/li>\n\n\n\n<li>\u8907\u6570\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304b\u3089\u306e\u30a2\u30af\u30bb\u30b9\u3067\u3082\u4e00\u8cab\u6027\u3092\u4fdd\u6301<\/li>\n\n\n\n<li>\u90e8\u5206\u7684\u306a\u66f4\u65b0\u304c\u767a\u751f\u3057\u306a\u3044<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-2\">\u4ed6\u306eRedis\u30c7\u30fc\u30bf\u578b\u3068\u306e\u9055\u3044\u3068\u7279\u5fb4<\/h3>\n\n\n\n<p>Redis\u306b\u306f\u69d8\u3005\u306a\u30c7\u30fc\u30bf\u578b\u304c\u5b58\u5728\u3057\u307e\u3059\u304c\u3001set\u30b3\u30de\u30f3\u30c9\u3067\u4f7f\u7528\u3055\u308c\u308b\u6587\u5b57\u5217\u578b\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u7279\u5fb4\u304c\u3042\u308a\u307e\u3059\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u4ed6\u306e\u30c7\u30fc\u30bf\u578b\u3068\u306e\u6bd4\u8f03<\/strong><\/li>\n<\/ol>\n\n\n<div id=\"id-8de2645c-57ee-4677-a30d-1ad1822b9a56\">\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u30c7\u30fc\u30bf\u578b<\/th><th>\u4e3b\u306a\u7528\u9014<\/th><th>\u7279\u5fb4<\/th><\/tr><\/thead><tbody><tr><td>String (SET)<\/td><td>\u5358\u4e00\u306e\u5024\u306e\u4fdd\u5b58<\/td><td>\u6700\u3082\u30b7\u30f3\u30d7\u30eb\u3067\u9ad8\u901f<\/td><\/tr><tr><td>Hash<\/td><td>\u8907\u6570\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u6301\u3064\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/td><td>\u3088\u308a\u69cb\u9020\u5316\u3055\u308c\u305f\u30c7\u30fc\u30bf\u306b\u9069\u3059\u308b<\/td><\/tr><tr><td>List<\/td><td>\u9806\u5e8f\u4ed8\u304d\u30b3\u30ec\u30af\u30b7\u30e7\u30f3<\/td><td>\u30ad\u30e5\u30fc\u3001\u30b9\u30bf\u30c3\u30af\u306e\u5b9f\u88c5\u306b\u9069\u3059\u308b<\/td><\/tr><tr><td>Set<\/td><td>\u91cd\u8907\u306e\u306a\u3044\u96c6\u5408<\/td><td>\u30e1\u30f3\u30d0\u30fc\u30b7\u30c3\u30d7\u30c6\u30b9\u30c8\u306b\u52b9\u7387\u7684<\/td><\/tr><tr><td>Sorted Set<\/td><td>\u30b9\u30b3\u30a2\u4ed8\u304d\u306e\u9806\u5e8f\u4ed8\u304d\u96c6\u5408<\/td><td>\u30e9\u30f3\u30ad\u30f3\u30b0\u306a\u3069\u306b\u9069\u3059\u308b<\/td><\/tr><\/tbody><\/table><\/figure>\n<\/div>\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u6587\u5b57\u5217\u578b\u306e\u5229\u70b9<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6700\u5c0f\u306e\u30e1\u30e2\u30ea\u30aa\u30fc\u30d0\u30fc\u30d8\u30c3\u30c9<\/li>\n\n\n\n<li>\u6700\u901f\u306e\u30a2\u30af\u30bb\u30b9\u901f\u5ea6<\/li>\n\n\n\n<li>\u30b7\u30f3\u30d7\u30eb\u306a\u64cd\u4f5c\u30bb\u30c3\u30c8<\/li>\n\n\n\n<li>\u76f4\u611f\u7684\u306a\u4f7f\u7528\u65b9\u6cd5<\/li>\n<\/ul>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u5225\u306e\u9069\u6027<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30ad\u30e3\u30c3\u30b7\u30e5: \u2705 \u9ad8\u901f\u306a\u30a2\u30af\u30bb\u30b9\u3068\u6709\u52b9\u671f\u9650\u8a2d\u5b9a<\/li>\n\n\n\n<li>\u30bb\u30c3\u30b7\u30e7\u30f3\u7ba1\u7406: \u2705 \u30b7\u30f3\u30d7\u30eb\u306a\u69cb\u9020\u3068\u6709\u52b9\u671f\u9650\u7ba1\u7406<\/li>\n\n\n\n<li>\u8a2d\u5b9a\u5024\u306e\u4fdd\u5b58: \u2705 \u30a2\u30c8\u30df\u30c3\u30af\u306a\u66f4\u65b0\u64cd\u4f5c<\/li>\n\n\n\n<li>\u30ab\u30a6\u30f3\u30bf\u30fc: \u2705 INCR\/DECR\u30b3\u30de\u30f3\u30c9\u3068\u306e\u7d44\u307f\u5408\u308f\u305b<\/li>\n\n\n\n<li>\u30d1\u30d6\u30ea\u30c3\u30b7\u30e5\/\u30b5\u30d6\u30b9\u30af\u30e9\u30a4\u30d6: \u274c PUB\/SUB\u306b\u7279\u5316\u3057\u305f\u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u7528<\/li>\n\n\n\n<li>\u8907\u96d1\u306a\u30c7\u30fc\u30bf\u69cb\u9020: \u274c \u4ed6\u306e\u30c7\u30fc\u30bf\u578b\u304c\u3088\u308a\u9069\u5207<\/li>\n<\/ul>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u7279\u6027<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6642\u9593\u8907\u96d1\u5ea6: O(1)<\/li>\n\n\n\n<li>\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf: \u30ad\u30fc\u306e\u30b5\u30a4\u30ba + \u5024\u306e\u30b5\u30a4\u30ba + \u7ba1\u7406\u7528\u30aa\u30fc\u30d0\u30fc\u30d8\u30c3\u30c9<\/li>\n\n\n\n<li>\u540c\u6642\u5b9f\u884c\u6027: \u9ad8\uff08\u30a2\u30c8\u30df\u30c3\u30af\u64cd\u4f5c\u3068\u3057\u3066\u5b9f\u884c\uff09<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u306e\u3088\u3046\u306b\u3001Redis\u306eset\u30b3\u30de\u30f3\u30c9\u306f\u3001\u30b7\u30f3\u30d7\u30eb\u306a\u304c\u3089\u3082\u5f37\u529b\u306a\u6a5f\u80fd\u3092\u63d0\u4f9b\u3057\u3001\u591a\u304f\u306e\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u3067\u52b9\u7387\u7684\u306b\u6d3b\u7528\u3067\u304d\u307e\u3059\u3002\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001\u3053\u308c\u3089\u306e\u6982\u5ff5\u3092\u5b9f\u969b\u306ePHP\u30b3\u30fc\u30c9\u3068\u3057\u3066\u5b9f\u88c5\u3059\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-3\">PHP\u3067\u306eRedis set\u30b3\u30de\u30f3\u30c9\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9<\/h2>\n\n\n\n<p>PHP\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067Redis\u3092\u52b9\u679c\u7684\u306b\u6d3b\u7528\u3059\u308b\u305f\u3081\u306e\u57fa\u672c\u7684\u306a\u5b9f\u88c5\u65b9\u6cd5\u306b\u3064\u3044\u3066\u3001\u9806\u3092\u8ffd\u3063\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-4\">PHP-Redis\u30a8\u30af\u30b9\u30c6\u30f3\u30b7\u30e7\u30f3\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3068\u8a2d\u5b9a<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u65b9\u6cd5<\/strong><\/li>\n<\/ol>\n\n\n\n<p>Ubuntu\/Debian\u306e\u5834\u5408:<\/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=\"\"># Redis\u30b5\u30fc\u30d0\u30fc\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\nsudo apt-get update\nsudo apt-get install redis-server\n\n# PHP-Redis\u30a8\u30af\u30b9\u30c6\u30f3\u30b7\u30e7\u30f3\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\nsudo apt-get install php-redis<\/pre>\n\n\n\n<p>Composer\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408:<\/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=\"\">composer require predis\/predis<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u57fa\u672c\u7684\u306a\u63a5\u7d9a\u8a2d\u5b9a<\/strong><\/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=\"\">\/\/ Redis\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306e\u521d\u671f\u5316\ntry {\n    $redis = new Redis();\n    $redis-&gt;connect('127.0.0.1', 6379);\n\n    \/\/ \u8a8d\u8a3c\u304c\u5fc5\u8981\u306a\u5834\u5408\n    $redis-&gt;auth('your_password');\n\n    \/\/ \u63a5\u7d9a\u30c6\u30b9\u30c8\n    if ($redis-&gt;ping()) {\n        echo \"Redis\u63a5\u7d9a\u6210\u529f\\n\";\n    }\n} catch (RedisException $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-5\">\u57fa\u672c\u7684\u306aset\/get\u30aa\u30da\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u5b9f\u88c5\u4f8b<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30b7\u30f3\u30d7\u30eb\u306a\u30ad\u30fc\/\u5024\u306e\u64cd\u4f5c<\/strong><\/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 RedisManager {\n    private $redis;\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    \/**\n     * \u5024\u3092\u4fdd\u5b58\u3059\u308b\n     * @param string $key \u30ad\u30fc\n     * @param mixed $value \u5024\n     * @return bool \u6210\u529f\/\u5931\u6557\n     *\/\n    public function setValue($key, $value) {\n        try {\n            \/\/ \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3084\u914d\u5217\u306e\u5834\u5408\u306f\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\n            if (is_array($value) || is_object($value)) {\n                $value = serialize($value);\n            }\n            return $this-&gt;redis-&gt;set($key, $value);\n        } catch (RedisException $e) {\n            error_log(\"Redis set error: \" . $e-&gt;getMessage());\n            return false;\n        }\n    }\n\n    \/**\n     * \u5024\u3092\u53d6\u5f97\u3059\u308b\n     * @param string $key \u30ad\u30fc\n     * @return mixed \u53d6\u5f97\u3057\u305f\u5024\n     *\/\n    public function getValue($key) {\n        try {\n            $value = $this-&gt;redis-&gt;get($key);\n            \/\/ \u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u3055\u308c\u305f\u30c7\u30fc\u30bf\u306e\u81ea\u52d5\u5fa9\u5143\n            if ($value &amp;&amp; @unserialize($value) !== false) {\n                return unserialize($value);\n            }\n            return $value;\n        } catch (RedisException $e) {\n            error_log(\"Redis get error: \" . $e-&gt;getMessage());\n            return null;\n        }\n    }\n}\n\n\/\/ \u4f7f\u7528\u4f8b\n$redisManager = new RedisManager();\n\n\/\/ \u6587\u5b57\u5217\u306e\u4fdd\u5b58\n$redisManager-&gt;setValue('user:name', 'John Doe');\n\n\/\/ \u914d\u5217\u306e\u4fdd\u5b58\n$userData = [\n    'name' =&gt; 'John Doe',\n    'age' =&gt; 30,\n    'email' =&gt; 'john@example.com'\n];\n$redisManager-&gt;setValue('user:1:data', $userData);<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-6\">\u6709\u52b9\u671f\u9650\uff08TTL\uff09\u306e\u8a2d\u5b9a\u65b9\u6cd5<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u57fa\u672c\u7684\u306aTTL\u8a2d\u5b9a<\/strong><\/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 RedisExpireManager extends RedisManager {\n    \/**\n     * \u6709\u52b9\u671f\u9650\u4ed8\u304d\u3067\u5024\u3092\u4fdd\u5b58\n     * @param string $key \u30ad\u30fc\n     * @param mixed $value \u5024\n     * @param int $ttl \u6709\u52b9\u671f\u9650\uff08\u79d2\uff09\n     * @return bool \u6210\u529f\/\u5931\u6557\n     *\/\n    public function setWithExpiry($key, $value, $ttl) {\n        try {\n            if (is_array($value) || is_object($value)) {\n                $value = serialize($value);\n            }\n            return $this-&gt;redis-&gt;setex($key, $ttl, $value);\n        } catch (RedisException $e) {\n            error_log(\"Redis setex error: \" . $e-&gt;getMessage());\n            return false;\n        }\n    }\n\n    \/**\n     * \u65e2\u5b58\u30ad\u30fc\u306e\u6709\u52b9\u671f\u9650\u3092\u66f4\u65b0\n     * @param string $key \u30ad\u30fc\n     * @param int $ttl \u65b0\u3057\u3044\u6709\u52b9\u671f\u9650\uff08\u79d2\uff09\n     * @return bool \u6210\u529f\/\u5931\u6557\n     *\/\n    public function updateExpiry($key, $ttl) {\n        try {\n            return $this-&gt;redis-&gt;expire($key, $ttl);\n        } catch (RedisException $e) {\n            error_log(\"Redis expire error: \" . $e-&gt;getMessage());\n            return false;\n        }\n    }\n\n    \/**\n     * \u30ad\u30fc\u306e\u6b8b\u308a\u6709\u52b9\u671f\u9650\u3092\u53d6\u5f97\n     * @param string $key \u30ad\u30fc\n     * @return int|false \u6b8b\u308a\u6642\u9593\uff08\u79d2\uff09\u307e\u305f\u306f\u5931\u6557\u6642\u306ffalse\n     *\/\n    public function getTimeToLive($key) {\n        try {\n            return $this-&gt;redis-&gt;ttl($key);\n        } catch (RedisException $e) {\n            error_log(\"Redis ttl error: \" . $e-&gt;getMessage());\n            return false;\n        }\n    }\n}\n\n\/\/ \u4f7f\u7528\u4f8b\n$redisExpire = new RedisExpireManager();\n\n\/\/ 60\u79d2\u306e\u6709\u52b9\u671f\u9650\u4ed8\u304d\u3067\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58\n$redisExpire-&gt;setWithExpiry('session:user:1', 'active', 60);\n\n\/\/ \u6709\u52b9\u671f\u9650\u306e\u78ba\u8a8d\n$ttl = $redisExpire-&gt;getTimeToLive('session:user:1');\necho \"\u6b8b\u308a\u6709\u52b9\u671f\u9650: {$ttl}\u79d2\\n\";\n\n\/\/ \u6709\u52b9\u671f\u9650\u306e\u66f4\u65b0\n$redisExpire-&gt;updateExpiry('session:user:1', 120);<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u5b9f\u88c5\u6642\u306e\u6ce8\u610f\u70b9<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>TTL\u306f\u5fc5\u8981\u6700\u5c0f\u9650\u306b\u8a2d\u5b9a\u3057\u3001\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u3092\u6700\u9069\u5316<\/li>\n\n\n\n<li>\u91cd\u8981\u306a\u30c7\u30fc\u30bf\u306b\u306f\u9069\u5207\u306a\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u6226\u7565\u3092\u4f75\u7528<\/li>\n\n\n\n<li>TTL\u306e\u76e3\u8996\u3068\u30a2\u30e9\u30fc\u30c8\u8a2d\u5b9a\u3092\u691c\u8a0e<\/li>\n\n\n\n<li>\u8907\u6570\u30b5\u30fc\u30d0\u30fc\u74b0\u5883\u3067\u306e\u6642\u523b\u540c\u671f\u306b\u6ce8\u610f<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u306e\u3088\u3046\u306b\u3001PHP-Redis\u30a8\u30af\u30b9\u30c6\u30f3\u30b7\u30e7\u30f3\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u52b9\u7387\u7684\u306a\u30ad\u30e3\u30c3\u30b7\u30e5\u30b7\u30b9\u30c6\u30e0\u3084\u30bb\u30c3\u30b7\u30e7\u30f3\u7ba1\u7406\u3092\u5b9f\u88c5\u3067\u304d\u307e\u3059\u3002\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001\u3053\u308c\u3089\u306e\u57fa\u672c\u7684\u306a\u5b9f\u88c5\u3092\u5fdc\u7528\u3057\u305f\u3001\u3088\u308a\u5b9f\u8df5\u7684\u306a\u6d3b\u7528\u30d1\u30bf\u30fc\u30f3\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-7\">\u5b9f\u8df5\u7684\u306aRedis set\u306e\u6d3b\u7528\u30d1\u30bf\u30fc\u30f3<\/h2>\n\n\n\n<p>\u5b9f\u52d9\u3067\u3088\u304f\u906d\u9047\u3059\u308b\u5177\u4f53\u7684\u306a\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u306b\u3064\u3044\u3066\u3001\u5b9f\u88c5\u4f8b\u3068\u5171\u306b\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-8\">\u30bb\u30c3\u30b7\u30e7\u30f3\u7ba1\u7406\u3067\u306e\u5229\u7528\u65b9\u6cd5<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30ab\u30b9\u30bf\u30e0\u30bb\u30c3\u30b7\u30e7\u30f3\u30cf\u30f3\u30c9\u30e9\u306e\u5b9f\u88c5<\/strong><\/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 RedisSessionHandler implements SessionHandlerInterface\n{\n    private $redis;\n    private $ttl;\n    private $prefix;\n\n    public function __construct(Redis $redis, $ttl = 3600, $prefix = 'session:') {\n        $this-&gt;redis = $redis;\n        $this-&gt;ttl = $ttl;\n        $this-&gt;prefix = $prefix;\n    }\n\n    public function open($savePath, $sessionName): bool {\n        return true;\n    }\n\n    public function close(): bool {\n        return true;\n    }\n\n    public function read($id): string {\n        $data = $this-&gt;redis-&gt;get($this-&gt;prefix . $id);\n        return $data ? $data : '';\n    }\n\n    public function write($id, $data): bool {\n        return $this-&gt;redis-&gt;setex(\n            $this-&gt;prefix . $id,\n            $this-&gt;ttl,\n            $data\n        );\n    }\n\n    public function destroy($id): bool {\n        $this-&gt;redis-&gt;del($this-&gt;prefix . $id);\n        return true;\n    }\n\n    public function gc($maxlifetime): bool {\n        return true; \/\/ Redis\u304c\u81ea\u52d5\u7684\u306b\u671f\u9650\u5207\u308c\u30ad\u30fc\u3092\u524a\u9664\n    }\n}\n\n\/\/ \u4f7f\u7528\u4f8b\n$redis = new Redis();\n$redis-&gt;connect('127.0.0.1', 6379);\n$handler = new RedisSessionHandler($redis);\nsession_set_save_handler($handler, true);\nsession_start();<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u30bb\u30c3\u30b7\u30e7\u30f3\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u306e\u5b9f\u73fe<\/strong><\/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 ClusteredSessionManager {\n    private $redis;\n    private $prefix = 'clustered_session:';\n\n    public function __construct(array $redisNodes) {\n        $this-&gt;redis = new RedisCluster(null, $redisNodes);\n    }\n\n    \/**\n     * \u30bb\u30c3\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf\u306e\u4fdd\u5b58\n     * @param string $sessionId \u30bb\u30c3\u30b7\u30e7\u30f3ID\n     * @param array $data \u30bb\u30c3\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf\n     * @param int $ttl \u6709\u52b9\u671f\u9650\uff08\u79d2\uff09\n     *\/\n    public function saveSession($sessionId, array $data, $ttl = 3600) {\n        $key = $this-&gt;prefix . $sessionId;\n        $this-&gt;redis-&gt;setex($key, $ttl, serialize($data));\n    }\n\n    \/**\n     * \u30bb\u30c3\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf\u306e\u53d6\u5f97\n     * @param string $sessionId \u30bb\u30c3\u30b7\u30e7\u30f3ID\n     * @return array|null \u30bb\u30c3\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf\n     *\/\n    public function getSession($sessionId) {\n        $key = $this-&gt;prefix . $sessionId;\n        $data = $this-&gt;redis-&gt;get($key);\n        return $data ? unserialize($data) : null;\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-9\">\u30ad\u30e3\u30c3\u30b7\u30e5\u30b7\u30b9\u30c6\u30e0\u3068\u3057\u3066\u306e\u5b9f\u88c5\u4f8b<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u968e\u5c64\u7684\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u5b9f\u88c5<\/strong><\/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 TieredCache {\n    private $redis;\n    private $localCache = [];\n    private $prefix = 'cache:';\n\n    public function __construct(Redis $redis) {\n        $this-&gt;redis = $redis;\n    }\n\n    \/**\n     * \u30ad\u30e3\u30c3\u30b7\u30e5\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\n     * @param string $key \u30ad\u30fc\n     * @param callable $fallback \u30ad\u30e3\u30c3\u30b7\u30e5\u30df\u30b9\u6642\u306e\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\n     * @return mixed\n     *\/\n    public function remember($key, callable $fallback) {\n        \/\/ \u30ed\u30fc\u30ab\u30eb\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u30c1\u30a7\u30c3\u30af\n        if (isset($this-&gt;localCache[$key])) {\n            return $this-&gt;localCache[$key];\n        }\n\n        \/\/ Redis\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u30c1\u30a7\u30c3\u30af\n        $value = $this-&gt;redis-&gt;get($this-&gt;prefix . $key);\n        if ($value !== false) {\n            $value = unserialize($value);\n            $this-&gt;localCache[$key] = $value;\n            return $value;\n        }\n\n        \/\/ \u30ad\u30e3\u30c3\u30b7\u30e5\u30df\u30b9\u6642\u306b\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\n        $value = $fallback();\n\n        \/\/ \u4e21\u65b9\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u66f4\u65b0\n        $this-&gt;redis-&gt;setex(\n            $this-&gt;prefix . $key,\n            3600,\n            serialize($value)\n        );\n        $this-&gt;localCache[$key] = $value;\n\n        return $value;\n    }\n}\n\n\/\/ \u4f7f\u7528\u4f8b\n$cache = new TieredCache($redis);\n$userData = $cache-&gt;remember('user:1', function() {\n    \/\/ DB\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u91cd\u3044\u51e6\u7406\n    return DB::table('users')-&gt;find(1);\n});<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-10\">\u5206\u6563\u30ed\u30c3\u30af\u306e\u5b9f\u73fe\u65b9\u6cd5<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Redis\u3092\u4f7f\u7528\u3057\u305f\u5206\u6563\u30ed\u30c3\u30af\u5b9f\u88c5<\/strong><\/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 RedisLock {\n    private $redis;\n    private $retryDelay = 100000; \/\/ \u30de\u30a4\u30af\u30ed\u79d2\n    private $maxRetries = 30;\n\n    public function __construct(Redis $redis) {\n        $this-&gt;redis = $redis;\n    }\n\n    \/**\n     * \u30ed\u30c3\u30af\u306e\u53d6\u5f97\n     * @param string $lockKey \u30ed\u30c3\u30af\u30ad\u30fc\n     * @param int $ttl \u30ed\u30c3\u30af\u306e\u6709\u52b9\u671f\u9650\uff08\u79d2\uff09\n     * @return string|false \u30ed\u30c3\u30af\u30c8\u30fc\u30af\u30f3\u307e\u305f\u306f\u5931\u6557\u6642\u306ffalse\n     *\/\n    public function acquire($lockKey, $ttl = 30) {\n        $token = uniqid('lock:', true);\n        $retry = $this-&gt;maxRetries;\n\n        while ($retry--) {\n            \/\/ NX\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u65e2\u5b58\u30ad\u30fc\u304c\u306a\u3044\u5834\u5408\u306e\u307f\u8a2d\u5b9a\n            if ($this-&gt;redis-&gt;set(\"lock:{$lockKey}\", $token, ['NX', 'EX' =&gt; $ttl])) {\n                return $token;\n            }\n\n            if ($retry) {\n                usleep($this-&gt;retryDelay);\n            }\n        }\n\n        return false;\n    }\n\n    \/**\n     * \u30ed\u30c3\u30af\u306e\u89e3\u653e\n     * @param string $lockKey \u30ed\u30c3\u30af\u30ad\u30fc\n     * @param string $token \u30ed\u30c3\u30af\u30c8\u30fc\u30af\u30f3\n     * @return bool \u6210\u529f\/\u5931\u6557\n     *\/\n    public function release($lockKey, $token) {\n        \/\/ Lua\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u30a2\u30c8\u30df\u30c3\u30af\u306a\u64cd\u4f5c\u3092\u5b9f\u73fe\n        $script = &lt;&lt;&lt;LUA\n        if redis.call('get', KEYS[1]) == ARGV[1] then\n            return redis.call('del', KEYS[1])\n        else\n            return 0\n        end\nLUA;\n\n        return (bool) $this-&gt;redis-&gt;eval(\n            $script,\n            [\"lock:{$lockKey}\", $token],\n            1\n        );\n    }\n}\n\n\/\/ \u4f7f\u7528\u4f8b\nclass PaymentProcessor {\n    private $lock;\n\n    public function __construct(RedisLock $lock) {\n        $this-&gt;lock = $lock;\n    }\n\n    public function processPayment($orderId) {\n        $lockKey = \"order:{$orderId}\";\n\n        \/\/ \u30ed\u30c3\u30af\u3092\u53d6\u5f97\n        if ($token = $this-&gt;lock-&gt;acquire($lockKey)) {\n            try {\n                \/\/ \u6392\u4ed6\u7684\u306a\u51e6\u7406\u3092\u5b9f\u884c\n                $this-&gt;executePayment($orderId);\n            } finally {\n                \/\/ \u51e6\u7406\u5b8c\u4e86\u5f8c\u3001\u5fc5\u305a\u30ed\u30c3\u30af\u3092\u89e3\u653e\n                $this-&gt;lock-&gt;release($lockKey, $token);\n            }\n        } else {\n            throw new RuntimeException('\u30ed\u30c3\u30af\u306e\u53d6\u5f97\u306b\u5931\u6557\u3057\u307e\u3057\u305f');\n        }\n    }\n}<\/pre>\n\n\n\n<p>\u3053\u306e\u3088\u3046\u306b\u3001Redis\u306eset\u30b3\u30de\u30f3\u30c9\u3092\u6d3b\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u69d8\u3005\u306a\u5b9f\u8df5\u7684\u306a\u30d1\u30bf\u30fc\u30f3\u3092\u5b9f\u88c5\u3067\u304d\u307e\u3059\u3002\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001\u3053\u308c\u3089\u306e\u5b9f\u88c5\u30d1\u30bf\u30fc\u30f3\u3092\u904b\u7528\u3059\u308b\u969b\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-11\">Redis set\u30b3\u30de\u30f3\u30c9\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0<\/h2>\n\n\n\n<p>Redis\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u6700\u5927\u9650\u306b\u5f15\u304d\u51fa\u3059\u305f\u3081\u306e\u5177\u4f53\u7684\u306a\u65b9\u6cd5\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-12\">\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u306e\u6700\u9069\u5316\u624b\u6cd5<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30ad\u30fc\u8a2d\u8a08\u306e\u6700\u9069\u5316<\/strong><\/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 OptimizedKeyManager {\n    private $redis;\n\n    \/**\n     * \u63a8\u5968\u3055\u308c\u308b\u30ad\u30fc\u547d\u540d\u898f\u5247\uff1a\n     * - \u77ed\u3059\u304e\u305a\u9577\u3059\u304e\u306a\u3044\uff08\u6700\u592744\u6587\u5b57\u3092\u76ee\u5b89\uff09\n     * - \u533a\u5207\u308a\u6587\u5b57\u3068\u3057\u3066':'\u3092\u4f7f\u7528\n     * - \u30d7\u30ec\u30d5\u30a3\u30c3\u30af\u30b9\u3067\u30c7\u30fc\u30bf\u30bf\u30a4\u30d7\u3092\u8b58\u5225\n     *\/\n    private $keyPatterns = [\n        'user' =&gt; 'usr:%d:profile',    \/\/ \u826f\u3044\u4f8b\uff1ausr:1000:profile\n        'session' =&gt; 'sess:%s',         \/\/ \u826f\u3044\u4f8b\uff1asess:abc123\n        'cache' =&gt; 'cache:%s:%s'        \/\/ \u826f\u3044\u4f8b\uff1acache:orders:recent\n    ];\n\n    public function __construct(Redis $redis) {\n        $this-&gt;redis = $redis;\n    }\n\n    \/**\n     * \u30e1\u30e2\u30ea\u52b9\u7387\u306e\u826f\u3044\u30ad\u30fc\u751f\u6210\n     * @param string $type \u30ad\u30fc\u30bf\u30a4\u30d7\n     * @param array $params \u30d1\u30e9\u30e1\u30fc\u30bf\n     * @return string \u751f\u6210\u3055\u308c\u305f\u30ad\u30fc\n     *\/\n    public function generateKey($type, array $params) {\n        if (!isset($this-&gt;keyPatterns[$type])) {\n            throw new InvalidArgumentException('Unknown key type');\n        }\n        return vsprintf($this-&gt;keyPatterns[$type], $params);\n    }\n\n    \/**\n     * \u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u306e\u63a8\u5b9a\n     * @param string $key \u30ad\u30fc\n     * @param mixed $value \u5024\n     * @return int \u63a8\u5b9a\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\uff08\u30d0\u30a4\u30c8\uff09\n     *\/\n    public function estimateMemoryUsage($key, $value) {\n        \/\/ \u30ad\u30fc\u306e\u30aa\u30fc\u30d0\u30fc\u30d8\u30c3\u30c9: \u7d0424\u30d0\u30a4\u30c8\n        $overhead = 24;\n        \/\/ \u30ad\u30fc\u306e\u30b5\u30a4\u30ba\n        $keySize = strlen($key);\n        \/\/ \u5024\u306e\u30b5\u30a4\u30ba\n        $valueSize = strlen(serialize($value));\n\n        return $overhead + $keySize + $valueSize;\n    }\n}<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u5727\u7e2e\u3068\u6700\u9069\u5316\u30c6\u30af\u30cb\u30c3\u30af<\/strong><\/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 DataCompressor {\n    \/**\n     * \u30c7\u30fc\u30bf\u306e\u5727\u7e2e\n     * @param mixed $data \u5727\u7e2e\u3059\u308b\u30c7\u30fc\u30bf\n     * @return string \u5727\u7e2e\u3055\u308c\u305f\u30c7\u30fc\u30bf\n     *\/\n    public function compress($data) {\n        \/\/ \u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u3057\u3066\u304b\u3089gzip\u5727\u7e2e\n        return gzcompress(serialize($data), 9);\n    }\n\n    \/**\n     * \u30c7\u30fc\u30bf\u306e\u5c55\u958b\n     * @param string $compressed \u5727\u7e2e\u3055\u308c\u305f\u30c7\u30fc\u30bf\n     * @return mixed \u5c55\u958b\u3055\u308c\u305f\u30c7\u30fc\u30bf\n     *\/\n    public function decompress($compressed) {\n        return unserialize(gzuncompress($compressed));\n    }\n}\n\n\/\/ \u4f7f\u7528\u4f8b\nclass OptimizedRedisManager {\n    private $redis;\n    private $compressor;\n\n    public function __construct(Redis $redis) {\n        $this-&gt;redis = $redis;\n        $this-&gt;compressor = new DataCompressor();\n    }\n\n    \/**\n     * \u6700\u9069\u5316\u3055\u308c\u305f\u5f62\u5f0f\u3067\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58\n     * @param string $key \u30ad\u30fc\n     * @param mixed $value \u5024\n     * @param int $ttl \u6709\u52b9\u671f\u9650\uff08\u79d2\uff09\n     *\/\n    public function setOptimized($key, $value, $ttl = null) {\n        \/\/ \u6570\u5024\u30c7\u30fc\u30bf\u306e\u6700\u9069\u5316\n        if (is_numeric($value)) {\n            $this-&gt;redis-&gt;set($key, $value);\n            return;\n        }\n\n        \/\/ \u5927\u304d\u306a\u30c7\u30fc\u30bf\u306e\u5727\u7e2e\n        if (strlen(serialize($value)) &gt; 1024) {\n            $value = $this-&gt;compressor-&gt;compress($value);\n        }\n\n        if ($ttl) {\n            $this-&gt;redis-&gt;setex($key, $ttl, $value);\n        } else {\n            $this-&gt;redis-&gt;set($key, $value);\n        }\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-13\">\u5927\u91cf\u30c7\u30fc\u30bf\u51e6\u7406\u6642\u306e\u6ce8\u610f\u70b9<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30d1\u30a4\u30d7\u30e9\u30a4\u30f3\u51e6\u7406\u306e\u5b9f\u88c5<\/strong><\/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 RedisBulkProcessor {\n    private $redis;\n    private $batchSize = 1000;\n\n    public function __construct(Redis $redis) {\n        $this-&gt;redis = $redis;\n    }\n\n    \/**\n     * \u5927\u91cf\u30c7\u30fc\u30bf\u306e\u4e00\u62ec\u51e6\u7406\n     * @param array $data \u30ad\u30fc\u3068\u5024\u306e\u914d\u5217\n     * @return array \u51e6\u7406\u7d50\u679c\n     *\/\n    public function processBulkData(array $data) {\n        $results = [];\n        $chunks = array_chunk($data, $this-&gt;batchSize, true);\n\n        foreach ($chunks as $chunk) {\n            \/\/ \u30d1\u30a4\u30d7\u30e9\u30a4\u30f3\u306e\u958b\u59cb\n            $this-&gt;redis-&gt;multi(Redis::PIPELINE);\n\n            foreach ($chunk as $key =&gt; $value) {\n                $this-&gt;redis-&gt;set($key, $value);\n            }\n\n            \/\/ \u30d1\u30a4\u30d7\u30e9\u30a4\u30f3\u306e\u5b9f\u884c\n            $results[] = $this-&gt;redis-&gt;exec();\n        }\n\n        return $results;\n    }\n\n    \/**\n     * \u30d0\u30eb\u30af\u53d6\u5f97\u306e\u6700\u9069\u5316\n     * @param array $keys \u53d6\u5f97\u3059\u308b\u30ad\u30fc\u306e\u914d\u5217\n     * @return array \u53d6\u5f97\u7d50\u679c\n     *\/\n    public function optimizedBulkGet(array $keys) {\n        $results = [];\n        $chunks = array_chunk($keys, $this-&gt;batchSize);\n\n        foreach ($chunks as $chunk) {\n            $results = array_merge(\n                $results,\n                $this-&gt;redis-&gt;mget($chunk) ?: []\n            );\n        }\n\n        return $results;\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-14\">\u30e2\u30cb\u30bf\u30ea\u30f3\u30b0\u3068\u76e3\u8996\u306e\u5b9f\u73fe<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30e2\u30cb\u30bf\u30ea\u30f3\u30b0\u306e\u5b9f\u88c5<\/strong><\/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 RedisMonitor {\n    private $redis;\n    private $metricsKey = 'metrics:redis:';\n\n    public function __construct(Redis $redis) {\n        $this-&gt;redis = $redis;\n    }\n\n    \/**\n     * \u64cd\u4f5c\u306e\u5b9f\u884c\u6642\u9593\u3092\u8a08\u6e2c\n     * @param string $operation \u64cd\u4f5c\u540d\n     * @param callable $callback \u5b9f\u884c\u3059\u308b\u64cd\u4f5c\n     * @return mixed \u64cd\u4f5c\u306e\u7d50\u679c\n     *\/\n    public function measureOperation($operation, callable $callback) {\n        $start = microtime(true);\n\n        try {\n            $result = $callback();\n            $duration = microtime(true) - $start;\n\n            \/\/ \u30e1\u30c8\u30ea\u30af\u30b9\u306e\u8a18\u9332\n            $this-&gt;recordMetrics($operation, $duration, true);\n\n            return $result;\n        } catch (Exception $e) {\n            $duration = microtime(true) - $start;\n            $this-&gt;recordMetrics($operation, $duration, false);\n            throw $e;\n        }\n    }\n\n    \/**\n     * \u30e1\u30c8\u30ea\u30af\u30b9\u306e\u8a18\u9332\n     * @param string $operation \u64cd\u4f5c\u540d\n     * @param float $duration \u5b9f\u884c\u6642\u9593\n     * @param bool $success \u6210\u529f\/\u5931\u6557\n     *\/\n    private function recordMetrics($operation, $duration, $success) {\n        $now = time();\n        $hourKey = $this-&gt;metricsKey . date('Y-m-d:H', $now);\n\n        $this-&gt;redis-&gt;pipeline()\n            -&gt;hIncrBy($hourKey, $operation . ':count', 1)\n            -&gt;hIncrByFloat($hourKey, $operation . ':total_time', $duration)\n            -&gt;hIncrBy($hourKey, $operation . ':errors', $success ? 0 : 1)\n            -&gt;expire($hourKey, 86400)\n            -&gt;exec();\n    }\n\n    \/**\n     * \u30e1\u30e2\u30ea\u4f7f\u7528\u72b6\u6cc1\u306e\u53d6\u5f97\n     * @return array \u30e1\u30e2\u30ea\u4f7f\u7528\u72b6\u6cc1\n     *\/\n    public function getMemoryStats() {\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            'used_memory_lua' =&gt; $info['used_memory_lua'],\n            'mem_fragmentation_ratio' =&gt; $info['mem_fragmentation_ratio']\n        ];\n    }\n\n    \/**\n     * \u30b9\u30ed\u30fc\u30af\u30a8\u30ea\u306e\u691c\u51fa\n     * @param float $threshold \u95be\u5024\uff08\u79d2\uff09\n     * @return array \u30b9\u30ed\u30fc\u30af\u30a8\u30ea\u60c5\u5831\n     *\/\n    public function detectSlowOperations($threshold = 0.1) {\n        $metrics = $this-&gt;redis-&gt;hGetAll($this-&gt;metricsKey . date('Y-m-d:H'));\n        $slowOps = [];\n\n        foreach ($metrics as $key =&gt; $value) {\n            if (strpos($key, ':total_time') !== false) {\n                $op = str_replace(':total_time', '', $key);\n                $count = $metrics[$op . ':count'] ?? 1;\n                $avgTime = $value \/ $count;\n\n                if ($avgTime &gt; $threshold) {\n                    $slowOps[$op] = [\n                        'average_time' =&gt; $avgTime,\n                        'total_count' =&gt; $count,\n                        'total_time' =&gt; $value\n                    ];\n                }\n            }\n        }\n\n        return $slowOps;\n    }\n}\n\n\/\/ \u4f7f\u7528\u4f8b\n$monitor = new RedisMonitor($redis);\n\n\/\/ \u64cd\u4f5c\u306e\u30e2\u30cb\u30bf\u30ea\u30f3\u30b0\n$result = $monitor-&gt;measureOperation('set_user_data', function() use ($redis) {\n    return $redis-&gt;set('user:1', json_encode(['name' =&gt; 'John']));\n});\n\n\/\/ \u30e1\u30e2\u30ea\u4f7f\u7528\u72b6\u6cc1\u306e\u78ba\u8a8d\n$memoryStats = $monitor-&gt;getMemoryStats();\nprint_r($memoryStats);\n\n\/\/ \u30b9\u30ed\u30fc\u30af\u30a8\u30ea\u306e\u691c\u51fa\n$slowOps = $monitor-&gt;detectSlowOperations(0.05);\nforeach ($slowOps as $op =&gt; $stats) {\n    echo \"Slow operation detected: {$op}\\n\";\n    echo \"Average time: {$stats['average_time']} seconds\\n\";\n}<\/pre>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u6700\u9069\u5316\u3068\u30e2\u30cb\u30bf\u30ea\u30f3\u30b0\u624b\u6cd5\u3092\u9069\u5207\u306b\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001Redis\u306e\u6027\u80fd\u3092\u6700\u5927\u9650\u306b\u5f15\u304d\u51fa\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001\u3053\u308c\u3089\u306e\u624b\u6cd5\u3092\u5b9f\u969b\u306e\u904b\u7528\u74b0\u5883\u3067\u6d3b\u7528\u3059\u308b\u305f\u3081\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-15\">\u904b\u7528\u74b0\u5883\u3067\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/h2>\n\n\n\n<p>\u672c\u756a\u74b0\u5883\u3067Redis\u3092\u5b89\u5168\u304b\u3064\u52b9\u7387\u7684\u306b\u904b\u7528\u3059\u308b\u305f\u3081\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-16\">\u30ad\u30fc\u8a2d\u8a08\u306e\u30ac\u30a4\u30c9\u30e9\u30a4\u30f3<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u547d\u540d\u898f\u5247\u306e\u78ba\u7acb<\/strong><\/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 KeyDesignManager {\n    \/**\n     * \u30ad\u30fc\u8a2d\u8a08\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\n     * - \u540d\u524d\u7a7a\u9593\u306e\u4f7f\u7528\n     * - \u30c7\u30fc\u30bf\u30bf\u30a4\u30d7\u306e\u660e\u793a\n     * - \u8b58\u5225\u5b50\u306e\u542b\u6709\n     *\/\n    private $keyTemplates = [\n        'user_data' =&gt; [\n            'pattern' =&gt; 'usr:{uid}:profile',\n            'example' =&gt; 'usr:1234:profile',\n            'ttl' =&gt; 3600\n        ],\n        'session' =&gt; [\n            'pattern' =&gt; 'sess:{sid}',\n            'example' =&gt; 'sess:abc123def456',\n            'ttl' =&gt; 1800\n        ],\n        'rate_limit' =&gt; [\n            'pattern' =&gt; 'rate:{ip}:{action}',\n            'example' =&gt; 'rate:192.168.1.1:login',\n            'ttl' =&gt; 300\n        ]\n    ];\n\n    \/**\n     * \u30ad\u30fc\u306e\u751f\u6210\n     * @param string $type \u30ad\u30fc\u30bf\u30a4\u30d7\n     * @param array $params \u30d1\u30e9\u30e1\u30fc\u30bf\n     * @return array \u30ad\u30fc\u60c5\u5831\n     *\/\n    public function generateKey($type, array $params) {\n        if (!isset($this-&gt;keyTemplates[$type])) {\n            throw new InvalidArgumentException('Invalid key type');\n        }\n\n        $template = $this-&gt;keyTemplates[$type];\n        $key = $template['pattern'];\n\n        foreach ($params as $name =&gt; $value) {\n            $key = str_replace(\"{{$name}}\", $value, $key);\n        }\n\n        return [\n            'key' =&gt; $key,\n            'ttl' =&gt; $template['ttl']\n        ];\n    }\n}<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u30ad\u30fc\u7ba1\u7406\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/strong><\/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 KeyManagementBestPractices {\n    private $redis;\n\n    public function __construct(Redis $redis) {\n        $this-&gt;redis = $redis;\n    }\n\n    \/**\n     * \u30ad\u30fc\u306e\u5b58\u5728\u78ba\u8a8d\u3068\u6709\u52b9\u671f\u9650\u306e\u66f4\u65b0\n     * @param string $key \u30ad\u30fc\n     * @param int $ttl \u65b0\u3057\u3044\u6709\u52b9\u671f\u9650\uff08\u79d2\uff09\n     * @return bool \u6210\u529f\/\u5931\u6557\n     *\/\n    public function refreshKey($key, $ttl) {\n        if (!$this-&gt;redis-&gt;exists($key)) {\n            return false;\n        }\n\n        \/\/ \u30ad\u30fc\u304c\u5b58\u5728\u3059\u308b\u5834\u5408\u306e\u307fTTL\u3092\u66f4\u65b0\n        return $this-&gt;redis-&gt;expire($key, $ttl);\n    }\n\n    \/**\n     * \u30ad\u30fc\u306e\u30d1\u30bf\u30fc\u30f3\u306b\u57fa\u3065\u304f\u4e00\u62ec\u7ba1\u7406\n     * @param string $pattern \u30d1\u30bf\u30fc\u30f3\n     * @param callable $callback \u51e6\u7406\u5185\u5bb9\n     *\/\n    public function manageBulkKeys($pattern, callable $callback) {\n        $iterator = null;\n        while ($keys = $this-&gt;redis-&gt;scan($iterator, $pattern, 100)) {\n            foreach ($keys as $key) {\n                $callback($key);\n            }\n        }\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-17\">\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3068\u5fa9\u65e7\u6226\u7565<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u81ea\u52d5\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u306e\u5b9f\u88c5<\/strong><\/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 RedisBackupManager {\n    private $redis;\n    private $backupPath;\n    private $maxBackups;\n\n    public function __construct(Redis $redis, $backupPath, $maxBackups = 7) {\n        $this-&gt;redis = $redis;\n        $this-&gt;backupPath = $backupPath;\n        $this-&gt;maxBackups = $maxBackups;\n    }\n\n    \/**\n     * \u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u306e\u5b9f\u884c\n     * @return bool \u6210\u529f\/\u5931\u6557\n     *\/\n    public function createBackup() {\n        try {\n            \/\/ RDB\u30d5\u30a1\u30a4\u30eb\u306e\u4fdd\u5b58\u3092\u5f37\u5236\n            $this-&gt;redis-&gt;save();\n\n            \/\/ \u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u30d5\u30a1\u30a4\u30eb\u540d\u306e\u751f\u6210\n            $filename = sprintf(\n                'redis_backup_%s.rdb',\n                date('Y-m-d_H-i-s')\n            );\n\n            \/\/ \u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u306e\u4fdd\u5b58\n            if (!copy('\/var\/lib\/redis\/dump.rdb', \n                     $this-&gt;backupPath . '\/' . $filename)) {\n                throw new RuntimeException('Backup file copy failed');\n            }\n\n            \/\/ \u53e4\u3044\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u306e\u524a\u9664\n            $this-&gt;rotateBackups();\n\n            return true;\n        } catch (Exception $e) {\n            error_log(\"Backup failed: \" . $e-&gt;getMessage());\n            return false;\n        }\n    }\n\n    \/**\n     * \u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u306e\u5fa9\u5143\n     * @param string $filename \u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u30d5\u30a1\u30a4\u30eb\u540d\n     * @return bool \u6210\u529f\/\u5931\u6557\n     *\/\n    public function restoreBackup($filename) {\n        try {\n            \/\/ Redis\u30b5\u30fc\u30d0\u30fc\u306e\u505c\u6b62\n            $this-&gt;redis-&gt;shutdown();\n\n            \/\/ \u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u30d5\u30a1\u30a4\u30eb\u306e\u5fa9\u5143\n            if (!copy($this-&gt;backupPath . '\/' . $filename,\n                     '\/var\/lib\/redis\/dump.rdb')) {\n                throw new RuntimeException('Restore file copy failed');\n            }\n\n            \/\/ Redis\u30b5\u30fc\u30d0\u30fc\u306e\u518d\u8d77\u52d5\uff08\u30b7\u30b9\u30c6\u30e0\u30b3\u30de\u30f3\u30c9\uff09\n            exec('sudo service redis-server start');\n\n            return true;\n        } catch (Exception $e) {\n            error_log(\"Restore failed: \" . $e-&gt;getMessage());\n            return false;\n        }\n    }\n\n    \/**\n     * \u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u30ed\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\n     *\/\n    private function rotateBackups() {\n        $backups = glob($this-&gt;backupPath . '\/redis_backup_*.rdb');\n        if (count($backups) &gt; $this-&gt;maxBackups) {\n            \/\/ \u53e4\u3044\u9806\u306b\u30bd\u30fc\u30c8\n            sort($backups);\n            \/\/ \u53e4\u3044\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3092\u524a\u9664\n            $deleteCount = count($backups) - $this-&gt;maxBackups;\n            for ($i = 0; $i &lt; $deleteCount; $i++) {\n                unlink($backups[$i]);\n            }\n        }\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-18\">\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u5bfe\u7b56\u306e\u5b9f\u73fe<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u8a2d\u5b9a\u306e\u5b9f\u88c5<\/strong><\/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 RedisSecurityManager {\n    private $redis;\n\n    public function __construct(Redis $redis) {\n        $this-&gt;redis = $redis;\n    }\n\n    \/**\n     * \u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u8a2d\u5b9a\u306e\u9069\u7528\n     * @param array $config \u8a2d\u5b9a\u5185\u5bb9\n     * @return bool \u6210\u529f\/\u5931\u6557\n     *\/\n    public function applySecuritySettings(array $config) {\n        try {\n            \/\/ \u30d1\u30b9\u30ef\u30fc\u30c9\u8a8d\u8a3c\u306e\u8a2d\u5b9a\n            if (isset($config['password'])) {\n                $this-&gt;redis-&gt;config('SET', 'requirepass', $config['password']);\n            }\n\n            \/\/ \u63a5\u7d9a\u5236\u9650\u306e\u8a2d\u5b9a\n            if (isset($config['bind'])) {\n                $this-&gt;redis-&gt;config('SET', 'bind', implode(' ', $config['bind']));\n            }\n\n            \/\/ \u6700\u5927\u63a5\u7d9a\u6570\u306e\u8a2d\u5b9a\n            if (isset($config['maxclients'])) {\n                $this-&gt;redis-&gt;config('SET', 'maxclients', $config['maxclients']);\n            }\n\n            \/\/ \u8a2d\u5b9a\u306e\u6c38\u7d9a\u5316\n            $this-&gt;redis-&gt;save();\n\n            return true;\n        } catch (Exception $e) {\n            error_log(\"Security settings failed: \" . $e-&gt;getMessage());\n            return false;\n        }\n    }\n\n    \/**\n     * \u30a2\u30af\u30bb\u30b9\u5236\u5fa1\u306e\u5b9f\u88c5\n     * @param string $command \u30b3\u30de\u30f3\u30c9\n     * @param array $args \u5f15\u6570\n     * @return bool \u8a31\u53ef\/\u62d2\u5426\n     *\/\n    public function isCommandAllowed($command, array $args) {\n        \/\/ \u7981\u6b62\u30b3\u30de\u30f3\u30c9\u30ea\u30b9\u30c8\n        $restrictedCommands = [\n            'FLUSHALL',\n            'FLUSHDB',\n            'CONFIG',\n            'SHUTDOWN'\n        ];\n\n        \/\/ \u30b3\u30de\u30f3\u30c9\u306e\u5236\u9650\u30c1\u30a7\u30c3\u30af\n        if (in_array(strtoupper($command), $restrictedCommands)) {\n            return false;\n        }\n\n        \/\/ \u30ad\u30fc\u30d1\u30bf\u30fc\u30f3\u306e\u5236\u9650\u30c1\u30a7\u30c3\u30af\n        if ($this-&gt;isRestrictedKeyPattern($args[0] ?? '')) {\n            return false;\n        }\n\n        return true;\n    }\n\n    \/**\n     * \u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u76e3\u67fb\u306e\u5b9f\u88c5\n     * @return array \u76e3\u67fb\u7d50\u679c\n     *\/\n    public function performSecurityAudit() {\n        $results = [];\n\n        \/\/ \u30d1\u30b9\u30ef\u30fc\u30c9\u8a2d\u5b9a\u306e\u78ba\u8a8d\n        $config = $this-&gt;redis-&gt;config('GET', 'requirepass');\n        $results['password_protected'] = !empty($config['requirepass']);\n\n        \/\/ \u63a5\u7d9a\u5236\u9650\u306e\u78ba\u8a8d\n        $config = $this-&gt;redis-&gt;config('GET', 'bind');\n        $results['bind_restrictions'] = $config['bind'] !== '*';\n\n        \/\/ \u4fdd\u8b77\u30e2\u30fc\u30c9\u306e\u78ba\u8a8d\n        $config = $this-&gt;redis-&gt;config('GET', 'protected-mode');\n        $results['protected_mode'] = $config['protected-mode'] === 'yes';\n\n        \/\/ TLS\u8a2d\u5b9a\u306e\u78ba\u8a8d\n        $config = $this-&gt;redis-&gt;config('GET', 'tls-*');\n        $results['tls_enabled'] = !empty($config['tls-port']);\n\n        return $results;\n    }\n}\n\n\/\/ \u4f7f\u7528\u4f8b\n$securityManager = new RedisSecurityManager($redis);\n\n\/\/ \u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u8a2d\u5b9a\u306e\u9069\u7528\n$config = [\n    'password' =&gt; 'strong_password_here',\n    'bind' =&gt; ['127.0.0.1', '192.168.1.100'],\n    'maxclients' =&gt; 1000\n];\n$securityManager-&gt;applySecuritySettings($config);\n\n\/\/ \u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u76e3\u67fb\u306e\u5b9f\u884c\n$auditResults = $securityManager-&gt;performSecurityAudit();\nprint_r($auditResults);<\/pre>\n\n\n\n<p>\u672c\u756a\u74b0\u5883\u3067\u306e\u904b\u7528\u306b\u304a\u3044\u3066\u3001\u3053\u308c\u3089\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u3092\u9069\u5207\u306b\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u5b89\u5168\u3067\u52b9\u7387\u7684\u306aRedis\u904b\u7528\u304c\u5b9f\u73fe\u3067\u304d\u307e\u3059\u3002\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001\u5b9f\u969b\u306e\u904b\u7528\u3067\u906d\u9047\u3059\u308b\u53ef\u80fd\u6027\u306e\u3042\u308b\u554f\u984c\u3068\u305d\u306e\u89e3\u6c7a\u65b9\u6cd5\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-19\">\u3088\u304f\u3042\u308b\u30c8\u30e9\u30d6\u30eb\u3068\u305d\u306e\u89e3\u6c7a\u65b9\u6cd5<\/h2>\n\n\n\n<p>\u904b\u7528\u74b0\u5883\u3067\u767a\u751f\u3057\u3084\u3059\u3044\u554f\u984c\u3068\u305d\u306e\u5177\u4f53\u7684\u306a\u89e3\u6c7a\u65b9\u6cd5\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-20\">\u30e1\u30e2\u30ea\u306e\u554f\u984c\u3068\u5bfe\u51e6\u6cd5<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u306e\u8a3a\u65ad\u3068\u5bfe\u7b56<\/strong><\/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 RedisMemoryDiagnostics {\n    private $redis;\n    private $warningThreshold = 0.8; \/\/ 80%\n    private $criticalThreshold = 0.9; \/\/ 90%\n\n    public function __construct(Redis $redis) {\n        $this-&gt;redis = $redis;\n    }\n\n    \/**\n     * \u30e1\u30e2\u30ea\u4f7f\u7528\u72b6\u6cc1\u306e\u8a73\u7d30\u5206\u6790\n     * @return array \u5206\u6790\u7d50\u679c\n     *\/\n    public function analyzeMemoryUsage() {\n        $info = $this-&gt;redis-&gt;info('memory');\n        $maxMemory = $info['maxmemory'];\n        $usedMemory = $info['used_memory'];\n\n        $results = [\n            'total_memory' =&gt; $maxMemory,\n            'used_memory' =&gt; $usedMemory,\n            'usage_ratio' =&gt; $usedMemory \/ $maxMemory,\n            'fragmentation_ratio' =&gt; $info['mem_fragmentation_ratio'],\n            'status' =&gt; 'normal'\n        ];\n\n        \/\/ \u8b66\u544a\u30ec\u30d9\u30eb\u306e\u5224\u5b9a\n        if ($results['usage_ratio'] &gt; $this-&gt;criticalThreshold) {\n            $results['status'] = 'critical';\n        } elseif ($results['usage_ratio'] &gt; $this-&gt;warningThreshold) {\n            $results['status'] = 'warning';\n        }\n\n        return $results;\n    }\n\n    \/**\n     * \u5927\u304d\u306a\u30ad\u30fc\u306e\u691c\u51fa\n     * @param int $threshold \u30b5\u30a4\u30ba\u95be\u5024\uff08\u30d0\u30a4\u30c8\uff09\n     * @return array \u691c\u51fa\u7d50\u679c\n     *\/\n    public function detectLargeKeys($threshold = 1024 * 1024) {\n        $largeKeys = [];\n        $iterator = null;\n\n        while ($keys = $this-&gt;redis-&gt;scan($iterator, '*', 100)) {\n            foreach ($keys as $key) {\n                $size = $this-&gt;redis-&gt;strlen($key);\n                if ($size &gt; $threshold) {\n                    $largeKeys[$key] = [\n                        'size' =&gt; $size,\n                        'ttl' =&gt; $this-&gt;redis-&gt;ttl($key)\n                    ];\n                }\n            }\n        }\n\n        return $largeKeys;\n    }\n\n    \/**\n     * \u30e1\u30e2\u30ea\u89e3\u653e\u306e\u5b9f\u884c\n     * @param array $config \u8a2d\u5b9a\n     * @return bool \u6210\u529f\/\u5931\u6557\n     *\/\n    public function releaseMemory(array $config = []) {\n        try {\n            \/\/ \u6709\u52b9\u671f\u9650\u5207\u308c\u30ad\u30fc\u306e\u5373\u6642\u524a\u9664\n            $this-&gt;redis-&gt;executeRaw(['EXPIRE', '*', 0]);\n\n            \/\/ maxmemory\u30dd\u30ea\u30b7\u30fc\u306e\u4e00\u6642\u7684\u306a\u5909\u66f4\n            if (isset($config['temp_policy'])) {\n                $this-&gt;redis-&gt;config('SET', 'maxmemory-policy', $config['temp_policy']);\n            }\n\n            \/\/ \u5927\u304d\u306a\u30ad\u30fc\u306e\u524a\u9664\n            $largeKeys = $this-&gt;detectLargeKeys();\n            foreach ($largeKeys as $key =&gt; $info) {\n                if (!isset($config['preserve_keys']) || \n                    !in_array($key, $config['preserve_keys'])) {\n                    $this-&gt;redis-&gt;del($key);\n                }\n            }\n\n            return true;\n        } catch (Exception $e) {\n            error_log(\"Memory release failed: \" . $e-&gt;getMessage());\n            return false;\n        }\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-21\">\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u4f4e\u4e0b\u6642\u306e\u8a3a\u65ad\u3068\u6539\u5584<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u8a3a\u65ad\u30c4\u30fc\u30eb\u306e\u5b9f\u88c5<\/strong><\/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 RedisPerformanceDiagnostics {\n    private $redis;\n    private $slowlogThreshold = 10000; \/\/ \u30de\u30a4\u30af\u30ed\u79d2\n\n    public function __construct(Redis $redis) {\n        $this-&gt;redis = $redis;\n    }\n\n    \/**\n     * \u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6307\u6a19\u306e\u53ce\u96c6\n     * @return array \u8a3a\u65ad\u7d50\u679c\n     *\/\n    public function collectPerformanceMetrics() {\n        $metrics = [\n            'operations' =&gt; $this-&gt;analyzeOperations(),\n            'connections' =&gt; $this-&gt;analyzeConnections(),\n            'slowlog' =&gt; $this-&gt;analyzeSlowLog(),\n            'keyspace' =&gt; $this-&gt;analyzeKeyspace()\n        ];\n\n        return $metrics;\n    }\n\n    \/**\n     * \u64cd\u4f5c\u7d71\u8a08\u306e\u5206\u6790\n     * @return array \u5206\u6790\u7d50\u679c\n     *\/\n    private function analyzeOperations() {\n        $info = $this-&gt;redis-&gt;info('stats');\n        return [\n            'total_commands_processed' =&gt; $info['total_commands_processed'],\n            'instantaneous_ops_per_sec' =&gt; $info['instantaneous_ops_per_sec'],\n            'rejected_connections' =&gt; $info['rejected_connections'],\n            'sync_full' =&gt; $info['sync_full'],\n            'sync_partial_ok' =&gt; $info['sync_partial_ok'],\n            'sync_partial_err' =&gt; $info['sync_partial_err']\n        ];\n    }\n\n    \/**\n     * \u63a5\u7d9a\u72b6\u6cc1\u306e\u5206\u6790\n     * @return array \u5206\u6790\u7d50\u679c\n     *\/\n    private function analyzeConnections() {\n        $info = $this-&gt;redis-&gt;info('clients');\n        return [\n            'connected_clients' =&gt; $info['connected_clients'],\n            'client_longest_output_list' =&gt; $info['client_longest_output_list'],\n            'client_biggest_input_buf' =&gt; $info['client_biggest_input_buf'],\n            'blocked_clients' =&gt; $info['blocked_clients']\n        ];\n    }\n\n    \/**\n     * \u30b9\u30ed\u30fc\u30af\u30a8\u30ea\u306e\u5206\u6790\n     * @return array \u5206\u6790\u7d50\u679c\n     *\/\n    private function analyzeSlowLog() {\n        $slowlogs = $this-&gt;redis-&gt;slowlog('get', 10);\n        $results = [];\n\n        foreach ($slowlogs as $log) {\n            $results[] = [\n                'id' =&gt; $log['id'],\n                'timestamp' =&gt; $log['timestamp'],\n                'duration' =&gt; $log['duration'],\n                'command' =&gt; implode(' ', $log['command'])\n            ];\n        }\n\n        return $results;\n    }\n\n    \/**\n     * \u30ad\u30fc\u30b9\u30da\u30fc\u30b9\u306e\u5206\u6790\n     * @return array \u5206\u6790\u7d50\u679c\n     *\/\n    private function analyzeKeyspace() {\n        $info = $this-&gt;redis-&gt;info('keyspace');\n        $results = [];\n\n        foreach ($info as $db =&gt; $stats) {\n            preg_match('\/keys=(\\d+),expires=(\\d+)\/', $stats, $matches);\n            $results[$db] = [\n                'total_keys' =&gt; $matches[1],\n                'expires_keys' =&gt; $matches[2]\n            ];\n        }\n\n        return $results;\n    }\n\n    \/**\n     * \u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6539\u5584\u306e\u63a8\u5968\u4e8b\u9805\n     * @param array $metrics \u53ce\u96c6\u3057\u305f\u30e1\u30c8\u30ea\u30af\u30b9\n     * @return array \u63a8\u5968\u4e8b\u9805\n     *\/\n    public function getPerformanceRecommendations($metrics) {\n        $recommendations = [];\n\n        \/\/ \u63a5\u7d9a\u6570\u306e\u78ba\u8a8d\n        if ($metrics['connections']['connected_clients'] &gt; 5000) {\n            $recommendations[] = [\n                'issue' =&gt; '\u63a5\u7d9a\u6570\u304c\u591a\u3059\u304e\u307e\u3059',\n                'solution' =&gt; '\u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u30d7\u30fc\u30eb\u306e\u5c0e\u5165\u3092\u691c\u8a0e\u3057\u3066\u304f\u3060\u3055\u3044'\n            ];\n        }\n\n        \/\/ \u30d6\u30ed\u30c3\u30af\u3055\u308c\u305f\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306e\u78ba\u8a8d\n        if ($metrics['connections']['blocked_clients'] &gt; 0) {\n            $recommendations[] = [\n                'issue' =&gt; '\u30d6\u30ed\u30c3\u30af\u3055\u308c\u305f\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304c\u5b58\u5728\u3057\u307e\u3059',\n                'solution' =&gt; '\u30d6\u30ed\u30c3\u30ad\u30f3\u30b0\u64cd\u4f5c\u306e\u4f7f\u7528\u3092\u898b\u76f4\u3057\u3066\u304f\u3060\u3055\u3044'\n            ];\n        }\n\n        \/\/ \u30b9\u30ed\u30fc\u30af\u30a8\u30ea\u306e\u78ba\u8a8d\n        if (count($metrics['slowlog']) &gt; 0) {\n            $recommendations[] = [\n                'issue' =&gt; '\u30b9\u30ed\u30fc\u30af\u30a8\u30ea\u304c\u691c\u51fa\u3055\u308c\u307e\u3057\u305f',\n                'solution' =&gt; '\u691c\u51fa\u3055\u308c\u305f\u30af\u30a8\u30ea\u306e\u6700\u9069\u5316\u3092\u691c\u8a0e\u3057\u3066\u304f\u3060\u3055\u3044'\n            ];\n        }\n\n        return $recommendations;\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-22\">\u8907\u6570\u30b5\u30fc\u30d0\u30fc\u74b0\u5883\u3067\u306e\u6574\u5408\u6027\u78ba\u4fdd\u95a2\u9023<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u76e3\u8996\u3068\u7ba1\u7406<\/strong><\/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 RedisReplicationManager {\n    private $master;\n    private $slaves;\n\n    public function __construct(Redis $master, array $slaves) {\n        $this-&gt;master = $master;\n        $this-&gt;slaves = $slaves;\n    }\n\n    \/**\n     * \u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u72b6\u614b\u306e\u76e3\u8996\n     * @return array \u76e3\u8996\u7d50\u679c\n     *\/\n    public function monitorReplication() {\n        $status = [\n            'master' =&gt; $this-&gt;checkMasterStatus(),\n            'slaves' =&gt; []\n        ];\n\n        foreach ($this-&gt;slaves as $slave) {\n            $status['slaves'][] = $this-&gt;checkSlaveStatus($slave);\n        }\n\n        return $status;\n    }\n\n    \/**\n     * \u30de\u30b9\u30bf\u30fc\u306e\u72b6\u614b\u78ba\u8a8d\n     * @return array \u72b6\u614b\u60c5\u5831\n     *\/\n    private function checkMasterStatus() {\n        $info = $this-&gt;master-&gt;info('replication');\n        return [\n            'role' =&gt; $info['role'],\n            'connected_slaves' =&gt; $info['connected_slaves'],\n            'master_repl_offset' =&gt; $info['master_repl_offset']\n        ];\n    }\n\n    \/**\n     * \u30b9\u30ec\u30fc\u30d6\u306e\u72b6\u614b\u78ba\u8a8d\n     * @param Redis $slave \u30b9\u30ec\u30fc\u30d6\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\n     * @return array \u72b6\u614b\u60c5\u5831\n     *\/\n    private function checkSlaveStatus($slave) {\n        $info = $slave-&gt;info('replication');\n        return [\n            'role' =&gt; $info['role'],\n            'master_host' =&gt; $info['master_host'],\n            'master_port' =&gt; $info['master_port'],\n            'master_link_status' =&gt; $info['master_link_status'],\n            'master_last_io_seconds_ago' =&gt; $info['master_last_io_seconds_ago'],\n            'master_sync_in_progress' =&gt; $info['master_sync_in_progress']\n        ];\n    }\n\n    \/**\n     * \u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u9045\u5ef6\u306e\u691c\u51fa\n     * @return array \u9045\u5ef6\u60c5\u5831\n     *\/\n    public function detectReplicationLag() {\n        $masterOffset = $this-&gt;master-&gt;info('replication')['master_repl_offset'];\n        $delays = [];\n\n        foreach ($this-&gt;slaves as $id =&gt; $slave) {\n            $slaveInfo = $slave-&gt;info('replication');\n            $slaveOffset = $slaveInfo['slave_repl_offset'];\n\n            $delays[$id] = [\n                'offset_diff' =&gt; $masterOffset - $slaveOffset,\n                'seconds_behind' =&gt; $slaveInfo['master_last_io_seconds_ago']\n            ];\n        }\n\n        return $delays;\n    }\n\n    \/**\n     * \u81ea\u52d5\u30d5\u30a7\u30a4\u30eb\u30aa\u30fc\u30d0\u30fc\u306e\u8a2d\u5b9a\n     * @param array $config \u8a2d\u5b9a\u5185\u5bb9\n     * @return bool \u6210\u529f\/\u5931\u6557\n     *\/\n    public function configureFailover(array $config) {\n        try {\n            \/\/ \u30bb\u30f3\u30c1\u30cd\u30eb\u306e\u8a2d\u5b9a\n            foreach ($this-&gt;slaves as $slave) {\n                $slave-&gt;executeRaw(['SENTINEL', 'MONITOR', \n                    'mymaster', \n                    $config['master_host'],\n                    $config['master_port'],\n                    $config['quorum']\n                ]);\n\n                $slave-&gt;executeRaw(['SENTINEL', 'SET', 'mymaster',\n                    'down-after-milliseconds',\n                    $config['down_after']\n                ]);\n\n                $slave-&gt;executeRaw(['SENTINEL', 'SET', 'mymaster',\n                    'failover-timeout',\n                    $config['failover_timeout']\n                ]);\n            }\n\n            return true;\n        } catch (Exception $e) {\n            error_log(\"Failover configuration failed: \" . $e-&gt;getMessage());\n            return false;\n        }\n    }\n}\n\n\/\/ \u4f7f\u7528\u4f8b\n$master = new Redis();\n$master-&gt;connect('master.redis.example.com', 6379);\n\n$slaves = [\n    new Redis(), \/\/ slave1\n    new Redis()  \/\/ slave2\n];\n$slaves[0]-&gt;connect('slave1.redis.example.com', 6379);\n$slaves[1]-&gt;connect('slave2.redis.example.com', 6379);\n\n$replicationManager = new RedisReplicationManager($master, $slaves);\n\n\/\/ \u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u72b6\u614b\u306e\u76e3\u8996\n$status = $replicationManager-&gt;monitorReplication();\nprint_r($status);\n\n\/\/ \u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u9045\u5ef6\u306e\u78ba\u8a8d\n$delays = $replicationManager-&gt;detectReplicationLag();\nprint_r($delays);<\/pre>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u30c8\u30e9\u30d6\u30eb\u30b7\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0\u30c4\u30fc\u30eb\u3068\u624b\u6cd5\u3092\u6d3b\u7528\u3059\u308b\u3053\u3068\u3067\u3001Redis\u904b\u7528\u306b\u304a\u3051\u308b\u69d8\u3005\u306a\u554f\u984c\u306b\u52b9\u679c\u7684\u306b\u5bfe\u51e6\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u91cd\u8981\u306a\u306e\u306f\u3001\u554f\u984c\u304c\u767a\u751f\u3059\u308b\u524d\u306b\u9069\u5207\u306a\u30e2\u30cb\u30bf\u30ea\u30f3\u30b0\u3068\u4e88\u9632\u63aa\u7f6e\u3092\u8b1b\u3058\u308b\u3053\u3068\u3067\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":{"0":"post-3334","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-php","7":"nothumb"},"_links":{"self":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts\/3334","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=3334"}],"version-history":[{"count":2,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts\/3334\/revisions"}],"predecessor-version":[{"id":3336,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts\/3334\/revisions\/3336"}],"wp:attachment":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3334"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3334"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3334"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}