Home > Backend Development > PHP Tutorial > PHP-Redis extension installation and application

PHP-Redis extension installation and application

WBOY
Release: 2016-07-29 09:09:54
Original
927 people have browsed it

In the first introduction to Redis, the installation and use of Redis are introduced, but only in this way, Redis cannot be operated in PHP. In order to be able to operate Redis in PHP, an expansion pack needs to be installed.
Download address:
https://github.com/phpredis/phpredis
Install after downloading:

<code><span>#unzip phpredis-develop.zip</span><span>#cd phpredis-develop</span><span>#/usr/local/php/bin/phpize</span><span>#./configure --with-php-c/local/php/bin/php-config</span><span>#make</span><span>#make install</span></code>
Copy after login

/usr/local/php directory is the PHP installation directory in my system. This is determined according to the PHP installation location of your system.
After the installation is complete, you need to modify PHP's php.ini configuration file, which is located in /usr/local/php/etc/php.ini. Add a line:

<code><span>extension</span>=<span>redis.so</span></code>
Copy after login

Then restart php-fpm. If it is an Apache environment, restart Apache service.
After the restart is complete, check to see if there is Redis support in PHP. Output phpinfo() to see:

<code><span><span><?php </span>
phpinfo();
<span>?></span></span></span></code>
Copy after login

Seeing such a display means that the Redis extension was installed successfully!
PHP-Redis extension installation and application
It is recommended to run the verification program that comes with the phpredis extension. In the tests directory in the unzipped directory:

<code><span>#cd phpredis-develop/tests/</span><span>#php TestRedis.php</span></code>
Copy after login

Write a test code to verify it:

<code><span></span>php
<span>$redis</span><span>=</span><span>new</span> Redis();
<span>$redis</span><span>-></span>connect(<span>'127.0.0.1'</span>,<span>6379</span>); <span>// 连接</span><span>//$r = $redis->ping();   // 检查连接状态,返回'+PONG'表示链接可用</span><span>$redis</span><span>-></span><span>set</span>(<span>'n4'</span>,<span>'DA L'</span>);  <span>// 设置set(key,value)</span><span>$r</span><span>=</span><span>$redis</span><span>-></span>get(<span>'n4'</span>);
echo <span>$r</span>;

<span>$redis</span><span>-></span>del(<span>'n4'</span>); <span>// 移除del(key)</span></code>
Copy after login

If the verification passes, it means that the installed Redis extension is available, and that’s it. Start operating Redis in PHP!
The instructions for operating Redis in PHP are very similar to the instructions for operating the Redis terminal. For more detailed documents, please refer to:
Standard: https://github.com/phpredis/phpredis
Chinese (translated with the efforts of others): http://www.cnblogs.com/weafer/archive/2011/09/21/2184059.html

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the installation and application of PHP-Redis extension, including Apache and github content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template