{"id":3308,"date":"2025-03-24T08:46:28","date_gmt":"2025-03-23T23:46:28","guid":{"rendered":"https:\/\/dexall.co.jp\/articles\/?p=3308"},"modified":"2025-03-24T08:46:59","modified_gmt":"2025-03-23T23:46:59","slug":"%e3%80%90%e4%bf%9d%e5%ad%98%e7%89%88%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%e5%ae%8c%e5%85%a8%e3%82%ac%e3%82%a4%e3%83%89%ef%bc%9a%e3%83%87","status":"publish","type":"post","link":"https:\/\/dexall.co.jp\/articles\/?p=3308","title":{"rendered":"\u3010\u4fdd\u5b58\u7248\u3011PHP\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u305f\u3081\u306eRedis\u5b8c\u5168\u30ac\u30a4\u30c9\uff1a\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u8a2d\u8a08\u304b\u3089\u5b9f\u88c5\u307e\u3067"},"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\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u306f<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-1\">\u5f93\u6765\u306eRDBMS\u3068\u306e\u6c7a\u5b9a\u7684\u306a\u9055\u3044<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-2\">\u306a\u305cPHP\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067Redis\u304c\u9078\u3070\u308c\u308b\u306e\u304b<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-3\">Redis\u3092\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u3057\u3066\u4f7f\u7528\u3059\u308b\u30e1\u30ea\u30c3\u30c8<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-4\">\u5727\u5012\u7684\u306a\u8aad\u307f\u53d6\u308a\/\u66f8\u304d\u8fbc\u307f\u901f\u5ea6<\/a>      <\/li>      <li>        <a href=\"#i-5\">\u30b9\u30b1\u30fc\u30e9\u30d3\u30ea\u30c6\u30a3\u306e\u78ba\u4fdd\u304c\u7c21\u5358<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-6\">\u30e1\u30e2\u30ea\u4f7f\u7528\u52b9\u7387\u306e\u6700\u9069\u5316<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-7\">PHP\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u306eRedis\u5b9f\u88c5\u624b\u9806<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-8\">Redis\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3068\u521d\u671f\u8a2d\u5b9a<\/a>      <\/li>      <li>        <a href=\"#i-9\">PHP\u3067\u306eRedis\u63a5\u7d9a\u8a2d\u5b9a<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-10\">\u57fa\u672c\u7684\u306aCRUD\u64cd\u4f5c\u306e\u5b9f\u88c5\u65b9\u6cd5<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-11\">Redis\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u8a2d\u8a08\u30d1\u30bf\u30fc\u30f3<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-12\">\u30ad\u30fc\u8a2d\u8a08\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/a>      <\/li>      <li>        <a href=\"#i-13\">\u30c7\u30fc\u30bf\u69cb\u9020\u306e\u9078\u629e\u57fa\u6e96<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-14\">\u6709\u52b9\u671f\u9650\u8a2d\u5b9a\u306e\u6226\u7565<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-15\">\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6700\u9069\u5316\u624b\u6cd5<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-16\">\u30e1\u30e2\u30ea\u7ba1\u7406\u306e\u6700\u9069\u5316\u624b\u6cd5<\/a>      <\/li>      <li>        <a href=\"#i-17\">\u6226\u7565\u7684\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u5b9f\u88c5<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-18\">\u8ca0\u8377\u5bfe\u7b56\u3068\u30b9\u30b1\u30fc\u30ea\u30f3\u30b0\u624b\u6cd5<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-19\">\u5b9f\u8df5\u7684\u306a\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-20\">\u30bb\u30c3\u30b7\u30e7\u30f3\u7ba1\u7406\u30b7\u30b9\u30c6\u30e0\u306e\u5b9f\u88c5<\/a>      <\/li>      <li>        <a href=\"#i-21\">\u9806\u4f4d\u30e9\u30f3\u30ad\u30f3\u30b0\u30b7\u30b9\u30c6\u30e0\u306e\u69cb\u7bc9<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-22\">\u30b8\u30e7\u30d6\u30ad\u30e5\u30fc\u30b7\u30b9\u30c6\u30e0\u306e\u958b\u767a<\/a>      <\/li>    <\/ul>  <\/li>  <li class=\"last\">    <a href=\"#i-23\">\u30c8\u30e9\u30d6\u30eb\u30b7\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0\u30ac\u30a4\u30c9<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-24\">\u4e00\u822c\u7684\u306a\u554f\u984c\u3068\u89e3\u6c7a\u65b9\u6cd5<\/a>      <\/li>      <li>        <a href=\"#i-25\">\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u76e3\u8996\u306e\u65b9\u6cd5<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-26\">\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3068\u5fa9\u65e7\u6226\u7565<\/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\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u306f<\/h2>\n\n\n\n<p>Redis\u306f\u3001\u201dRemote Dictionary Server\u201d\u306e\u7565\u3067\u3001\u9ad8\u6027\u80fd\u306a\u30a4\u30f3\u30e1\u30e2\u30ea\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u3057\u3066\u77e5\u3089\u308c\u3066\u3044\u307e\u3059\u3002\u5f93\u6765\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u306f\u7570\u306a\u308a\u3001\u4e3b\u306b\u30e1\u30e2\u30ea\u4e0a\u3067\u30c7\u30fc\u30bf\u3092\u7ba1\u7406\u3059\u308b\u3053\u3068\u3067\u3001\u8d85\u9ad8\u901f\u306a\u8aad\u307f\u66f8\u304d\u3092\u5b9f\u73fe\u3059\u308b\u65b0\u4e16\u4ee3\u306e\u30c7\u30fc\u30bf\u30b9\u30c8\u30a2\u3067\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-1\">\u5f93\u6765\u306eRDBMS\u3068\u306e\u6c7a\u5b9a\u7684\u306a\u9055\u3044<\/h3>\n\n\n\n<p>\u5f93\u6765\u306e\u30ea\u30ec\u30fc\u30b7\u30e7\u30ca\u30eb\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\uff08RDBMS\uff09\u3068Redis\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u672c\u8cea\u7684\u306a\u9055\u3044\u304c\u3042\u308a\u307e\u3059\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30c7\u30fc\u30bf\u306e\u4fdd\u5b58\u5834\u6240<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>RDBMS\uff1a\u4e3b\u306b\u30c7\u30a3\u30b9\u30af\u306b\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58<\/li>\n\n\n\n<li>Redis\uff1a\u4e3b\u306b\u30e1\u30e2\u30ea\u4e0a\u306b\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58\uff08\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u30c7\u30a3\u30b9\u30af\u306b\u3082\u4fdd\u5b58\u53ef\u80fd\uff09<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30c7\u30fc\u30bf\u69cb\u9020<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>RDBMS\uff1a\u30c6\u30fc\u30d6\u30eb\u3068\u3044\u3046\u4e8c\u6b21\u5143\u306e\u69cb\u9020\u3067\u30c7\u30fc\u30bf\u3092\u7ba1\u7406<\/li>\n\n\n\n<li>Redis\uff1a\u6587\u5b57\u5217\u3001\u30ea\u30b9\u30c8\u3001\u30cf\u30c3\u30b7\u30e5\u3001\u30bb\u30c3\u30c8\u3001\u30bd\u30fc\u30c8\u6e08\u307f\u30bb\u30c3\u30c8\u306a\u3069\u3001\u591a\u69d8\u306a\u30c7\u30fc\u30bf\u69cb\u9020\u3092\u30b5\u30dd\u30fc\u30c8<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u51e6\u7406<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>RDBMS\uff1aACID\u7279\u6027\u3092\u5b8c\u5168\u306b\u4fdd\u8a3c<\/li>\n\n\n\n<li>Redis\uff1a\u7c21\u6613\u7684\u306a\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u3092\u30b5\u30dd\u30fc\u30c8\uff08\u7279\u5b9a\u306e\u64cd\u4f5c\u306b\u9650\u5b9a\uff09<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30af\u30a8\u30ea\u8a00\u8a9e<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>RDBMS\uff1aSQL\uff08\u69cb\u9020\u5316\u554f\u3044\u5408\u308f\u305b\u8a00\u8a9e\uff09\u3092\u4f7f\u7528<\/li>\n\n\n\n<li>Redis\uff1a\u30b7\u30f3\u30d7\u30eb\u306a\u30b3\u30de\u30f3\u30c9\u30bb\u30c3\u30c8\u3092\u4f7f\u7528<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u7528\u9014\u306e\u6700\u9069\u5316<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>RDBMS\uff1a\u8907\u96d1\u306a\u30c7\u30fc\u30bf\u95a2\u4fc2\u306e\u7ba1\u7406\u3001\u5927\u898f\u6a21\u306a\u30c7\u30fc\u30bf\u306e\u6c38\u7d9a\u5316<\/li>\n\n\n\n<li>Redis\uff1a\u9ad8\u901f\u306a\u30c7\u30fc\u30bf\u30a2\u30af\u30bb\u30b9\u3001\u4e00\u6642\u7684\u306a\u30c7\u30fc\u30bf\u306e\u7ba1\u7406\u3001\u30ad\u30e3\u30c3\u30b7\u30e5<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-2\">\u306a\u305cPHP\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067Redis\u304c\u9078\u3070\u308c\u308b\u306e\u304b<\/h3>\n\n\n\n<p>PHP\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067Redis\u304c\u63a1\u7528\u3055\u308c\u308b\u4e3b\u306a\u7406\u7531\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30bb\u30c3\u30b7\u30e7\u30f3\u7ba1\u7406\u306e\u52b9\u7387\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=\"\">   \/\/ Redis\u3092\u30bb\u30c3\u30b7\u30e7\u30f3\u30cf\u30f3\u30c9\u30e9\u3068\u3057\u3066\u8a2d\u5b9a\n   ini_set('session.save_handler', 'redis');\n   ini_set('session.save_path', 'tcp:\/\/localhost:6379');<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u30ad\u30e3\u30c3\u30b7\u30e5\u30b7\u30b9\u30c6\u30e0\u3068\u3057\u3066\u306e\u512a\u4f4d\u6027<\/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=\"\">   \/\/ API\u30ec\u30b9\u30dd\u30f3\u30b9\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u4f8b\n   $redis = new Redis();\n   $redis-&gt;connect('127.0.0.1', 6379);\n\n   $cacheKey = 'api_response_' . $requestId;\n   if ($redis-&gt;exists($cacheKey)) {\n       return $redis-&gt;get($cacheKey);\n   }<\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30c7\u30fc\u30bf\u51e6\u7406<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30e6\u30fc\u30b6\u30fc\u30a2\u30af\u30c6\u30a3\u30d3\u30c6\u30a3\u306e\u8ffd\u8de1<\/li>\n\n\n\n<li>\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30e9\u30f3\u30ad\u30f3\u30b0\u306e\u5b9f\u88c5<\/li>\n\n\n\n<li>\u30e1\u30c3\u30bb\u30fc\u30b8\u30ad\u30e5\u30fc\u306e\u7ba1\u7406<\/li>\n<\/ul>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>\u30b9\u30b1\u30fc\u30e9\u30d3\u30ea\u30c6\u30a3\u306e\u78ba\u4fdd<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6c34\u5e73\u30b9\u30b1\u30fc\u30ea\u30f3\u30b0\u304c\u5bb9\u6613<\/li>\n\n\n\n<li>\u30de\u30b9\u30bf\u30fc\/\u30b9\u30ec\u30fc\u30d6\u69cb\u6210\u306e\u30b5\u30dd\u30fc\u30c8<\/li>\n\n\n\n<li>\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u6a5f\u80fd\u306e\u63d0\u4f9b<\/li>\n<\/ul>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>PHP\u3068\u306e\u89aa\u548c\u6027<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8c4a\u5bcc\u306aPHP\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30e9\u30a4\u30d6\u30e9\u30ea<\/li>\n\n\n\n<li>Laravel\u306a\u3069\u306e\u4e3b\u8981\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3068\u306e\u7d71\u5408<\/li>\n\n\n\n<li>\u30b7\u30f3\u30d7\u30eb\u306aAPI\u8a2d\u8a08<\/li>\n<\/ul>\n\n\n\n<p>Redis\u306f\u3001\u7279\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306aPHP\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u771f\u4fa1\u3092\u767a\u63ee\u3057\u307e\u3059\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9ad8\u30c8\u30e9\u30d5\u30a3\u30c3\u30af\u306eWeb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3<\/li>\n\n\n\n<li>\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u306e\u5206\u6790\u3084\u7d71\u8a08\u304c\u5fc5\u8981\u306a\u30b7\u30b9\u30c6\u30e0<\/li>\n\n\n\n<li>\u30de\u30a4\u30af\u30ed\u30b5\u30fc\u30d3\u30b9\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u3092\u63a1\u7528\u3057\u305f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8<\/li>\n\n\n\n<li>\u5927\u898f\u6a21\u306a\u30bb\u30c3\u30b7\u30e7\u30f3\u7ba1\u7406\u304c\u5fc5\u8981\u306a\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u306e\u3088\u3046\u306b\u3001Redis\u306fPHP\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u304a\u3044\u3066\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3001\u30b9\u30b1\u30fc\u30e9\u30d3\u30ea\u30c6\u30a3\u3001\u305d\u3057\u3066\u958b\u767a\u52b9\u7387\u306e\u5411\u4e0a\u306b\u5927\u304d\u304f\u8ca2\u732e\u3059\u308b\u91cd\u8981\u306a\u30c4\u30fc\u30eb\u3068\u3057\u3066\u4f4d\u7f6e\u3065\u3051\u3089\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-3\">Redis\u3092\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u3057\u3066\u4f7f\u7528\u3059\u308b\u30e1\u30ea\u30c3\u30c8<\/h2>\n\n\n\n<p>Redis\u3092\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u3057\u3066\u63a1\u7528\u3059\u308b\u969b\u306e\u4e3b\u8981\u306a\u30e1\u30ea\u30c3\u30c8\u3092\u3001\u5b9f\u969b\u306e\u4f7f\u7528\u30b7\u30fc\u30f3\u3068\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u30c7\u30fc\u30bf\u3092\u4ea4\u3048\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-4\">\u5727\u5012\u7684\u306a\u8aad\u307f\u53d6\u308a\/\u66f8\u304d\u8fbc\u307f\u901f\u5ea6<\/h3>\n\n\n\n<p>Redis\u306e\u6700\u5927\u306e\u7279\u5fb4\u306f\u3001\u305d\u306e\u5727\u5012\u7684\u306a\u51e6\u7406\u901f\u5ea6\u3067\u3059\u3002\u4ee5\u4e0b\u306b\u3001\u5178\u578b\u7684\u306a\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u3067\u306e\u6027\u80fd\u6bd4\u8f03\u3092\u793a\u3057\u307e\u3059\uff1a<\/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\u3067\u306e\u9ad8\u901f\u306a\u8aad\u307f\u53d6\u308a\/\u66f8\u304d\u8fbc\u307f\u4f8b\n$redis = new Redis();\n$redis-&gt;connect('127.0.0.1', 6379);\n\n\/\/ \u5358\u7d14\u306a\u6587\u5b57\u5217\u306e\u66f8\u304d\u8fbc\u307f\u3068\u8aad\u307f\u53d6\u308a\n$startTime = microtime(true);\nfor ($i = 0; $i &lt; 10000; $i++) {\n    $redis-&gt;set(\"key:$i\", \"value:$i\");\n}\n$writeTime = microtime(true) - $startTime;\n\n$startTime = microtime(true);\nfor ($i = 0; $i &lt; 10000; $i++) {\n    $value = $redis-&gt;get(\"key:$i\");\n}\n$readTime = microtime(true) - $startTime;<\/pre>\n\n\n\n<p>\u5178\u578b\u7684\u306a\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u7d50\u679c\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u66f8\u304d\u8fbc\u307f\u901f\u5ea6\uff1a\u7d04100,000\u64cd\u4f5c\/\u79d2<\/li>\n\n\n\n<li>\u8aad\u307f\u53d6\u308a\u901f\u5ea6\uff1a\u7d04150,000\u64cd\u4f5c\/\u79d2<\/li>\n\n\n\n<li>\u30ec\u30a4\u30c6\u30f3\u30b7\uff1a&lt; 1\u30df\u30ea\u79d2<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u308c\u306f\u5f93\u6765\u306eRDBMS\u3068\u6bd4\u8f03\u3057\u3066\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u512a\u4f4d\u6027\u304c\u3042\u308a\u307e\u3059\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30b7\u30f3\u30d7\u30eb\u306aKVS\u64cd\u4f5c\u3067\u7d0410\u500d\u306e\u901f\u5ea6\u5411\u4e0a<\/li>\n\n\n\n<li>\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u53c2\u7167\u3067\u7d045\u500d\u306e\u901f\u5ea6\u5411\u4e0a<\/li>\n\n\n\n<li>\u8907\u6570\u30ad\u30fc\u306e\u4e00\u62ec\u64cd\u4f5c\u3067\u7d043\u500d\u306e\u901f\u5ea6\u5411\u4e0a<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-5\">\u30b9\u30b1\u30fc\u30e9\u30d3\u30ea\u30c6\u30a3\u306e\u78ba\u4fdd\u304c\u7c21\u5358<\/h3>\n\n\n\n<p>Redis\u306e\u30b9\u30b1\u30fc\u30e9\u30d3\u30ea\u30c6\u30a3\u306f\u3001\u4ee5\u4e0b\u306e3\u3064\u306e\u65b9\u5f0f\u3067\u78ba\u4fdd\u3067\u304d\u307e\u3059\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30de\u30b9\u30bf\u30fc\/\u30b9\u30ec\u30fc\u30d6\u30ec\u30d7\u30ea\u30b1\u30fc\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=\"\">\/\/ \u30b9\u30ec\u30fc\u30d6\u30ce\u30fc\u30c9\u306e\u8a2d\u5b9a\u4f8b\n$redis-&gt;slaveof('master_host', 6379);\n\n\/\/ \u8aad\u307f\u53d6\u308a\u5c02\u7528\u30af\u30a8\u30ea\u306e\u5206\u6563\n$slaveNodes = ['slave1:6379', 'slave2:6379', 'slave3:6379'];\n$nodeIndex = array_rand($slaveNodes);\n$redis-&gt;connect($slaveNodes[$nodeIndex]);<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Redis Cluster<\/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=\"\">\/\/ \u30af\u30e9\u30b9\u30bf\u63a5\u7d9a\u306e\u8a2d\u5b9a\u4f8b\n$clusterNodes = [\n    'node1:6379',\n    'node2:6379',\n    'node3:6379'\n];\n\n$options = ['cluster' =&gt; 'redis'];\n$redis = new RedisCluster(NULL, $clusterNodes, 1.5, 1.5, true, $options);<\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Sentinel \u306b\u3088\u308b\u81ea\u52d5\u30d5\u30a7\u30a4\u30eb\u30aa\u30fc\u30d0\u30fc<\/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=\"\">\/\/ Sentinel\u3092\u4f7f\u7528\u3057\u305f\u9ad8\u53ef\u7528\u6027\u306e\u78ba\u4fdd\n$sentinel = new RedisSentinel('sentinel_host', 26379);\n$masterInfo = $sentinel-&gt;getMasterAddrByName('mymaster');\n$redis-&gt;connect($masterInfo[0], $masterInfo[1]);<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-6\">\u30e1\u30e2\u30ea\u4f7f\u7528\u52b9\u7387\u306e\u6700\u9069\u5316<\/h3>\n\n\n\n<p>Redis\u306f\u3001\u30e1\u30e2\u30ea\u4f7f\u7528\u52b9\u7387\u3092\u6700\u5927\u5316\u3059\u308b\u305f\u3081\u306e\u69d8\u3005\u306a\u6a5f\u80fd\u3092\u63d0\u4f9b\u3057\u307e\u3059\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30e1\u30e2\u30ea\u7ba1\u7406\u30dd\u30ea\u30b7\u30fc<\/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=\"\">\/\/ \u30e1\u30e2\u30ea\u30dd\u30ea\u30b7\u30fc\u306e\u8a2d\u5b9a\n$redis-&gt;config('SET', 'maxmemory-policy', 'allkeys-lru');\n$redis-&gt;config('SET', 'maxmemory', '1gb');<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u30c7\u30fc\u30bf\u5727\u7e2e\u6a5f\u80fd<\/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=\"\">\/\/ \u6587\u5b57\u5217\u306e\u5727\u7e2e\u4fdd\u5b58\n$redis-&gt;set('compressed_key', gzcompress($largeString));\n$originalString = gzuncompress($redis-&gt;get('compressed_key'));<\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>\u52b9\u7387\u7684\u306a\u30c7\u30fc\u30bf\u69cb\u9020<\/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=\"\">\/\/ \u30d3\u30c3\u30c8\u30de\u30c3\u30d7\u3092\u4f7f\u7528\u3057\u305f\u52b9\u7387\u7684\u306a\u30d5\u30e9\u30b0\u7ba1\u7406\n$redis-&gt;setBit('user_active', $userId, 1);\n$isActive = $redis-&gt;getBit('user_active', $userId);\n\n\/\/ HyperLogLog\u3092\u4f7f\u7528\u3057\u305f\u6982\u7b97\u30ab\u30a6\u30f3\u30c8\n$redis-&gt;pfadd('unique_visitors', $visitorId);\n$uniqueCount = $redis-&gt;pfcount('unique_visitors');<\/pre>\n\n\n\n<p>\u30e1\u30e2\u30ea\u4f7f\u7528\u52b9\u7387\u306e\u6700\u9069\u5316\u306b\u3088\u308a\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u52b9\u679c\u304c\u5f97\u3089\u308c\u307e\u3059\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u306e\u524a\u6e1b\uff1a\u901a\u5e38\u306eKey-Value\u65b9\u5f0f\u3068\u6bd4\u8f03\u3057\u306630-50%\u306e\u524a\u6e1b<\/li>\n\n\n\n<li>\u30b3\u30b9\u30c8\u52b9\u7387\u306e\u5411\u4e0a\uff1a\u5fc5\u8981\u306a\u30b5\u30fc\u30d0\u30fc\u30ea\u30bd\u30fc\u30b9\u306e\u524a\u6e1b<\/li>\n\n\n\n<li>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u5b89\u5b9a\u5316\uff1a\u30e1\u30e2\u30ea\u30b9\u30ef\u30c3\u30d7\u306e\u9632\u6b62<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u30e1\u30ea\u30c3\u30c8\u306f\u3001\u7279\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b1\u30fc\u30b9\u3067\u52b9\u679c\u3092\u767a\u63ee\u3057\u307e\u3059\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5927\u898f\u6a21\u30bb\u30c3\u30b7\u30e7\u30f3\u7ba1\u7406<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6570\u767e\u4e07\u30e6\u30fc\u30b6\u30fc\u306e\u30bb\u30c3\u30b7\u30e7\u30f3\u60c5\u5831\u3092\u52b9\u7387\u7684\u306b\u7ba1\u7406<\/li>\n\n\n\n<li>\u30bb\u30c3\u30b7\u30e7\u30f3\u306e\u6709\u52b9\u671f\u9650\u7ba1\u7406\u3092\u81ea\u52d5\u5316<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30e9\u30f3\u30ad\u30f3\u30b0<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30bd\u30fc\u30c8\u6e08\u307f\u30bb\u30c3\u30c8\u306b\u3088\u308b\u52b9\u7387\u7684\u306a\u30e9\u30f3\u30ad\u30f3\u30b0\u7ba1\u7406<\/li>\n\n\n\n<li>\u30b9\u30b3\u30a2\u306e\u66f4\u65b0\u3068\u9806\u4f4d\u306e\u53d6\u5f97\u3092\u5373\u6642\u306b\u5b9f\u884c<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30ad\u30e3\u30c3\u30b7\u30e5\u30b7\u30b9\u30c6\u30e0<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u983b\u7e41\u306b\u30a2\u30af\u30bb\u30b9\u3055\u308c\u308b\u30c7\u30fc\u30bf\u306e\u9ad8\u901f\u306a\u63d0\u4f9b<\/li>\n\n\n\n<li>\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u81ea\u52d5\u524a\u9664\u306b\u3088\u308b\u6700\u9069\u306a\u30e1\u30e2\u30ea\u4f7f\u7528<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u30e1\u30ea\u30c3\u30c8\u3092\u6700\u5927\u9650\u306b\u6d3b\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u9ad8\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3067\u52b9\u7387\u7684\u306a\u30b7\u30b9\u30c6\u30e0\u306e\u69cb\u7bc9\u304c\u53ef\u80fd\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-7\">PHP\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u306eRedis\u5b9f\u88c5\u624b\u9806<\/h2>\n\n\n\n<p>PHP\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067Redis\u3092\u5b9f\u88c5\u3059\u308b\u624b\u9806\u3092\u3001\u74b0\u5883\u69cb\u7bc9\u304b\u3089\u57fa\u672c\u7684\u306a\u64cd\u4f5c\u307e\u3067\u8a73\u3057\u304f\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-8\">Redis\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3068\u521d\u671f\u8a2d\u5b9a<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Redis\u30b5\u30fc\u30d0\u30fc\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/strong><\/li>\n<\/ol>\n\n\n\n<p>Ubuntu\/Debian\u306e\u5834\u5408\uff1a<\/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\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\nsudo apt update\nsudo apt install redis-server\n\n# \u30b5\u30fc\u30d3\u30b9\u306e\u8d77\u52d5\nsudo systemctl start redis-server\nsudo systemctl enable redis-server\n\n# \u52d5\u4f5c\u78ba\u8a8d\nredis-cli ping\n# \u671f\u5f85\u3055\u308c\u308b\u5fdc\u7b54: PONG<\/pre>\n\n\n\n<p>macOS\u306e\u5834\u5408\uff1a<\/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=\"\"># Homebrew\u3092\u4f7f\u7528\u3057\u305f\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\nbrew install redis\n\n# \u30b5\u30fc\u30d3\u30b9\u306e\u8d77\u52d5\nbrew services start redis<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u57fa\u672c\u7684\u306a\u8a2d\u5b9a\uff08redis.conf\uff09<\/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=\"\"># \u57fa\u672c\u8a2d\u5b9a\nport 6379\nbind 127.0.0.1\nmaxmemory 1gb\nmaxmemory-policy allkeys-lru\n\n# \u6c38\u7d9a\u5316\u8a2d\u5b9a\nsave 900 1\nsave 300 10\nsave 60 10000\n\n# \u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u8a2d\u5b9a\nrequirepass your_secure_password<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-9\">PHP\u3067\u306eRedis\u63a5\u7d9a\u8a2d\u5b9a<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>PHP Redis\u62e1\u5f35\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/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=\"\"># Ubuntu\/Debian\nsudo apt install php-redis\n\n# macOS\npecl install redis<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>composer.json\u3067\u306eRedis\u95a2\u9023\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u8ffd\u52a0<\/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=\"\">{\n    \"require\": {\n        \"predis\/predis\": \"^2.0\",\n        \"php-redis\/php-redis\": \"^5.3\"\n    }\n}<\/pre>\n\n\n\n<ol start=\"3\" 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=\"\">\/\/ \u30b7\u30f3\u30d7\u30eb\u306a\u63a5\u7d9a\ntry {\n    $redis = new Redis();\n    $redis-&gt;connect('127.0.0.1', 6379);\n    $redis-&gt;auth('your_secure_password');\n\n    \/\/ \u63a5\u7d9a\u30c6\u30b9\u30c8\n    if ($redis-&gt;ping()) {\n        echo \"Redis\u63a5\u7d9a\u6210\u529f\uff01\";\n    }\n} catch (RedisException $e) {\n    echo \"Redis\u63a5\u7d9a\u30a8\u30e9\u30fc: \" . $e-&gt;getMessage();\n}\n\n\/\/ \u30af\u30e9\u30b9\u3092\u4f7f\u7528\u3057\u305f\u63a5\u7d9a\u7ba1\u7406\nclass RedisConnection {\n    private static $instance = null;\n    private $redis;\n\n    private function __construct() {\n        $this-&gt;redis = new Redis();\n        $this-&gt;redis-&gt;connect('127.0.0.1', 6379);\n        $this-&gt;redis-&gt;auth('your_secure_password');\n    }\n\n    public static function getInstance() {\n        if (self::$instance === null) {\n            self::$instance = new self();\n        }\n        return self::$instance-&gt;redis;\n    }\n}\n\n\/\/ \u4f7f\u7528\u4f8b\n$redis = RedisConnection::getInstance();<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-10\">\u57fa\u672c\u7684\u306aCRUD\u64cd\u4f5c\u306e\u5b9f\u88c5\u65b9\u6cd5<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6587\u5b57\u5217\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=\"\">\/\/ \u4f5c\u6210\u3068\u66f4\u65b0\n$redis-&gt;set('user:name', 'John Doe');\n$redis-&gt;setex('session:token', 3600, 'abc123'); \/\/ \u6709\u52b9\u671f\u9650\u4ed8\u304d\n\n\/\/ \u8aad\u307f\u53d6\u308a\n$name = $redis-&gt;get('user:name');\n$exists = $redis-&gt;exists('user:name');\n\n\/\/ \u524a\u9664\n$redis-&gt;del('user:name');<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u30cf\u30c3\u30b7\u30e5\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=\"\">\/\/ \u30e6\u30fc\u30b6\u30fc\u30d7\u30ed\u30d5\u30a3\u30fc\u30eb\u306e\u4fdd\u5b58\n$redis-&gt;hMset('user:1', [\n    'name' =&gt; 'John Doe',\n    'email' =&gt; 'john@example.com',\n    'age' =&gt; 30\n]);\n\n\/\/ \u7279\u5b9a\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u53d6\u5f97\n$email = $redis-&gt;hGet('user:1', 'email');\n\n\/\/ \u5168\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u53d6\u5f97\n$profile = $redis-&gt;hGetAll('user:1');\n\n\/\/ \u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u524a\u9664\n$redis-&gt;hDel('user:1', 'age');<\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>\u30ea\u30b9\u30c8\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=\"\">\/\/ \u30bf\u30b9\u30af\u30ad\u30e5\u30fc\u306e\u5b9f\u88c5\u4f8b\n$redis-&gt;lPush('tasks', json_encode([\n    'id' =&gt; uniqid(),\n    'type' =&gt; 'email',\n    'data' =&gt; ['to' =&gt; 'user@example.com']\n]));\n\n\/\/ \u30bf\u30b9\u30af\u306e\u53d6\u5f97\n$task = $redis-&gt;rPop('tasks');\n\n\/\/ \u30ea\u30b9\u30c8\u306e\u9577\u3055\u53d6\u5f97\n$length = $redis-&gt;lLen('tasks');<\/pre>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li><strong>\u30bb\u30c3\u30c8\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=\"\">\/\/ \u30bf\u30b0\u4ed8\u3051\u30b7\u30b9\u30c6\u30e0\u306e\u5b9f\u88c5\u4f8b\n$redis-&gt;sAdd('article:1:tags', 'php', 'redis', 'database');\n$redis-&gt;sAdd('article:2:tags', 'php', 'mysql');\n\n\/\/ \u5171\u901a\u30bf\u30b0\u306e\u691c\u7d22\n$commonTags = $redis-&gt;sInter('article:1:tags', 'article:2:tags');\n\n\/\/ \u30bf\u30b0\u306e\u524a\u9664\n$redis-&gt;sRem('article:1:tags', 'database');<\/pre>\n\n\n\n<ol start=\"5\" class=\"wp-block-list\">\n<li><strong>\u30bd\u30fc\u30c8\u6e08\u307f\u30bb\u30c3\u30c8\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=\"\">\/\/ \u30e9\u30f3\u30ad\u30f3\u30b0\u30b7\u30b9\u30c6\u30e0\u306e\u5b9f\u88c5\u4f8b\n$redis-&gt;zAdd('leaderboard', [\n    'player1' =&gt; 100,\n    'player2' =&gt; 200,\n    'player3' =&gt; 150\n]);\n\n\/\/ \u30b9\u30b3\u30a2\u306e\u66f4\u65b0\n$redis-&gt;zIncrBy('leaderboard', 50, 'player1');\n\n\/\/ \u30e9\u30f3\u30ad\u30f3\u30b0\u306e\u53d6\u5f97\n$topPlayers = $redis-&gt;zRevRange('leaderboard', 0, 2, true);<\/pre>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u57fa\u672c\u64cd\u4f5c\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u69d8\u3005\u306a\u6a5f\u80fd\u3092\u5b9f\u88c5\u3067\u304d\u307e\u3059\u3002\u4f8b\u3048\u3070\uff1a<\/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=\"\">\/\/ \u30bb\u30c3\u30b7\u30e7\u30f3\u7ba1\u7406\u306e\u5b9f\u88c5\u4f8b\nclass RedisSession {\n    private $redis;\n    private $prefix = 'session:';\n\n    public function __construct(Redis $redis) {\n        $this-&gt;redis = $redis;\n    }\n\n    public function set($sessionId, $data, $ttl = 3600) {\n        $key = $this-&gt;prefix . $sessionId;\n        return $this-&gt;redis-&gt;setex($key, $ttl, json_encode($data));\n    }\n\n    public function get($sessionId) {\n        $key = $this-&gt;prefix . $sessionId;\n        $data = $this-&gt;redis-&gt;get($key);\n        return $data ? json_decode($data, true) : null;\n    }\n\n    public function destroy($sessionId) {\n        $key = $this-&gt;prefix . $sessionId;\n        return $this-&gt;redis-&gt;del($key);\n    }\n}<\/pre>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u5b9f\u88c5\u4f8b\u306f\u3001\u672c\u756a\u74b0\u5883\u3067\u4f7f\u7528\u3059\u308b\u524d\u306b\u9069\u5207\u306a\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3068\u30ed\u30b0\u8a18\u9332\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u3092\u304a\u52e7\u3081\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-11\">Redis\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u8a2d\u8a08\u30d1\u30bf\u30fc\u30f3<\/h2>\n\n\n\n<p>\u52b9\u7387\u7684\u306aRedis\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u8a2d\u8a08\u306b\u306f\u3001\u9069\u5207\u306a\u30ad\u30fc\u8a2d\u8a08\u3001\u30c7\u30fc\u30bf\u69cb\u9020\u306e\u9078\u629e\u3001\u6709\u52b9\u671f\u9650\u306e\u7ba1\u7406\u304c\u91cd\u8981\u3067\u3059\u3002\u3053\u3053\u3067\u306f\u3001\u5b9f\u8df5\u7684\u306a\u8a2d\u8a08\u30d1\u30bf\u30fc\u30f3\u3068\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u3092\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-12\">\u30ad\u30fc\u8a2d\u8a08\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/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=\"\">\/\/ \u63a8\u5968\u3055\u308c\u308b\u547d\u540d\u30d1\u30bf\u30fc\u30f3\n$keyPatterns = [\n    '\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u7684\u306a\u547d\u540d' =&gt; [\n        'user:{userId}:profile',     \/\/ \u30e6\u30fc\u30b6\u30fc\u30d7\u30ed\u30d5\u30a3\u30fc\u30eb\n        'user:{userId}:sessions',    \/\/ \u30e6\u30fc\u30b6\u30fc\u30bb\u30c3\u30b7\u30e7\u30f3\n        'post:{postId}:comments'     \/\/ \u6295\u7a3f\u306e\u30b3\u30e1\u30f3\u30c8\n    ],\n\n    '\u6a5f\u80fd\u5358\u4f4d\u3067\u306e\u547d\u540d' =&gt; [\n        'session:{sessionId}',       \/\/ \u30bb\u30c3\u30b7\u30e7\u30f3\u60c5\u5831\n        'cache:routes',              \/\/ \u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u30ad\u30e3\u30c3\u30b7\u30e5\n        'queue:mail'                 \/\/ \u30e1\u30fc\u30eb\u30ad\u30e5\u30fc\n    ]\n];\n\n\/\/ \u30ad\u30fc\u751f\u6210\u306e\u30d8\u30eb\u30d1\u30fc\u30af\u30e9\u30b9\nclass RedisKeyGenerator {\n    private $prefix;\n\n    public function __construct(string $prefix = '') {\n        $this-&gt;prefix = $prefix;\n    }\n\n    public function getUserKey(int $userId, string $type): string {\n        return sprintf('user:%d:%s', $userId, $type);\n    }\n\n    public function getCacheKey(string $type, string $identifier): string {\n        return sprintf('cache:%s:%s', $type, $identifier);\n    }\n}<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u30ad\u30fc\u306e\u9577\u3055\u3068\u69cb\u9020<\/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=\"\">\/\/ \u30ad\u30fc\u8a2d\u8a08\u306e\u4f8b\nclass RedisKeyManager {\n    private const MAX_KEY_LENGTH = 128;\n\n    public function createKey(array $parts): string {\n        $key = implode(':', $parts);\n\n        if (strlen($key) &gt; self::MAX_KEY_LENGTH) {\n            \/\/ \u9577\u3059\u304e\u308b\u30ad\u30fc\u306e\u51e6\u7406\n            $hash = md5(implode('', array_slice($parts, 1)));\n            $key = $parts[0] . ':' . $hash;\n        }\n\n        return $key;\n    }\n\n    public function parseKey(string $key): array {\n        return explode(':', $key);\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-13\">\u30c7\u30fc\u30bf\u69cb\u9020\u306e\u9078\u629e\u57fa\u6e96<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u7528\u9014\u306b\u5fdc\u3058\u305f\u9069\u5207\u306a\u30c7\u30fc\u30bf\u69cb\u9020\u306e\u9078\u629e<\/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 RedisDataStructureSelector {\n    private $redis;\n\n    public function __construct(Redis $redis) {\n        $this-&gt;redis = $redis;\n    }\n\n    \/\/ \u30e6\u30fc\u30b6\u30fc\u30d7\u30ed\u30d5\u30a3\u30fc\u30eb\uff08\u30cf\u30c3\u30b7\u30e5\uff09\n    public function storeUserProfile(int $userId, array $profile): void {\n        $key = \"user:$userId:profile\";\n        $this-&gt;redis-&gt;hMset($key, $profile);\n    }\n\n    \/\/ \u30a2\u30af\u30c6\u30a3\u30d3\u30c6\u30a3\u30ed\u30b0\uff08\u30ea\u30b9\u30c8\uff09\n    public function logActivity(int $userId, string $activity): void {\n        $key = \"user:$userId:activities\";\n        $this-&gt;redis-&gt;lPush($key, json_encode([\n            'timestamp' =&gt; time(),\n            'activity' =&gt; $activity\n        ]));\n        \/\/ \u30ea\u30b9\u30c8\u306e\u6700\u5927\u9577\u3092\u5236\u9650\n        $this-&gt;redis-&gt;lTrim($key, 0, 99);\n    }\n\n    \/\/ \u30e6\u30fc\u30b6\u30fc\u306e\u6a29\u9650\uff08\u30bb\u30c3\u30c8\uff09\n    public function assignPermissions(int $userId, array $permissions): void {\n        $key = \"user:$userId:permissions\";\n        $this-&gt;redis-&gt;sAdd($key, ...$permissions);\n    }\n\n    \/\/ \u30e9\u30f3\u30ad\u30f3\u30b0\uff08\u30bd\u30fc\u30c8\u6e08\u307f\u30bb\u30c3\u30c8\uff09\n    public function updateScore(int $userId, float $score): void {\n        $this-&gt;redis-&gt;zAdd('rankings', [$userId =&gt; $score]);\n    }\n}<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u30c7\u30fc\u30bf\u69cb\u9020\u9078\u629e\u306e\u30ac\u30a4\u30c9\u30e9\u30a4\u30f3<\/strong><\/li>\n<\/ol>\n\n\n<div id=\"id-cca150b9-6d77-422c-8189-8cb986225f9c\">\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u30c7\u30fc\u30bf\u578b<\/th><th>\u4f7f\u7528\u30b1\u30fc\u30b9<\/th><th>\u30e1\u30e2\u30ea\u52b9\u7387<\/th><th>\u64cd\u4f5c\u306e\u8907\u96d1\u3055<\/th><\/tr><\/thead><tbody><tr><td>\u6587\u5b57\u5217<\/td><td>\u30b7\u30f3\u30d7\u30eb\u306a\u5024\u3001\u30ad\u30e3\u30c3\u30b7\u30e5<\/td><td>\u9ad8<\/td><td>\u4f4e<\/td><\/tr><tr><td>\u30cf\u30c3\u30b7\u30e5<\/td><td>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3001\u8a2d\u5b9a<\/td><td>\u4e2d<\/td><td>\u4e2d<\/td><\/tr><tr><td>\u30ea\u30b9\u30c8<\/td><td>\u30ad\u30e5\u30fc\u3001\u6700\u65b0\u9805\u76ee<\/td><td>\u4e2d<\/td><td>\u4f4e<\/td><\/tr><tr><td>\u30bb\u30c3\u30c8<\/td><td>\u4e00\u610f\u306e\u5024\u306e\u96c6\u5408\u3001\u30bf\u30b0<\/td><td>\u4e2d<\/td><td>\u4e2d<\/td><\/tr><tr><td>\u30bd\u30fc\u30c8\u6e08\u307f\u30bb\u30c3\u30c8<\/td><td>\u30e9\u30f3\u30ad\u30f3\u30b0\u3001\u30b9\u30b3\u30a2\u7ba1\u7406<\/td><td>\u4f4e<\/td><td>\u9ad8<\/td><\/tr><\/tbody><\/table><\/figure>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"i-14\">\u6709\u52b9\u671f\u9650\u8a2d\u5b9a\u306e\u6226\u7565<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>TTL\uff08Time To Live\uff09\u306e\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 RedisTTLManager {\n    private $redis;\n    private $defaultTTL = 3600; \/\/ \u30c7\u30d5\u30a9\u30eb\u30c81\u6642\u9593\n\n    public function __construct(Redis $redis) {\n        $this-&gt;redis = $redis;\n    }\n\n    \/\/ \u52d5\u7684TTL\u306e\u8a08\u7b97\n    public function calculateTTL(string $type): int {\n        $ttlMap = [\n            'session' =&gt; 3600,      \/\/ \u30bb\u30c3\u30b7\u30e7\u30f3\uff1a1\u6642\u9593\n            'cache' =&gt; 300,         \/\/ \u30ad\u30e3\u30c3\u30b7\u30e5\uff1a5\u5206\n            'temporary' =&gt; 60       \/\/ \u4e00\u6642\u30c7\u30fc\u30bf\uff1a1\u5206\n        ];\n\n        return $ttlMap[$type] ?? $this-&gt;defaultTTL;\n    }\n\n    \/\/ TTL\u4ed8\u304d\u3067\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58\n    public function setWithTTL(string $key, $value, string $type): bool {\n        $ttl = $this-&gt;calculateTTL($type);\n\n        if (is_array($value)) {\n            $value = json_encode($value);\n        }\n\n        return $this-&gt;redis-&gt;setex($key, $ttl, $value);\n    }\n\n    \/\/ \u30d0\u30c3\u30c1\u51e6\u7406\u3067\u306e\u6709\u52b9\u671f\u9650\u66f4\u65b0\n    public function refreshExpiration(array $keys, string $type): void {\n        $ttl = $this-&gt;calculateTTL($type);\n        foreach ($keys as $key) {\n            $this-&gt;redis-&gt;expire($key, $ttl);\n        }\n    }\n}<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u6709\u52b9\u671f\u9650\u30d1\u30bf\u30fc\u30f3\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 RedisExpirationPatterns {\n    private $redis;\n\n    public function __construct(Redis $redis) {\n        $this-&gt;redis = $redis;\n    }\n\n    \/\/ \u6bb5\u968e\u7684\u306a\u6709\u52b9\u671f\u9650\u8a2d\u5b9a\n    public function setWithSlidingExpiration(string $key, $value, int $initialTTL, int $extendTTL): void {\n        \/\/ \u521d\u671f\u8a2d\u5b9a\n        $this-&gt;redis-&gt;setex($key, $initialTTL, $value);\n\n        \/\/ \u30a2\u30af\u30bb\u30b9\u6642\u306b\u6709\u52b9\u671f\u9650\u3092\u5ef6\u9577\n        $this-&gt;redis-&gt;expire($key, $extendTTL);\n    }\n\n    \/\/ \u30d0\u30c3\u30c1\u51e6\u7406\u7528\u306e\u6709\u52b9\u671f\u9650\u8a2d\u5b9a\n    public function setBatchExpiration(array $keys, int $ttl): void {\n        $pipe = $this-&gt;redis-&gt;multi(Redis::PIPELINE);\n        foreach ($keys as $key) {\n            $pipe-&gt;expire($key, $ttl);\n        }\n        $pipe-&gt;exec();\n    }\n}<\/pre>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u8a2d\u8a08\u30d1\u30bf\u30fc\u30f3\u3092\u9069\u5207\u306b\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u5229\u70b9\u304c\u5f97\u3089\u308c\u307e\u3059\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u4fdd\u5b88\u6027\u306e\u5411\u4e0a<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4e00\u8cab\u3057\u305f\u547d\u540d\u898f\u5247\u306b\u3088\u308b\u53ef\u8aad\u6027\u306e\u5411\u4e0a<\/li>\n\n\n\n<li>\u69cb\u9020\u5316\u3055\u308c\u305f\u30c7\u30fc\u30bf\u30a2\u30af\u30bb\u30b9\u30d1\u30bf\u30fc\u30f3<\/li>\n\n\n\n<li>\u52b9\u7387\u7684\u306a\u30e1\u30e2\u30ea\u4f7f\u7528<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u6700\u9069\u5316<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9069\u5207\u306a\u30c7\u30fc\u30bf\u69cb\u9020\u306e\u9078\u629e\u306b\u3088\u308b\u51e6\u7406\u52b9\u7387\u306e\u5411\u4e0a<\/li>\n\n\n\n<li>\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u52b9\u679c\u7684\u306a\u6d3b\u7528<\/li>\n\n\n\n<li>\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u306e\u6700\u9069\u5316<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30b9\u30b1\u30fc\u30e9\u30d3\u30ea\u30c6\u30a3\u306e\u78ba\u4fdd<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u52b9\u7387\u7684\u306a\u30ad\u30fc\u5206\u6563<\/li>\n\n\n\n<li>\u9069\u5207\u306a\u30e1\u30e2\u30ea\u7ba1\u7406<\/li>\n\n\n\n<li>\u67d4\u8edf\u306a\u62e1\u5f35\u6027<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-15\">\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6700\u9069\u5316\u624b\u6cd5<\/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\u6700\u9069\u5316\u624b\u6cd5\u3092\u3001\u5b9f\u88c5\u4f8b\u3068\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u30c7\u30fc\u30bf\u3068\u5171\u306b\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-16\">\u30e1\u30e2\u30ea\u7ba1\u7406\u306e\u6700\u9069\u5316\u624b\u6cd5<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u306e\u76e3\u8996\u3068\u5206\u6790<\/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 RedisMemoryAnalyzer {\n    private $redis;\n\n    public function __construct(Redis $redis) {\n        $this-&gt;redis = $redis;\n    }\n\n    \/\/ \u30e1\u30e2\u30ea\u4f7f\u7528\u72b6\u6cc1\u306e\u5206\u6790\n    public function analyzeMemoryUsage(): array {\n        $info = $this-&gt;redis-&gt;info('memory');\n\n        return [\n            'used_memory_human' =&gt; $info['used_memory_human'],\n            'used_memory_peak_human' =&gt; $info['used_memory_peak_human'],\n            'used_memory_lua_human' =&gt; $info['used_memory_lua_human'],\n            'mem_fragmentation_ratio' =&gt; $info['mem_fragmentation_ratio']\n        ];\n    }\n\n    \/\/ \u30ad\u30fc\u306e\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u3092\u78ba\u8a8d\n    public function getKeyMemoryUsage(string $key): int {\n        return $this-&gt;redis-&gt;execute('MEMORY', ['USAGE', $key]);\n    }\n\n    \/\/ \u5927\u304d\u306a\u30ad\u30fc\u306e\u691c\u51fa\n    public function findLargeKeys(int $sampleSize = 1000): array {\n        $largeKeys = [];\n        $keys = $this-&gt;redis-&gt;scan(0, ['COUNT' =&gt; $sampleSize]);\n\n        foreach ($keys as $key) {\n            $size = $this-&gt;getKeyMemoryUsage($key);\n            if ($size &gt; 1024 * 1024) { \/\/ 1MB\u4ee5\u4e0a\u306e\u30ad\u30fc\n                $largeKeys[$key] = $size;\n            }\n        }\n\n        return $largeKeys;\n    }\n}<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u30e1\u30e2\u30ea\u6700\u9069\u5316\u306e\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 RedisMemoryOptimizer {\n    private $redis;\n\n    public function __construct(Redis $redis) {\n        $this-&gt;redis = $redis;\n    }\n\n    \/\/ \u6587\u5b57\u5217\u306e\u5727\u7e2e\u4fdd\u5b58\n    public function setCompressed(string $key, string $value, int $ttl = 0): bool {\n        $compressed = gzcompress($value, 9);\n        return $ttl &gt; 0 \n            ? $this-&gt;redis-&gt;setex($key, $ttl, $compressed)\n            : $this-&gt;redis-&gt;set($key, $compressed);\n    }\n\n    \/\/ \u5727\u7e2e\u30c7\u30fc\u30bf\u306e\u53d6\u5f97\n    public function getCompressed(string $key): ?string {\n        $value = $this-&gt;redis-&gt;get($key);\n        return $value ? gzuncompress($value) : null;\n    }\n\n    \/\/ \u30cf\u30c3\u30b7\u30e5\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u6700\u9069\u5316\n    public function optimizeHash(string $key): void {\n        \/\/ \u5c0f\u3055\u306a\u30cf\u30c3\u30b7\u30e5\u306fziplist\u3068\u3057\u3066\u4fdd\u5b58\n        $this-&gt;redis-&gt;configure(['hash-max-ziplist-entries' =&gt; 512]);\n        $this-&gt;redis-&gt;configure(['hash-max-ziplist-value' =&gt; 64]);\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-17\">\u6226\u7565\u7684\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u5b9f\u88c5<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u591a\u5c64\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 MultiLevelCache {\n    private $redis;\n    private $localCache = [];\n\n    public function __construct(Redis $redis) {\n        $this-&gt;redis = $redis;\n    }\n\n    \/\/ \u591a\u5c64\u30ad\u30e3\u30c3\u30b7\u30e5\u304b\u3089\u306e\u8aad\u307f\u53d6\u308a\n    public function get(string $key) {\n        \/\/ L1: \u30ed\u30fc\u30ab\u30eb\u30ad\u30e3\u30c3\u30b7\u30e5\n        if (isset($this-&gt;localCache[$key])) {\n            return $this-&gt;localCache[$key];\n        }\n\n        \/\/ L2: Redis\u30ad\u30e3\u30c3\u30b7\u30e5\n        $value = $this-&gt;redis-&gt;get($key);\n        if ($value !== false) {\n            $this-&gt;localCache[$key] = $value;\n            return $value;\n        }\n\n        return null;\n    }\n\n    \/\/ \u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u66f4\u65b0\n    public function set(string $key, $value, int $ttl = 3600): void {\n        \/\/ L1\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u66f4\u65b0\n        $this-&gt;localCache[$key] = $value;\n\n        \/\/ L2\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u66f4\u65b0\n        $this-&gt;redis-&gt;setex($key, $ttl, $value);\n    }\n}<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u30ad\u30e3\u30c3\u30b7\u30e5\u30a6\u30a9\u30fc\u30df\u30f3\u30b0\u6226\u7565<\/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 CacheWarmer {\n    private $redis;\n\n    public function __construct(Redis $redis) {\n        $this-&gt;redis = $redis;\n    }\n\n    \/\/ \u4e88\u6e2c\u7684\u30ad\u30e3\u30c3\u30b7\u30e5\u30a6\u30a9\u30fc\u30df\u30f3\u30b0\n    public function warmupCache(array $keys, callable $dataFetcher): void {\n        $pipe = $this-&gt;redis-&gt;multi(Redis::PIPELINE);\n\n        foreach ($keys as $key) {\n            if (!$this-&gt;redis-&gt;exists($key)) {\n                $data = $dataFetcher($key);\n                $pipe-&gt;setex($key, 3600, serialize($data));\n            }\n        }\n\n        $pipe-&gt;exec();\n    }\n\n    \/\/ \u30d0\u30c3\u30c1\u30ad\u30e3\u30c3\u30b7\u30e5\u66f4\u65b0\n    public function batchUpdate(array $keyValuePairs, int $ttl = 3600): void {\n        $pipe = $this-&gt;redis-&gt;multi(Redis::PIPELINE);\n\n        foreach ($keyValuePairs as $key =&gt; $value) {\n            $pipe-&gt;setex($key, $ttl, serialize($value));\n        }\n\n        $pipe-&gt;exec();\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-18\">\u8ca0\u8377\u5bfe\u7b56\u3068\u30b9\u30b1\u30fc\u30ea\u30f3\u30b0\u624b\u6cd5<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u8ca0\u8377\u5206\u6563\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 RedisLoadBalancer {\n    private $nodes = [];\n    private $weights = [];\n\n    public function addNode(Redis $redis, int $weight = 1): void {\n        $this-&gt;nodes[] = $redis;\n        $this-&gt;weights[] = $weight;\n    }\n\n    \/\/ \u4e00\u8cab\u6027\u30cf\u30c3\u30b7\u30e5\u306b\u3088\u308b\u30ce\u30fc\u30c9\u9078\u629e\n    public function getNode(string $key): Redis {\n        $hash = crc32($key);\n        $totalWeight = array_sum($this-&gt;weights);\n        $target = $hash % $totalWeight;\n\n        $currentWeight = 0;\n        foreach ($this-&gt;nodes as $index =&gt; $node) {\n            $currentWeight += $this-&gt;weights[$index];\n            if ($target &lt; $currentWeight) {\n                return $node;\n            }\n        }\n\n        return $this-&gt;nodes[0];\n    }\n}<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u30d0\u30c3\u30af\u30d7\u30ec\u30c3\u30b7\u30e3\u30fc\u5236\u5fa1<\/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 RedisBackPressure {\n    private $redis;\n    private $maxQueueSize;\n    private $windowSize;\n\n    public function __construct(Redis $redis, int $maxQueueSize = 1000, int $windowSize = 60) {\n        $this-&gt;redis = $redis;\n        $this-&gt;maxQueueSize = $maxQueueSize;\n        $this-&gt;windowSize = $windowSize;\n    }\n\n    \/\/ \u30ec\u30fc\u30c8\u5236\u9650\u306e\u5b9f\u88c5\n    public function isAllowed(string $key): bool {\n        $current = $this-&gt;redis-&gt;incr($key);\n        if ($current === 1) {\n            $this-&gt;redis-&gt;expire($key, $this-&gt;windowSize);\n        }\n\n        return $current &lt;= $this-&gt;maxQueueSize;\n    }\n\n    \/\/ \u30ad\u30e5\u30fc\u5236\u5fa1\n    public function enqueue(string $queue, $data): bool {\n        $queueLength = $this-&gt;redis-&gt;lLen($queue);\n\n        if ($queueLength &gt;= $this-&gt;maxQueueSize) {\n            return false;\n        }\n\n        $this-&gt;redis-&gt;rPush($queue, serialize($data));\n        return true;\n    }\n}<\/pre>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u6700\u9069\u5316\u624b\u6cd5\u3092\u9069\u7528\u3057\u305f\u5834\u5408\u306e\u5178\u578b\u7684\u306a\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6539\u5584\u52b9\u679c\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30e1\u30e2\u30ea\u6700\u9069\u5316<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5727\u7e2e\u306b\u3088\u308b\u4fdd\u5b58\u5bb9\u91cf\uff1a40-60%\u524a\u6e1b<\/li>\n\n\n\n<li>\u30e1\u30e2\u30ea\u30d5\u30e9\u30b0\u30e1\u30f3\u30c6\u30fc\u30b7\u30e7\u30f3\uff1a30%\u4ee5\u4e0a\u6539\u5584<\/li>\n\n\n\n<li>\u30ad\u30fc\u30b5\u30a4\u30ba\u306e\u6700\u9069\u5316\uff1a20-40%\u306e\u5bb9\u91cf\u524a\u6e1b<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30ec\u30b9\u30dd\u30f3\u30b9\u30bf\u30a4\u30e0\u6539\u5584<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u591a\u5c64\u30ad\u30e3\u30c3\u30b7\u30e5\uff1a\u30ec\u30a4\u30c6\u30f3\u30b750-70%\u6539\u5584<\/li>\n\n\n\n<li>\u30d1\u30a4\u30d7\u30e9\u30a4\u30f3\u51e6\u7406\uff1a\u30b9\u30eb\u30fc\u30d7\u30c3\u30c83-5\u500d\u5411\u4e0a<\/li>\n\n\n\n<li>\u8ca0\u8377\u5206\u6563\uff1a\u5168\u4f53\u7684\u306a\u30ec\u30b9\u30dd\u30f3\u30b9\u6642\u959330-50%\u6539\u5584<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30b9\u30b1\u30fc\u30e9\u30d3\u30ea\u30c6\u30a3\u5411\u4e0a<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6c34\u5e73\u30b9\u30b1\u30fc\u30ea\u30f3\u30b0\uff1a\u307b\u307c\u7dda\u5f62\u7684\u306a\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u5411\u4e0a<\/li>\n\n\n\n<li>\u30d0\u30c3\u30af\u30d7\u30ec\u30c3\u30b7\u30e3\u30fc\u5236\u5fa1\uff1a\u30b7\u30b9\u30c6\u30e0\u5b89\u5b9a\u6027\u306e\u5927\u5e45\u6539\u5584<\/li>\n\n\n\n<li>\u30ad\u30e3\u30c3\u30b7\u30e5\u30a6\u30a9\u30fc\u30df\u30f3\u30b0\uff1a\u30b3\u30fc\u30eb\u30c9\u30b9\u30bf\u30fc\u30c8\u6642\u959390%\u524a\u6e1b<\/li>\n<\/ul>\n\n\n\n<p>\u6700\u9069\u5316\u3092\u5b9f\u65bd\u3059\u308b\u969b\u306e\u91cd\u8981\u306a\u30dd\u30a4\u30f3\u30c8\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u76e3\u8996\u3068\u8a08\u6e2c<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5b9a\u671f\u7684\u306a\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u8a08\u6e2c<\/li>\n\n\n\n<li>\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u306e\u7d99\u7d9a\u7684\u306a\u76e3\u8996<\/li>\n\n\n\n<li>\u30dc\u30c8\u30eb\u30cd\u30c3\u30af\u306e\u65e9\u671f\u767a\u898b<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6bb5\u968e\u7684\u306a\u6700\u9069\u5316<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6700\u3082\u52b9\u679c\u306e\u9ad8\u3044\u90e8\u5206\u304b\u3089\u7740\u624b<\/li>\n\n\n\n<li>A\/B\u30c6\u30b9\u30c8\u306b\u3088\u308b\u52b9\u679c\u691c\u8a3c<\/li>\n\n\n\n<li>\u7d99\u7d9a\u7684\u306a\u6539\u5584\u30b5\u30a4\u30af\u30eb\u306e\u78ba\u7acb<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30d0\u30e9\u30f3\u30b9\u306e\u53d6\u308c\u305f\u8a2d\u8a08<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u3068\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u30c8\u30ec\u30fc\u30c9\u30aa\u30d5<\/li>\n\n\n\n<li>\u8907\u96d1\u6027\u3068\u4fdd\u5b88\u6027\u306e\u30d0\u30e9\u30f3\u30b9<\/li>\n\n\n\n<li>\u30b3\u30b9\u30c8\u3068\u52b9\u679c\u306e\u9069\u5207\u306a\u5224\u65ad<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-19\">\u5b9f\u8df5\u7684\u306a\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9<\/h2>\n\n\n\n<p>Redis\u306e\u5b9f\u8df5\u7684\u306a\u6d3b\u7528\u65b9\u6cd5\u3092\u3001\u5177\u4f53\u7684\u306a\u5b9f\u88c5\u4f8b\u3068\u3068\u3082\u306b\u89e3\u8aac\u3057\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u3001\u5b9f\u969b\u306e\u30d3\u30b8\u30cd\u30b9\u30b7\u30fc\u30f3\u3067\u3088\u304f\u4f7f\u7528\u3055\u308c\u308b3\u3064\u306e\u4e3b\u8981\u306a\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u3092\u8a73\u3057\u304f\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-20\">\u30bb\u30c3\u30b7\u30e7\u30f3\u7ba1\u7406\u30b7\u30b9\u30c6\u30e0\u306e\u5b9f\u88c5<\/h3>\n\n\n\n<p>\u9ad8\u30c8\u30e9\u30d5\u30a3\u30c3\u30afWeb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u306e\u30bb\u30c3\u30b7\u30e7\u30f3\u7ba1\u7406\u3092Redis\u3067\u5b9f\u88c5\u3059\u308b\u4f8b\u3092\u793a\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=\"\">class RedisSessionHandler implements SessionHandlerInterface\n{\n    private $redis;\n    private $prefix;\n    private $ttl;\n\n    public function __construct(Redis $redis, string $prefix = 'session:', int $ttl = 3600)\n    {\n        $this-&gt;redis = $redis;\n        $this-&gt;prefix = $prefix;\n        $this-&gt;ttl = $ttl;\n    }\n\n    public function open($path, $name): bool\n    {\n        return true;\n    }\n\n    public function close(): bool\n    {\n        return true;\n    }\n\n    public function read($id): string\n    {\n        $data = $this-&gt;redis-&gt;get($this-&gt;prefix . $id);\n        return $data === false ? '' : $data;\n    }\n\n    public function write($id, $data): bool\n    {\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    {\n        $this-&gt;redis-&gt;del($this-&gt;prefix . $id);\n        return true;\n    }\n\n    public function gc($maxlifetime): bool\n    {\n        return true; \/\/ Redis\u304c\u81ea\u52d5\u7684\u306b\u671f\u9650\u5207\u308c\u306e\u30ad\u30fc\u3092\u524a\u9664\n    }\n}\n\n\/\/ \u4f7f\u7528\u4f8b\nclass SessionManager\n{\n    private $redis;\n    private $handler;\n\n    public function __construct(Redis $redis)\n    {\n        $this-&gt;redis = $redis;\n        $this-&gt;handler = new RedisSessionHandler($redis);\n\n        \/\/ \u30bb\u30c3\u30b7\u30e7\u30f3\u30cf\u30f3\u30c9\u30e9\u306e\u767b\u9332\n        session_set_save_handler($this-&gt;handler, true);\n    }\n\n    \/\/ \u30a2\u30af\u30c6\u30a3\u30d6\u30bb\u30c3\u30b7\u30e7\u30f3\u6570\u306e\u53d6\u5f97\n    public function getActiveSessionCount(): int\n    {\n        return $this-&gt;redis-&gt;dbSize();\n    }\n\n    \/\/ \u7279\u5b9a\u30e6\u30fc\u30b6\u30fc\u306e\u30bb\u30c3\u30b7\u30e7\u30f3\u3092\u7121\u52b9\u5316\n    public function invalidateUserSessions(int $userId): void\n    {\n        $pattern = \"session:user:{$userId}:*\";\n        $keys = $this-&gt;redis-&gt;keys($pattern);\n\n        if (!empty($keys)) {\n            $this-&gt;redis-&gt;del($keys);\n        }\n    }\n\n    \/\/ \u30bb\u30c3\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf\u306e\u5206\u6790\n    public function analyzeSessionStats(): array\n    {\n        $totalSessions = $this-&gt;getActiveSessionCount();\n        $sessions = $this-&gt;redis-&gt;keys('session:*');\n\n        $stats = [\n            'total_sessions' =&gt; $totalSessions,\n            'average_size' =&gt; 0,\n            'expiry_distribution' =&gt; []\n        ];\n\n        foreach ($sessions as $session) {\n            $ttl = $this-&gt;redis-&gt;ttl($session);\n            $size = strlen($this-&gt;redis-&gt;get($session));\n\n            $stats['average_size'] += $size;\n            $stats['expiry_distribution'][floor($ttl \/ 600)] ??= 0;\n            $stats['expiry_distribution'][floor($ttl \/ 600)]++;\n        }\n\n        if ($totalSessions &gt; 0) {\n            $stats['average_size'] \/= $totalSessions;\n        }\n\n        return $stats;\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-21\">\u9806\u4f4d\u30e9\u30f3\u30ad\u30f3\u30b0\u30b7\u30b9\u30c6\u30e0\u306e\u69cb\u7bc9<\/h3>\n\n\n\n<p>\u30b2\u30fc\u30e0\u3084\u30b3\u30f3\u30c6\u30b9\u30c8\u306a\u3069\u3067\u306e\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30e9\u30f3\u30ad\u30f3\u30b0\u30b7\u30b9\u30c6\u30e0\u306e\u5b9f\u88c5\u4f8b\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=\"\">class RankingSystem\n{\n    private $redis;\n    private const RANKING_KEY = 'rankings:';\n    private const DAILY_RANKING_KEY = 'daily_rankings:';\n\n    public function __construct(Redis $redis)\n    {\n        $this-&gt;redis = $redis;\n    }\n\n    \/\/ \u30b9\u30b3\u30a2\u306e\u66f4\u65b0\n    public function updateScore(int $userId, float $score, string $gameId = 'default'): void\n    {\n        $key = self::RANKING_KEY . $gameId;\n        $dailyKey = self::DAILY_RANKING_KEY . date('Y-m-d') . ':' . $gameId;\n\n        $pipe = $this-&gt;redis-&gt;multi(Redis::PIPELINE);\n\n        \/\/ \u5168\u4f53\u30e9\u30f3\u30ad\u30f3\u30b0\u306e\u66f4\u65b0\n        $pipe-&gt;zAdd($key, ['score' =&gt; $score, 'member' =&gt; $userId]);\n\n        \/\/ \u65e5\u6b21\u30e9\u30f3\u30ad\u30f3\u30b0\u306e\u66f4\u65b0\n        $pipe-&gt;zAdd($dailyKey, ['score' =&gt; $score, 'member' =&gt; $userId]);\n\n        \/\/ \u65e5\u6b21\u30e9\u30f3\u30ad\u30f3\u30b0\u306e\u6709\u52b9\u671f\u9650\u8a2d\u5b9a\uff082\u65e5\u9593\uff09\n        $pipe-&gt;expire($dailyKey, 172800);\n\n        $pipe-&gt;exec();\n    }\n\n    \/\/ \u30e9\u30f3\u30ad\u30f3\u30b0\u306e\u53d6\u5f97\n    public function getRanking(string $gameId = 'default', int $start = 0, int $limit = 10): array\n    {\n        $key = self::RANKING_KEY . $gameId;\n\n        \/\/ \u30b9\u30b3\u30a2\u4ed8\u304d\u3067\u30e9\u30f3\u30ad\u30f3\u30b0\u3092\u53d6\u5f97\n        $rankings = $this-&gt;redis-&gt;zRevRangeByScore(\n            $key,\n            '+inf',\n            '-inf',\n            [\n                'withscores' =&gt; true,\n                'limit' =&gt; [$start, $limit]\n            ]\n        );\n\n        \/\/ \u30e6\u30fc\u30b6\u30fc\u60c5\u5831\u306e\u53d6\u5f97\n        $result = [];\n        foreach ($rankings as $userId =&gt; $score) {\n            $result[] = [\n                'user_id' =&gt; $userId,\n                'score' =&gt; $score,\n                'rank' =&gt; $this-&gt;redis-&gt;zRevRank($key, $userId) + 1\n            ];\n        }\n\n        return $result;\n    }\n\n    \/\/ \u30e6\u30fc\u30b6\u30fc\u306e\u9806\u4f4d\u53d6\u5f97\n    public function getUserRank(int $userId, string $gameId = 'default'): ?array\n    {\n        $key = self::RANKING_KEY . $gameId;\n        $rank = $this-&gt;redis-&gt;zRevRank($key, $userId);\n\n        if ($rank === false) {\n            return null;\n        }\n\n        return [\n            'rank' =&gt; $rank + 1,\n            'score' =&gt; $this-&gt;redis-&gt;zScore($key, $userId)\n        ];\n    }\n\n    \/\/ \u7bc4\u56f2\u5185\u306e\u30e6\u30fc\u30b6\u30fc\u306e\u30e9\u30f3\u30ad\u30f3\u30b0\u53d6\u5f97\n    public function getRankingAroundUser(\n        int $userId,\n        string $gameId = 'default',\n        int $range = 5\n    ): array {\n        $key = self::RANKING_KEY . $gameId;\n        $rank = $this-&gt;redis-&gt;zRevRank($key, $userId);\n\n        if ($rank === false) {\n            return [];\n        }\n\n        $start = max(0, $rank - $range);\n        $end = $rank + $range;\n\n        return $this-&gt;redis-&gt;zRevRange($key, $start, $end, true);\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-22\">\u30b8\u30e7\u30d6\u30ad\u30e5\u30fc\u30b7\u30b9\u30c6\u30e0\u306e\u958b\u767a<\/h3>\n\n\n\n<p>\u975e\u540c\u671f\u51e6\u7406\u306e\u305f\u3081\u306e\u30b8\u30e7\u30d6\u30ad\u30e5\u30fc\u30b7\u30b9\u30c6\u30e0\u306e\u5b9f\u88c5\u4f8b\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=\"\">class RedisJobQueue\n{\n    private $redis;\n    private const QUEUE_KEY = 'queue:';\n    private const PROCESSING_KEY = 'processing:';\n    private const FAILED_KEY = 'failed:';\n\n    public function __construct(Redis $redis)\n    {\n        $this-&gt;redis = $redis;\n    }\n\n    \/\/ \u30b8\u30e7\u30d6\u306e\u8ffd\u52a0\n    public function enqueue(string $queue, array $job): string\n    {\n        $jobId = uniqid('job:', true);\n        $job['id'] = $jobId;\n        $job['created_at'] = time();\n\n        $this-&gt;redis-&gt;lPush(\n            self::QUEUE_KEY . $queue,\n            json_encode($job)\n        );\n\n        return $jobId;\n    }\n\n    \/\/ \u30b8\u30e7\u30d6\u306e\u53d6\u5f97\u3068\u51e6\u7406\n    public function dequeue(string $queue, int $timeout = 0): ?array\n    {\n        $job = $this-&gt;redis-&gt;brPop([self::QUEUE_KEY . $queue], $timeout);\n\n        if (!$job) {\n            return null;\n        }\n\n        $jobData = json_decode($job[1], true);\n\n        \/\/ \u51e6\u7406\u4e2d\u306e\u30b8\u30e7\u30d6\u3068\u3057\u3066\u8a18\u9332\n        $this-&gt;redis-&gt;setex(\n            self::PROCESSING_KEY . $jobData['id'],\n            3600, \/\/ 1\u6642\u9593\u306e\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\n            json_encode($jobData)\n        );\n\n        return $jobData;\n    }\n\n    \/\/ \u30b8\u30e7\u30d6\u306e\u5b8c\u4e86\n    public function complete(string $jobId): void\n    {\n        $this-&gt;redis-&gt;del(self::PROCESSING_KEY . $jobId);\n    }\n\n    \/\/ \u30b8\u30e7\u30d6\u306e\u5931\u6557\n    public function fail(string $jobId, string $error): void\n    {\n        $job = $this-&gt;redis-&gt;get(self::PROCESSING_KEY . $jobId);\n\n        if ($job) {\n            $jobData = json_decode($job, true);\n            $jobData['error'] = $error;\n            $jobData['failed_at'] = time();\n\n            $this-&gt;redis-&gt;lPush(\n                self::FAILED_KEY,\n                json_encode($jobData)\n            );\n\n            $this-&gt;redis-&gt;del(self::PROCESSING_KEY . $jobId);\n        }\n    }\n\n    \/\/ \u30ad\u30e5\u30fc\u306e\u72b6\u614b\u76e3\u8996\n    public function getQueueStats(string $queue): array\n    {\n        $queueKey = self::QUEUE_KEY . $queue;\n        $processingPattern = self::PROCESSING_KEY . '*';\n\n        return [\n            'queued' =&gt; $this-&gt;redis-&gt;lLen($queueKey),\n            'processing' =&gt; count($this-&gt;redis-&gt;keys($processingPattern)),\n            'failed' =&gt; $this-&gt;redis-&gt;lLen(self::FAILED_KEY)\n        ];\n    }\n\n    \/\/ \u5931\u6557\u3057\u305f\u30b8\u30e7\u30d6\u306e\u518d\u8a66\u884c\n    public function retryFailed(int $limit = 10): int\n    {\n        $retried = 0;\n\n        for ($i = 0; $i &lt; $limit; $i++) {\n            $job = $this-&gt;redis-&gt;lPop(self::FAILED_KEY);\n\n            if (!$job) {\n                break;\n            }\n\n            $jobData = json_decode($job, true);\n            unset($jobData['error'], $jobData['failed_at']);\n\n            $this-&gt;enqueue($jobData['queue'], $jobData);\n            $retried++;\n        }\n\n        return $retried;\n    }\n}\n\n\/\/ \u4f7f\u7528\u4f8b\n$queue = new RedisJobQueue($redis);\n\n\/\/ \u30b8\u30e7\u30d6\u306e\u767b\u9332\n$jobId = $queue-&gt;enqueue('emails', [\n    'type' =&gt; 'welcome_email',\n    'user_id' =&gt; 123,\n    'data' =&gt; [\n        'email' =&gt; 'user@example.com',\n        'name' =&gt; 'John Doe'\n    ]\n]);\n\n\/\/ \u30ef\u30fc\u30ab\u30fc\u30d7\u30ed\u30bb\u30b9\u3067\u306e\u51e6\u7406\nwhile (true) {\n    if ($job = $queue-&gt;dequeue('emails', 5)) {\n        try {\n            \/\/ \u30b8\u30e7\u30d6\u306e\u51e6\u7406\n            processJob($job);\n            $queue-&gt;complete($job['id']);\n        } catch (Exception $e) {\n            $queue-&gt;fail($job['id'], $e-&gt;getMessage());\n        }\n    }\n}<\/pre>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u5b9f\u88c5\u4f8b\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u7279\u5fb4\u3092\u6301\u3063\u3066\u3044\u307e\u3059\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30bb\u30c3\u30b7\u30e7\u30f3\u7ba1\u7406\u30b7\u30b9\u30c6\u30e0<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5206\u6563\u74b0\u5883\u3067\u306e\u6574\u5408\u6027\u78ba\u4fdd<\/li>\n\n\n\n<li>\u9ad8\u901f\u306a\u30bb\u30c3\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf\u30a2\u30af\u30bb\u30b9<\/li>\n\n\n\n<li>\u30b9\u30b1\u30fc\u30e9\u30d6\u30eb\u306a\u8a2d\u8a08<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30e9\u30f3\u30ad\u30f3\u30b0\u30b7\u30b9\u30c6\u30e0<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30b9\u30b3\u30a2\u66f4\u65b0<\/li>\n\n\n\n<li>\u52b9\u7387\u7684\u306a\u30e9\u30f3\u30ad\u30f3\u30b0\u8a08\u7b97<\/li>\n\n\n\n<li>\u67d4\u8edf\u306a\u30e9\u30f3\u30ad\u30f3\u30b0\u7bc4\u56f2\u53d6\u5f97<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30b8\u30e7\u30d6\u30ad\u30e5\u30fc\u30b7\u30b9\u30c6\u30e0<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4fe1\u983c\u6027\u306e\u9ad8\u3044\u30b8\u30e7\u30d6\u7ba1\u7406<\/li>\n\n\n\n<li>\u5931\u6557\u6642\u306e\u30ea\u30c8\u30e9\u30a4\u6a5f\u80fd<\/li>\n\n\n\n<li>\u30ad\u30e5\u30fc\u72b6\u614b\u306e\u76e3\u8996\u6a5f\u80fd<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u5b9f\u88c5\u306f\u3001\u5b9f\u969b\u306e\u30d7\u30ed\u30c0\u30af\u30b7\u30e7\u30f3\u74b0\u5883\u3067\u4f7f\u7528\u3059\u308b\u524d\u306b\u3001\u9069\u5207\u306a\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3001\u30ed\u30b0\u8a18\u9332\u3001\u30e2\u30cb\u30bf\u30ea\u30f3\u30b0\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u3092\u304a\u52e7\u3081\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-23\">\u30c8\u30e9\u30d6\u30eb\u30b7\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0\u30ac\u30a4\u30c9<\/h2>\n\n\n\n<p>Redis\u306e\u904b\u7528\u306b\u304a\u3044\u3066\u906d\u9047\u3059\u308b\u53ef\u80fd\u6027\u306e\u3042\u308b\u554f\u984c\u3068\u305d\u306e\u89e3\u6c7a\u65b9\u6cd5\u3001\u52b9\u679c\u7684\u306a\u76e3\u8996\u65b9\u6cd5\u3001\u305d\u3057\u3066\u30c7\u30fc\u30bf\u4fdd\u8b77\u306e\u305f\u3081\u306e\u6226\u7565\u3092\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-24\">\u4e00\u822c\u7684\u306a\u554f\u984c\u3068\u89e3\u6c7a\u65b9\u6cd5<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30e1\u30e2\u30ea\u95a2\u9023\u306e\u554f\u984c<\/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 RedisMemoryTroubleshooter\n{\n    private $redis;\n\n    public function __construct(Redis $redis)\n    {\n        $this-&gt;redis = $redis;\n    }\n\n    \/\/ \u30e1\u30e2\u30ea\u4f7f\u7528\u72b6\u6cc1\u306e\u8a3a\u65ad\n    public function diagnoseMemoryIssues(): array\n    {\n        $info = $this-&gt;redis-&gt;info('memory');\n        $warnings = [];\n\n        \/\/ \u30e1\u30e2\u30ea\u4f7f\u7528\u7387\u306e\u78ba\u8a8d\n        $usedMemory = $info['used_memory'];\n        $maxMemory = $info['maxmemory'];\n        $memoryUsageRatio = $usedMemory \/ $maxMemory;\n\n        if ($memoryUsageRatio &gt; 0.85) {\n            $warnings[] = sprintf(\n                '\u30e1\u30e2\u30ea\u4f7f\u7528\u7387\u304c\u9ad8\u3059\u304e\u307e\u3059\uff08%.2f%%\uff09\u3002maxmemory\u306e\u8a2d\u5b9a\u3092\u898b\u76f4\u3059\u304b\u3001\u4e0d\u8981\u306a\u30ad\u30fc\u3092\u524a\u9664\u3057\u3066\u304f\u3060\u3055\u3044\u3002',\n                $memoryUsageRatio * 100\n            );\n        }\n\n        \/\/ \u30d5\u30e9\u30b0\u30e1\u30f3\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u78ba\u8a8d\n        $fragRatio = $info['mem_fragmentation_ratio'];\n        if ($fragRatio &gt; 1.5) {\n            $warnings[] = sprintf(\n                '\u30e1\u30e2\u30ea\u30d5\u30e9\u30b0\u30e1\u30f3\u30c6\u30fc\u30b7\u30e7\u30f3\u304c\u9ad8\u3059\u304e\u307e\u3059\uff08%.2f\uff09\u3002Redis\u518d\u8d77\u52d5\u3092\u691c\u8a0e\u3057\u3066\u304f\u3060\u3055\u3044\u3002',\n                $fragRatio\n            );\n        }\n\n        return $warnings;\n    }\n\n    \/\/ \u5927\u304d\u306a\u30ad\u30fc\u306e\u691c\u51fa\u3068\u51e6\u7406\n    public function handleLargeKeys(int $threshold = 1024 * 1024): array\n    {\n        $largeKeys = [];\n        $iterator = null;\n\n        while ($keys = $this-&gt;redis-&gt;scan($iterator, ['COUNT' =&gt; 100])) {\n            foreach ($keys as $key) {\n                $size = $this-&gt;redis-&gt;execute('MEMORY', ['USAGE', $key]);\n                if ($size &gt; $threshold) {\n                    $largeKeys[$key] = [\n                        'size' =&gt; $size,\n                        'type' =&gt; $this-&gt;redis-&gt;type($key),\n                        'ttl' =&gt; $this-&gt;redis-&gt;ttl($key)\n                    ];\n                }\n            }\n        }\n\n        return $largeKeys;\n    }\n}<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u63a5\u7d9a\u7ba1\u7406\u306e\u554f\u984c<\/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 RedisConnectionTroubleshooter\n{\n    private $redis;\n    private const MAX_RETRIES = 3;\n    private const RETRY_DELAY = 1000000; \/\/ 1\u79d2\n\n    public function __construct(Redis $redis)\n    {\n        $this-&gt;redis = $redis;\n    }\n\n    \/\/ \u63a5\u7d9a\u306e\u5065\u5168\u6027\u30c1\u30a7\u30c3\u30af\n    public function checkConnectionHealth(): array\n    {\n        $status = [\n            'is_connected' =&gt; false,\n            'latency' =&gt; 0,\n            'errors' =&gt; []\n        ];\n\n        try {\n            $start = microtime(true);\n            $this-&gt;redis-&gt;ping();\n            $status['latency'] = (microtime(true) - $start) * 1000;\n            $status['is_connected'] = true;\n        } catch (RedisException $e) {\n            $status['errors'][] = $e-&gt;getMessage();\n        }\n\n        return $status;\n    }\n\n    \/\/ \u63a5\u7d9a\u306e\u518d\u8a66\u884c\u30ed\u30b8\u30c3\u30af\n    public function executeWithRetry(callable $operation)\n    {\n        $attempts = 0;\n        $lastError = null;\n\n        while ($attempts &lt; self::MAX_RETRIES) {\n            try {\n                return $operation();\n            } catch (RedisException $e) {\n                $lastError = $e;\n                $attempts++;\n\n                if ($attempts &lt; self::MAX_RETRIES) {\n                    usleep(self::RETRY_DELAY * $attempts);\n                    try {\n                        $this-&gt;redis-&gt;connect(\n                            $this-&gt;redis-&gt;getHost(),\n                            $this-&gt;redis-&gt;getPort()\n                        );\n                    } catch (RedisException $e) {\n                        \/\/ \u518d\u63a5\u7d9a\u306b\u5931\u6557\u3057\u305f\u5834\u5408\u306f\u6b21\u306e\u8a66\u884c\u3078\n                        continue;\n                    }\n                }\n            }\n        }\n\n        throw new RuntimeException(\n            '\u64cd\u4f5c\u304c\u5931\u6557\u3057\u307e\u3057\u305f: ' . $lastError-&gt;getMessage(),\n            0,\n            $lastError\n        );\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-25\">\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u76e3\u8996\u306e\u65b9\u6cd5<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30e1\u30c8\u30ea\u30af\u30b9\u306e\u53ce\u96c6<\/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{\n    private $redis;\n    private const METRICS_KEY = 'metrics:';\n\n    public function __construct(Redis $redis)\n    {\n        $this-&gt;redis = $redis;\n    }\n\n    \/\/ \u57fa\u672c\u7684\u306a\u30e1\u30c8\u30ea\u30af\u30b9\u306e\u53ce\u96c6\n    public function collectMetrics(): array\n    {\n        $info = $this-&gt;redis-&gt;info();\n        $metrics = [\n            'timestamp' =&gt; time(),\n            'connected_clients' =&gt; $info['connected_clients'],\n            'used_memory' =&gt; $info['used_memory'],\n            'total_commands_processed' =&gt; $info['total_commands_processed'],\n            'keyspace_hits' =&gt; $info['keyspace_hits'],\n            'keyspace_misses' =&gt; $info['keyspace_misses']\n        ];\n\n        \/\/ \u30e1\u30c8\u30ea\u30af\u30b9\u306e\u4fdd\u5b58\uff081\u6642\u9593\u5206\uff09\n        $this-&gt;redis-&gt;zAdd(\n            self::METRICS_KEY . date('Y-m-d:H'),\n            ['score' =&gt; $metrics['timestamp'], 'member' =&gt; json_encode($metrics)]\n        );\n\n        return $metrics;\n    }\n\n    \/\/ \u30b9\u30ed\u30fc\u30af\u30a8\u30ea\u306e\u691c\u51fa\n    public function monitorSlowQueries(float $threshold = 0.1): array\n    {\n        $this-&gt;redis-&gt;config('SET', 'slowlog-log-slower-than', (int)($threshold * 1000000));\n        $slowLogs = $this-&gt;redis-&gt;slowlog('get', 10);\n\n        return array_map(function ($log) {\n            return [\n                'id' =&gt; $log['id'],\n                'timestamp' =&gt; $log['timestamp'],\n                'execution_time' =&gt; $log['execution_time'],\n                'command' =&gt; $log['command']\n            ];\n        }, $slowLogs);\n    }\n\n    \/\/ \u30ad\u30e3\u30c3\u30b7\u30e5\u30d2\u30c3\u30c8\u7387\u306e\u5206\u6790\n    public function analyzeHitRate(string $date = null): array\n    {\n        $date = $date ?? date('Y-m-d:H');\n        $metrics = $this-&gt;redis-&gt;zRange(self::METRICS_KEY . $date, 0, -1);\n\n        $totalHits = 0;\n        $totalMisses = 0;\n\n        foreach ($metrics as $metric) {\n            $data = json_decode($metric, true);\n            $totalHits += $data['keyspace_hits'];\n            $totalMisses += $data['keyspace_misses'];\n        }\n\n        $total = $totalHits + $totalMisses;\n        return [\n            'hit_rate' =&gt; $total &gt; 0 ? ($totalHits \/ $total) * 100 : 0,\n            'total_operations' =&gt; $total\n        ];\n    }\n}<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u30a2\u30e9\u30fc\u30c8\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 RedisAlertManager\n{\n    private $redis;\n    private $notifier;\n\n    public function __construct(Redis $redis, callable $notifier)\n    {\n        $this-&gt;redis = $redis;\n        $this-&gt;notifier = $notifier;\n    }\n\n    \/\/ \u30e1\u30e2\u30ea\u4f7f\u7528\u7387\u306e\u30a2\u30e9\u30fc\u30c8\n    public function checkMemoryUsage(float $threshold = 0.85): void\n    {\n        $info = $this-&gt;redis-&gt;info('memory');\n        $usageRatio = $info['used_memory'] \/ $info['maxmemory'];\n\n        if ($usageRatio &gt; $threshold) {\n            ($this-&gt;notifier)([\n                'type' =&gt; 'memory_alert',\n                'message' =&gt; sprintf(\n                    '\u30e1\u30e2\u30ea\u4f7f\u7528\u7387\u304c%.2f%%\u306b\u9054\u3057\u307e\u3057\u305f',\n                    $usageRatio * 100\n                ),\n                'timestamp' =&gt; time()\n            ]);\n        }\n    }\n\n    \/\/ \u63a5\u7d9a\u6570\u306e\u30a2\u30e9\u30fc\u30c8\n    public function checkConnections(int $threshold = 5000): void\n    {\n        $info = $this-&gt;redis-&gt;info('clients');\n\n        if ($info['connected_clients'] &gt; $threshold) {\n            ($this-&gt;notifier)([\n                'type' =&gt; 'connection_alert',\n                'message' =&gt; sprintf(\n                    '\u63a5\u7d9a\u6570\u304c%d\u306b\u9054\u3057\u307e\u3057\u305f',\n                    $info['connected_clients']\n                ),\n                'timestamp' =&gt; time()\n            ]);\n        }\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-26\">\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3068\u5fa9\u65e7\u6226\u7565<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\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 RedisBackupManager\n{\n    private $redis;\n    private $backupPath;\n\n    public function __construct(Redis $redis, string $backupPath)\n    {\n        $this-&gt;redis = $redis;\n        $this-&gt;backupPath = $backupPath;\n    }\n\n    \/\/ RDB\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u306e\u4f5c\u6210\n    public function createBackup(): string\n    {\n        $filename = sprintf(\n            'redis_backup_%s.rdb',\n            date('Y-m-d_H-i-s')\n        );\n        $filepath = $this-&gt;backupPath . '\/' . $filename;\n\n        \/\/ SAVE \u30b3\u30de\u30f3\u30c9\u306e\u5b9f\u884c\n        $this-&gt;redis-&gt;save();\n\n        \/\/ \u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u30d5\u30a1\u30a4\u30eb\u306e\u30b3\u30d4\u30fc\n        if (!copy('\/var\/lib\/redis\/dump.rdb', $filepath)) {\n            throw new RuntimeException('\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u306e\u4f5c\u6210\u306b\u5931\u6557\u3057\u307e\u3057\u305f');\n        }\n\n        return $filepath;\n    }\n\n    \/\/ \u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u306e\u6574\u7406\uff08\u53e4\u3044\u3082\u306e\u3092\u524a\u9664\uff09\n    public function cleanupBackups(int $keepLast = 5): array\n    {\n        $files = glob($this-&gt;backupPath . '\/redis_backup_*.rdb');\n        rsort($files);\n\n        $deleted = [];\n        for ($i = $keepLast; $i &lt; count($files); $i++) {\n            if (unlink($files[$i])) {\n                $deleted[] = basename($files[$i]);\n            }\n        }\n\n        return $deleted;\n    }\n}<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u30c7\u30fc\u30bf\u5fa9\u65e7\u624b\u9806<\/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 RedisRecoveryManager\n{\n    private $redis;\n\n    public function __construct(Redis $redis)\n    {\n        $this-&gt;redis = $redis;\n    }\n\n    \/\/ \u30ad\u30fc\u306e\u5fa9\u65e7\n    public function recoverKeys(array $keys, string $backupInstance): array\n    {\n        $recovered = [];\n        $failed = [];\n\n        $backup = new Redis();\n        $backup-&gt;connect($backupInstance);\n\n        foreach ($keys as $key) {\n            try {\n                $type = $backup-&gt;type($key);\n\n                switch ($type) {\n                    case Redis::REDIS_STRING:\n                        $value = $backup-&gt;get($key);\n                        $this-&gt;redis-&gt;set($key, $value);\n                        break;\n\n                    case Redis::REDIS_HASH:\n                        $value = $backup-&gt;hGetAll($key);\n                        $this-&gt;redis-&gt;hMset($key, $value);\n                        break;\n\n                    case Redis::REDIS_LIST:\n                        $value = $backup-&gt;lRange($key, 0, -1);\n                        if (!empty($value)) {\n                            $this-&gt;redis-&gt;del($key);\n                            $this-&gt;redis-&gt;rPush($key, ...$value);\n                        }\n                        break;\n\n                    case Redis::REDIS_SET:\n                        $value = $backup-&gt;sMembers($key);\n                        if (!empty($value)) {\n                            $this-&gt;redis-&gt;del($key);\n                            $this-&gt;redis-&gt;sAdd($key, ...$value);\n                        }\n                        break;\n\n                    case Redis::REDIS_ZSET:\n                        $value = $backup-&gt;zRange($key, 0, -1, true);\n                        if (!empty($value)) {\n                            $this-&gt;redis-&gt;del($key);\n                            $this-&gt;redis-&gt;zAdd($key, $value);\n                        }\n                        break;\n                }\n\n                $recovered[] = $key;\n            } catch (Exception $e) {\n                $failed[] = [\n                    'key' =&gt; $key,\n                    'error' =&gt; $e-&gt;getMessage()\n                ];\n            }\n        }\n\n        return [\n            'recovered' =&gt; $recovered,\n            'failed' =&gt; $failed\n        ];\n    }\n}<\/pre>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u30c8\u30e9\u30d6\u30eb\u30b7\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0\u30c4\u30fc\u30eb\u3092\u52b9\u679c\u7684\u306b\u6d3b\u7528\u3059\u308b\u305f\u3081\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u4e88\u9632\u7684\u306a\u76e3\u8996<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5b9a\u671f\u7684\u306a\u30e1\u30c8\u30ea\u30af\u30b9\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\u7d99\u7d9a\u7684\u306a\u76e3\u8996<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u554f\u984c\u767a\u751f\u6642\u306e\u5bfe\u5fdc<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30a8\u30e9\u30fc\u30ed\u30b0\u306e\u8a73\u7d30\u306a\u5206\u6790<\/li>\n\n\n\n<li>\u6bb5\u968e\u7684\u306a\u30c8\u30e9\u30d6\u30eb\u30b7\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0<\/li>\n\n\n\n<li>\u5f71\u97ff\u7bc4\u56f2\u306e\u7279\u5b9a\u3068\u6700\u5c0f\u5316<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u6226\u7565<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5b9a\u671f\u7684\u306a\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u30b9\u30b1\u30b8\u30e5\u30fc\u30eb<\/li>\n\n\n\n<li>\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u306e\u691c\u8a3c\u3068\u5fa9\u65e7\u30c6\u30b9\u30c8<\/li>\n\n\n\n<li>\u8907\u6570\u4e16\u4ee3\u306e\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u4fdd\u6301<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5b9a\u671f\u7684\u306a\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u5206\u6790<\/li>\n\n\n\n<li>\u30dc\u30c8\u30eb\u30cd\u30c3\u30af\u306e\u7279\u5b9a\u3068\u89e3\u6d88<\/li>\n\n\n\n<li>\u8a2d\u5b9a\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u6700\u9069\u5316<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u5bfe\u7b56\u3092\u5b9f\u65bd\u3059\u308b\u3053\u3068\u3067\u3001Redis\u306e\u5b89\u5b9a\u904b\u7528\u3068\u9ad8\u3044\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u7dad\u6301\u3059\u308b\u3053\u3068\u304c\u3067\u304d\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":{"0":"post-3308","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\/3308","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=3308"}],"version-history":[{"count":2,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts\/3308\/revisions"}],"predecessor-version":[{"id":3310,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts\/3308\/revisions\/3310"}],"wp:attachment":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}