Home >php教程 >PHP开发 >Php-Redis installation test notes

Php-Redis installation test notes

高洛峰
高洛峰Original
2016-12-21 15:00:241554browse

Back-end development uses PHP to operate redis. Here, we will summarize and record the problems encountered during the installation and testing process for future reference! (The system is ubuntu)

1.redis installation

Download address: http://download.redis.io/releases/
Unzip and install:

tar -xvf redis-2.8.17.tar.gz
make
sudo make install

For ease of use, create a redis directory in the /usr directory, as follows Copy several files to the /usr/redis/ directory:

/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 to facilitate use. In addition, you can also add redis-server to startup, which is omitted here.


2. redis test

1) First open the redis server program
To facilitate testing, we modified 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) Open the redi client and perform addition, deletion, modification and query operations in the redis database through the client. The 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:

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
"m.sbmmt.com"

3. Install phpredis extension

When using sudo apt-get install php5 to install php, phpize is not installed by default. When we install phpredis, we need to use it. phpize, therefore, you need to install phpize first.
1) We get phpize by installing php developer tools. Execute the following command:

sudo apt-get install php5-dev

2) Get the phpredis source file
The latest phpRedis address: https://github.com/nicolasff/phpredis
When installing as follows according to the instructions on GitHub,

phpize
./configure --enable-redis-igbinary
make && make install

may appear The error description is as follows:

checking for igbinary includes... configure: error: Cannot find igbinary.h

This is because we do not have the igbinary extension, which is something that phpredis depends on.
Okay, how to install igbinary?


The installation cannot be completed using apt-get. We install it by downloading the installation file.

wget <a href="http://pecl.php.net/get/igbinary-1.1.1.tgz">http://pecl.php.net/get/igbinary-1.1.1.tgz</a>
 
tar -xzvf igbinary-1.1.1.tgz
 
cd igbinary-1.1.1
 
phpize
 
./configure # No need for extra config params
 
make
 
make install

After installing igbinary, you can use the following command to install phpredis.

phpize
./configure –enable-redis-igbinary
make && make install

At this point, the installation is complete.

We modify the php.ini configuration file and add the two extensions we just installed to the php.ini file. The added statements are as follows:

extension=igbinary.so
extension=redis.so


Restart apache, Done! ! !

4. Test php-redis

Create a new file test.php in the web root directory /var/www/ with the following content:

<?php 
$redis = new Redis(); 
$redis->connect(&#39;127.0.0.1&#39;,6379); 
$redis->set(&#39;Jay13&#39;,&#39;m.sbmmt.com&#39;); 
echo &#39;Jay13:&#39;.$redis->get(&#39;Jay13&#39;); 
echo &#39;</br>&#39;; 
echo &#39;Jay12:&#39;.$redis->get(&#39;Jay12&#39;); 
?>

The result is as shown below:

Php-Redis installation test notes


More Php-Redis installation For articles related to test notes, please pay attention to the PHP Chinese website!


Statement:
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