Redis PHP connection operation, redisphp connection _php Tutorial

Source: Internet
Author: User
Tags redis server redis tutorial

Redis PHP connection operation, redisphp connection


Installation

To use Redis in a PHP program, you first need to make sure that the Redis PHP driver and the PHP installation are set up on the machine. You can view PHP tutorials to teach you how to install PHP on your machine. Now, let's look at how to set up a Redis PHP driver.

Need to download Phpredis from GitHub on the repository: Https://github.com/nicolasff/phpredis. After the download is complete, unzip the file to the Phpredis directory. Install this extension on Ubuntu, which can be installed using the commands shown.

CD Phpredissudo Phpizesudo./configuresudo Makesudo Make Install

Now copy and paste the contents of the "modules" folder into the PHP extension directory and add the following lines in the php.ini.

Extension = redis.so

Now the Redis and PHP installation is complete.

Connect to a Redis server

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

When the program executes, the following results are produced:

Connection to server Sucessfullyserver is Running:pong

Example of a Redis PHP string

  
   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 executes, the following results are produced:

Connection to server sucessfullystored string in Redis:: Redis Tutorial

Example of a redis PHP column

  
   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 executes, the following results are produced:

Connection to server sucessfullystored string in Redis::redismongodbmysql

Example of a Redis PHP key

  
   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 executes, the following results are produced:

Connection to server sucessfullystored string in Redis::tutorial-nametutorial-list

http://www.bkjia.com/PHPjc/1133574.html www.bkjia.com true http://www.bkjia.com/PHPjc/1133574.html techarticle Redis PHP Connection operation, redisphp connection installation to use Redis in a PHP program, you first need to make sure that the Redis PHP driver and the PHP installation are set up on the machine. You can view PHP tutorials to teach ...

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