This article mainly introduces the installation and testing notes of Php-Redis. This article describes redis installation, redis testing, phpredis extension installation, and php-redis testing, you can refer to the backend development and use php to operate redis. here, we will summarize the problems encountered during the installation and testing process for future reference! (The system is ubuntu)
1. install redis
: Http://download.redis.io/releases/
Unzip and install:
The code is as follows:
Tar-xvf redis-2.8.17.tar.gz
Make
Sudo make install
For ease of use, create the redis directory under the/usr directory and copy the following files to the/usr/redis/directory:
The code is as follows:
/Yourdir/redis-2.8.17/redis. conf
/Yourdir/redis-2.8.17/src/redis-benchmark
/Yourdir/redis-2.8.17/src/redis-server
/Yourdir/redis-2.8.17/src/redis-cli
Of course, you can also use soft connections for ease of use. In addition, you can add the redis-server to the startup mode.
2. redis test
1) enable the redis server program first
To facilitate the test, we modify the values of loglevel and logfile in the redis. conf configuration file as follows:
Loglevel debug
Logfile "/tmp/redis. log"
Jay13 @ ubuntu:/usr/redis $ redis-server redis. conf
2) enable the redi client to add, delete, modify, and query data to the redis database through the client. Logs generated during the entire operation can be viewed in/tmp/redis. log.
Take the simplest key operation as an example. The example is as follows:
The code is as follows:
Jay13 @ ubuntu:/usr/redis $ redis-cli
127.0.0.1: 6379> set jay13 jb51.net
OK
127.0.0.1: 6379> set jay hello, world
OK
127.0.0.1: 6379> get jay
"Hello, world"
127.0.0.1: 6379> get jay13
"Jb51.net"
127.0.0.1: 6379> del jay
(Integer) 1
127.0.0.1: 6379> get jay
(Nil)
127.0.0.1: 6379> set jay13 www.jb51.net
OK
127.0.0.1: 6379> get jay13
"Www.jb51.net"
3. install phpredis extension
When using sudo apt-get install php5 to install php, phpize is not installed by default. we need to use phpize when installing phpredis. Therefore, we need to install phpize first.
1) we can get phpize by installing the php developer tool. Run the following command:
The code is as follows:
Sudo apt-get install php5-dev
2) obtain the phpredis source file
Latest phpRedis address: https://github.com/nicolasff/phpredis
Follow the instructions on GitHub for the following installation,
The code is as follows:
Phpize
./Configure -- enable-redis-igbinary
Make & make install
The following error may occur:
The code is as follows:
Checking for igbinary between Des... configure: error: Cannot find igbinary. h
This is because we do not have an igbinary extension, which is a dependency of phpredis.
Okay. how can I install igbinary?
The installation is not completed by using apt-get. we can download the installation file for installation.
The code is as follows:
Wget http://pecl.php.net/get/igbinary-1.1.1.tgz
Tar-xzvf igbinary-1.1.1.tgz
Cd igbinary-1.1.1
Phpize
./Configure # No need for extra config params
Make
Make install
After igbinary is installed, run the following command to install phpredis.
The code is as follows:
Phpize
./Configure-enable-redis-igbinary
Make & make install
So far, the installation is complete.
Modify the php. ini configuration file and add the two extensions that have just been installed to the php. ini file. The statement is as follows:
The code is as follows:
Extension = igbinary. so
Extension = redis. so
Restart apache, Done !!!
4. test php-redis
Create the file test. php in the root directory/var/www/of the webpage. the content is as follows:
The code is as follows:
<? Php
$ Redis = new Redis ();
$ Redis-> connect ('2017. 0.0.1 ', 127 );
$ Redis-> set ('jay13', 'www .jb51.net ');
Echo 'jay13: '. $ redis-> get ('jay13 ');
Echo'
';
Echo 'jay12: '. $ redis-> get ('jay12 ');
?>
The result is as follows: