Redis Summary (i)--use of Redis in PHP

Source: Internet
Author: User
Tags php language php redis

Redis is often used, but is basically based on the integrated development environment, Redis connection is also based on the framework itself, the total sense of weakness, just in the Ubuntu system Apt-get does not directly provide PHP Redis extension, take this opportunity to summarize the next Redis support for PHP If you want to use Redis in the program, then there are two prerequisites, the first to install the Redis program, the second to enable Redis support PHP Here is mainly about the Redis support for PHP, we have two common 1.phpredis (implementation: PHP extension, C language) Features: We need to install PHP extension in the development environment, the use of more convenient, the disadvantage is that the threshold of expansion is relatively high, but the speed is fast, CI framework Official document in this way 2. Predis (Implementation: pure PHP language) features: Convenient, easy to expand, laraval Framework Official document in this wayone. Ubuntu installation Phpredis extension, PHP version is 7.01. Preparation: Installation of the extension requires phpize view of the extensible apt Search php7 Discovery Php7.0-dev extension is supported, start installing Apt-get install Php7.0-dev 2. Start installing the Redis extension for PHP [ Email protected]:/tmp# git clone-b php7 https://github.com/phpredis/phpredis.git[email protected]:/tmp# mv phpredis// Etc/[email protected]:/tmp# cd/etc/phpredis[email protected]://etc/phpredis# phpize[email Protected]://etc/phpredis #./configure[email protected]://etc/phpredis#make && make install 3. Start the extension vim/etc/php/7.0/fpm/php. ini, in Add the following statement to the configuration file: Extension=redis.so finally uses the command to restart the PHP service: Service PHP7.   0-FPM Restart 4. Test is successful, write test.php file, add the following content <?php phpinfo (); Successful display of Redis entries proves successful 5. Use PHP to access the Redis writing testredis.php file, which reads as follows <?php$redis = new Redis (); $redis->connect (' 127.0.0.1 ' , 6379); $redis->set (' say ', ' Hello World '); Echo ' Archer: '. $redis->get (' say '); Output the following to prove the success of the visit Archer:hello Worldtwo. Use of Predis1. First of all, if you have installed the Phpredis extension, then you may want to consider the conflict problem, specifically not verified, the Internet has this statement, so I would like to redisphp start the extension operation extension=redis.so this sentence out of 2. Download Predis: https://codeload.github.com/nrk/predis/zip/v1.1, then unzip to your corresponding site under the directory structure below 3. Introduce Predis to test, create testpredis.php file, the content is as follows < PHP require './predis-1.1/autoload.php '; $client = new Predis\client (); $client->set (' foo ', ' Bar '); $value = $client- >get (' foo '); Var_dump ($value); exit; Output: String (3) "bar" proves to be successful 4. As for the connection, the default is 127.0.0.1 port 6379, we can also pass in the parameter $client = new Predis\client ([' Scheme ' = ' tcp ', ' Host ' = ' 10.0.0.1 ', ' port ' = 6379,]);  Same set of parameters, passed using an URI string: $client = new Predis\client (' tcp://10.0.0.1:6379 '); Resourceshttp://blog.csdn.net/u013474436/article/details/53131259Http://www.tuicool.com/articles/JVnqUnEhttp://blog.csdn.net/zls986992484/article/details/52730725Https://github.com/nrk/predisHttps://github.com/phpredis/phpredis

Redis Summary (i)--use of Redis in PHP

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.