After apsaradb for redis is installed (if the reader has not installed it, please refer to the plugin), we cannot only use the redis client to operate the database. Currently, apsaradb for redis supports c, c ++, c #, this document describes how to use php to operate redis databases.
Php itself does not directly operate redis. Our functions are carried out through third-party services. redis officially provides five methods. Here I use the most commonly used phpredis.
1. Install phpredis and obtain the latest version code for compilation.
wget --no-check-certificate http://github.com/nicolasff/phpredis/tarball/master -O phpredis.tar.gztar phpredis.tar.gzcd nicolasff-phpredis-f1231c9phpize./configure --with-php-config=/usr/local/php/bin/php-configmake make install
2. Modify php. ini and add the redis. so module.
vim /etc/php5/apache2/php.inivim /etc/php5/cli/php.ini
Add the following line to both files.
Extension = redis. so
3. Restart apache
cd /etc/init.d./apache restart
4. If the above operation is successful, you can operate redis on php. Create a test file, such as test. php, in your php Directory. The test code can be as follows:
<?php$redis = new Redis();$redis->connect('127.0.0.1', 6379);$redis->set('hello', 'hello world');echo $redis->get('hello');?>
Run the test file above. If the word "hello world" appears on the page, it means you have succeeded!
Finally, we recommend several useful redis learning websites.
Online redis: http://try.redis.io/
Redis Chinese manual: http://www.cnblogs.com/ikodota/archive/2012/03/05/php_redis_cn.html
Redis Official Website: http://redis.io/