{"id":43292,"date":"2024-10-05T00:52:07","date_gmt":"2024-10-04T16:52:07","guid":{"rendered":"https:\/\/server.hk\/cnblog\/43292\/"},"modified":"2024-10-05T00:52:07","modified_gmt":"2024-10-04T16:52:07","slug":"centos-7-%e4%b8%8b%e5%ae%89%e8%a3%9d-php-redis-%e6%93%b4%e5%b1%95%e5%8f%8a%e7%b0%a1%e5%96%ae%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/43292\/","title":{"rendered":"CentOS 7 \u4e0b\u5b89\u88dd php-redis \u64f4\u5c55\u53ca\u7c21\u55ae\u4f7f\u7528"},"content":{"rendered":"<h1 id=\"centos-7-%e4%b8%8b%e5%ae%89%e8%a3%9d-php-redis-%e6%93%b4%e5%b1%95%e5%8f%8a%e7%b0%a1%e5%96%ae%e4%bd%bf%e7%94%a8-jfrNRICSIl\">CentOS 7 \u4e0b\u5b89\u88dd php-redis \u64f4\u5c55\u53ca\u7c21\u55ae\u4f7f\u7528<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0cRedis \u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6548\u7684\u9375\u503c\u5b58\u5132\u7cfb\u7d71\uff0c\u8d8a\u4f86\u8d8a\u53d7\u5230\u958b\u767c\u8005\u7684\u9752\u775e\u3002\u5b83\u4e0d\u50c5\u80fd\u5920\u52a0\u901f\u6578\u64da\u5b58\u53d6\uff0c\u9084\u80fd\u6709\u6548\u5730\u6e1b\u5c11\u6578\u64da\u5eab\u7684\u8ca0\u64d4\u3002\u82e5\u60a8\u5728\u4f7f\u7528 PHP \u958b\u767c\u61c9\u7528\u7a0b\u5f0f\uff0c\u5b89\u88dd php-redis \u64f4\u5c55\u5c07\u4f7f\u60a8\u80fd\u5920\u66f4\u65b9\u4fbf\u5730\u8207 Redis \u9032\u884c\u4ea4\u4e92\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 CentOS 7 \u4e0a\u5b89\u88dd php-redis \u64f4\u5c55\u53ca\u5176\u7c21\u55ae\u4f7f\u7528\u65b9\u6cd5\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d%e5%89%8d%e7%9a%84%e6%ba%96%e5%82%99-jfrNRICSIl\">\u5b89\u88dd\u524d\u7684\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u5b89\u88dd php-redis \u64f4\u5c55\u4e4b\u524d\uff0c\u8acb\u78ba\u4fdd\u60a8\u7684 CentOS 7 \u7cfb\u7d71\u5df2\u7d93\u5b89\u88dd\u4e86 PHP \u548c Redis\u3002\u60a8\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5 PHP \u548c Redis \u662f\u5426\u5df2\u5b89\u88dd\uff1a<\/p>\n<pre><code>php -v\nredis-server -v\n<\/code><\/pre>\n<p>\u5982\u679c\u5c1a\u672a\u5b89\u88dd\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u5b89\u88dd\uff1a<\/p>\n<pre><code>sudo yum install epel-release\nsudo yum install php php-cli php-pear php-devel\nsudo yum install redis\n<\/code><\/pre>\n<h2 id=\"%e5%ae%89%e8%a3%9d-php-redis-%e6%93%b4%e5%b1%95-jfrNRICSIl\">\u5b89\u88dd php-redis \u64f4\u5c55<\/h2>\n<p>\u5b89\u88dd php-redis \u64f4\u5c55\u7684\u6700\u7c21\u55ae\u65b9\u6cd5\u662f\u4f7f\u7528 PECL\u3002\u8acb\u6309\u7167\u4ee5\u4e0b\u6b65\u9a5f\u9032\u884c\u5b89\u88dd\uff1a<\/p>\n<ol>\n<li>\u9996\u5148\uff0c\u78ba\u4fdd\u60a8\u5df2\u7d93\u5b89\u88dd\u4e86\u5fc5\u8981\u7684\u958b\u767c\u5de5\u5177\uff1a<\/li>\n<pre><code>sudo yum groupinstall \"Development Tools\"<\/code><\/pre>\n<li>\u63a5\u4e0b\u4f86\uff0c\u4f7f\u7528 PECL \u5b89\u88dd php-redis \u64f4\u5c55\uff1a<\/li>\n<pre><code>sudo pecl install redis<\/code><\/pre>\n<li>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u9700\u8981\u5c07\u64f4\u5c55\u6dfb\u52a0\u5230 PHP \u914d\u7f6e\u4e2d\u3002\u7de8\u8f2f php.ini \u6587\u4ef6\uff1a<\/li>\n<pre><code>sudo nano \/etc\/php.ini<\/code><\/pre>\n<li>\u5728\u6587\u4ef6\u672b\u5c3e\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/li>\n<pre><code>extension=redis.so<\/code><\/pre>\n<li>\u4fdd\u5b58\u4e26\u9000\u51fa\u7de8\u8f2f\u5668\u3002<\/li>\n<\/ol>\n<h2 id=\"%e9%87%8d%e5%95%9f-php-%e5%92%8c-redis-%e6%9c%8d%e5%8b%99-jfrNRICSIl\">\u91cd\u555f PHP \u548c Redis \u670d\u52d9<\/h2>\n<p>\u70ba\u4e86\u4f7f\u66f4\u6539\u751f\u6548\uff0c\u60a8\u9700\u8981\u91cd\u555f PHP \u548c Redis \u670d\u52d9\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u91cd\u555f\uff1a<\/p>\n<pre><code>sudo systemctl restart php-fpm\nsudo systemctl restart redis\n<\/code><\/pre>\n<h2 id=\"%e9%a9%97%e8%ad%89%e5%ae%89%e8%a3%9d-jfrNRICSIl\">\u9a57\u8b49\u5b89\u88dd<\/h2>\n<p>\u8981\u78ba\u8a8d php-redis \u64f4\u5c55\u662f\u5426\u5b89\u88dd\u6210\u529f\uff0c\u60a8\u53ef\u4ee5\u5275\u5efa\u4e00\u500b PHP \u6e2c\u8a66\u6587\u4ef6\uff1a<\/p>\n<pre><code>&lt;?php\nphpinfo();\n?&gt;<\/code><\/pre>\n<p>\u5c07\u4e0a\u8ff0\u4ee3\u78bc\u4fdd\u5b58\u70ba info.php\uff0c\u7136\u5f8c\u5728\u700f\u89bd\u5668\u4e2d\u8a2a\u554f\u8a72\u6587\u4ef6\u3002\u67e5\u627e &#8220;redis&#8221; \u90e8\u5206\uff0c\u5982\u679c\u80fd\u770b\u5230\u76f8\u95dc\u4fe1\u606f\uff0c\u5247\u8868\u793a\u5b89\u88dd\u6210\u529f\u3002<\/p>\n<h2 id=\"%e7%b0%a1%e5%96%ae%e4%bd%bf%e7%94%a8%e7%a4%ba%e4%be%8b-jfrNRICSIl\">\u7c21\u55ae\u4f7f\u7528\u793a\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684 PHP \u7a0b\u5f0f\u78bc\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528 php-redis \u64f4\u5c55\u9032\u884c\u57fa\u672c\u7684\u64cd\u4f5c\uff1a<\/p>\n<pre><code>&lt;?php\n\/\/ \u5275\u5efa Redis \u5be6\u4f8b\n$redis = new Redis();\n\n\/\/ \u9023\u63a5\u5230 Redis \u670d\u52d9\u5668\n$redis-&gt;connect('127.0.0.1', 6379);\n\n\/\/ \u8a2d\u7f6e\u9375\u503c\u5c0d\n$redis-&gt;set('test_key', 'Hello, Redis!');\n\n\/\/ \u7372\u53d6\u9375\u503c\u5c0d\n$value = $redis-&gt;get('test_key');\necho $value; \/\/ \u8f38\u51fa: Hello, Redis!\n?&gt;<\/code><\/pre>\n<p>\u9019\u6bb5\u4ee3\u78bc\u5c55\u793a\u4e86\u5982\u4f55\u9023\u63a5\u5230 Redis \u670d\u52d9\u5668\uff0c\u8a2d\u7f6e\u548c\u7372\u53d6\u9375\u503c\u5c0d\u3002\u60a8\u53ef\u4ee5\u6839\u64da\u9700\u8981\u64f4\u5c55\u9019\u4e9b\u529f\u80fd\uff0c\u4ee5\u6eff\u8db3\u60a8\u7684\u61c9\u7528\u9700\u6c42\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-jfrNRICSIl\">\u7e3d\u7d50<\/h2>\n<p>\u5728 CentOS 7 \u4e0a\u5b89\u88dd php-redis \u64f4\u5c55\u662f\u4e00\u500b\u76f8\u5c0d\u7c21\u55ae\u7684\u904e\u7a0b\uff0c\u901a\u904e PECL \u5b89\u88dd\u548c\u914d\u7f6e\u5f8c\uff0c\u60a8\u53ef\u4ee5\u8f15\u9b06\u5730\u5728 PHP \u61c9\u7528\u4e2d\u4f7f\u7528 Redis\u3002\u9019\u4e0d\u50c5\u80fd\u63d0\u9ad8\u61c9\u7528\u7684\u6027\u80fd\uff0c\u9084\u80fd\u6709\u6548\u7ba1\u7406\u6578\u64da\u3002\u82e5\u60a8\u9700\u8981\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u670d\u52d9\u4f86\u904b\u884c\u60a8\u7684\u61c9\u7528\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u9069\u5408\u4e0d\u540c\u9700\u6c42\u7684\u7528\u6236\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to install the php-redis extension on CentOS 7 and explore its simple usage for enhanced PHP performance.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-43292","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43292","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=43292"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43292\/revisions"}],"predecessor-version":[{"id":43293,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43292\/revisions\/43293"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=43292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=43292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=43292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}