RedisPHP connection operation, redisphp connection _ PHP Tutorial

Source: Internet
Author: User
Tags redis tutorial
RedisPHP connection and redisphp connection. RedisPHP connection operations, redisphp connection installation to use Redis in the PHP program, the first need to ensure that the Redis PHP driver and PHP installation settings on the machine. You can view the PHP Tutorial to teach Redis PHP connection operations and redisphp connection
Install

To use Redis in PHP programs, you must first ensure that the PHP driver and PHP installation of Redis are set on the machine. You can refer to the PHP Tutorial to teach you how to install PHP on a machine. Now, let's take a look at how to set up the Redis PHP driver.

You need to download phpredis from the github repository: https://github.com/nicolasff/phpredis. After the download is complete, decompress the file to the phpredis directory. Install the extension on Ubuntu by using the command shown in.

cd phpredissudo phpizesudo ./configuresudo makesudo make install

Copy and paste the contents of the "modules" folder to the PHP extension directory, and add the following lines in php. ini.

extension = redis.so

Now the installation of Redis and PHP is complete.

Connect to the Redis server
 connect('127.0.0.1', 6379);   echo "Connection to server sucessfully";   //check whether server is running or not   echo "Server is running: " . $redis->ping();?>

When the program is executed, the following results are generated:

Connection to server sucessfullyServer is running: PONG
PHP string instance of Redis
 connect('127.0.0.1', 6379);   echo "Connection to server sucessfully";   //set the data in redis string   $redis->set("tutorial-name", "Redis tutorial");   // Get the stored data and print it   echo "Stored string in redis:: " . $redis.get("tutorial-name");?>

When the program is executed, the following results are generated:

Connection to server sucessfullyStored string in redis:: Redis tutorial
PHP list example of Redis
 connect('127.0.0.1', 6379);   echo "Connection to server sucessfully";   //store data in redis list   $redis->lpush("tutorial-list", "Redis");   $redis->lpush("tutorial-list", "Mongodb");   $redis->lpush("tutorial-list", "Mysql");   // Get the stored data and print it   $arList = $redis->lrange("tutorial-list", 0 ,5);   echo "Stored string in redis:: "   print_r($arList);?>

When the program is executed, the following results are generated:

Connection to server sucessfullyStored string in redis::RedisMongodbMysql
Redis PHP key example
 connect('127.0.0.1', 6379);   echo "Connection to server sucessfully";   // Get the stored keys and print it   $arList = $redis->keys("*");   echo "Stored keys in redis:: "   print_r($arList);?>

When the program is executed, the following results are generated:

Connection to server sucessfullyStored string in redis::tutorial-nametutorial-list

Http://www.bkjia.com/PHPjc/1133574.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1133574.htmlTechArticleRedis PHP connection operations, redisphp connection installation to use Redis in the PHP program, first of all need to ensure that the Redis PHP driver and PHP installation settings on the machine. You can view the PHP Tutorial...

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.