Php and phpredis

Source: Internet
Author: User

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.