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

Php-Redis installation test notes

Dec 21, 2016 pm 03:00 PM

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
Copy after login

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
Copy after login

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
"www.php.cn"
Copy after login

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
Copy after login

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
Copy after login

may appear The error description is as follows:

checking for igbinary includes... configure: error: Cannot find igbinary.h
Copy after login

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
Copy after login

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

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

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
Copy after login


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;www.php.cn&#39;); 
echo &#39;Jay13:&#39;.$redis->get(&#39;Jay13&#39;); 
echo &#39;</br>&#39;; 
echo &#39;Jay12:&#39;.$redis->get(&#39;Jay12&#39;); 
?>
Copy after login

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1672
14
PHP Tutorial
1277
29
C# Tutorial
1257
24