Home > Backend Development > PHP Tutorial > Php-Redis installation test notes, php-redis test notes_PHP tutorial

Php-Redis installation test notes, php-redis test notes_PHP tutorial

WBOY
Release: 2016-07-13 10:05:27
Original
999 people have browsed it

Php-Redis installation test notes, php-redis test notes

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

1.redis installation

Download address: http://download.redis.io/releases/
Unzip and install:
Copy code The code is as follows:
tar -xvf redis-2.8.17.tar.gz
make
sudo make install

For ease of use, create a redis directory in the /usr directory and copy the following files to the /usr/redis/ directory:
Copy code 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 to achieve the purpose of convenient 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.
Taking the simplest key operation as an example, the example is as follows:

Copy code 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. When we install phpredis, we need to use phpize, so we need to install phpize first.
1) We get phpize by installing php developer tools. Just execute the following command:
Copy code The code is as follows:
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 following the instructions on GitHub,

Copy code The code is as follows:
phpize
./configure --enable-redis-igbinary
make && make install

The following error description may appear:
Copy code The code 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.
Ok, how to install igbinary?

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

Copy code 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 installing igbinary, you can use the following command to install phpredis.
Copy code The code is as follows:
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:
Copy code The code is 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:

Copy code The code is as follows:
$redis = new Redis();
$redis->connect('127.0.0.1',6379);
$redis->set('Jay13','www.jb51.net');
echo 'Jay13:'.$redis->get('Jay13');
echo '
';
echo 'Jay12:'.$redis->get('Jay12');
?>

The result is as shown below:

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/963842.htmlTechArticlePhp-Redis installation test notes, php-redis test notes back-end development uses php to operate redis, here we will The problems encountered during the installation and testing process are summarized and recorded for future reference! (System...
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