Download and install redis:@ Ubuntu:/$ mkdir/usr/local/redis @ Ubuntu:/$ CD/usr/local/redis @ Ubuntu:/$ wget unzip tar xzf redis-2.4.2.tar.gz @ Ubuntu: /$ CD redis-2.4.2 @ Ubuntu:/$ make @ Ubuntu:/$ src/redis-Server
Redis test command:@ Ubuntu:/$ src/redis-cli @ Ubuntu:/$ redis> set Foo bar @ Ubuntu:/$ OK
@ Ubuntu:/$ redis> Get foo
@ Ubuntu:/$ "bar ";
We have installed the redis server program. Now we need to use redis In the project. Because our backend is written in PHP, we need to use it with the redis PHP client. There are several PHP clients:
Predis★ |
Repository |
Jol1hahn |
Mature and supported |
Phpredis★ |
Repository |
Yowgi |
This is a client written in C as a PHP module. |
Rediska |
Repository Homepage |
Shumkov |
|
Redisent |
Repository |
Justinpoliey |
|
Iredis |
Repository |
Dhorrigan |
Here I select phpredis (
C development extension package) This PHP extension.
@ Ubuntu:/$ wget https://download.github.com/owlient-phpredis-2.1.1-1-g90ecd17.tar.gz
@ Ubuntu:/$ tar zxvf owlient-phpredis-2.1.1-1-g90ecd17.tar.gz
@ Ubuntu:/$ CD owlient-phpredis-90ecd17/
@ Ubuntu: // $/usr/local/PHP/bin/phpize
@ Ubuntu:/$./configure -- With-PHP-Config =/usr/local/PHP/bin/PHP-config
@ Ubuntu:/$ make
@ Ubuntu:/$ make install
Note: When developing PHP extensions using C, if you use the dynamic link library to compile the extension module, you need to use phpize. This tool is not installed by default when you use apt-Get install PhP5, install phpize: APT-Get install php5-dev.
Modify the configuration file:
Modify the php. ini file
Add the following line to PhP. ini:
Extension = redis. So
It takes effect after nginx is restarted.
Enable the redis service: redis-server or redis-server/etc/redis. conf (running in the background ),
If the service is not enabled, "uncaught exception 'redisexception' with message 'redis server went away 'may occur '? "Error