Using Redis with PHP

Source: Internet
Author: User
Tags php redis redis tutorial

before PHP uses Redis installation to start using Redis in PHP, we need to make sure that the Redis service and the PHP Redis driver are installed, and that PHP is working properly on your machine. Next, let's install the PHP redis driver:: https://Github.com/nicolasff/phpredis. PHP installation Redis extensions/usr/local/php/bin/phpize #php安装后的路径./configure--with-php-config=/usr/local/php/bin/php-Configmake&&Make Install modify php.ini file VI/usr/local/php/lib/php.ini Add the following content: Extension_dir="/usr/local/php/lib/php/extensions/no-debug-zts-20090626"extension=redis.so Restart PHP when the installation is complete-fpm or Apache. View the phpinfo information to see the Redis extension. PHP connects to Redis service using Redis<?PHP//Connect to a local Redis service$redis =NewRedis (); $redis->connect ('127.0.0.1',6379); Echo"Connection to server sucessfully"; //See if the service is runningEcho"Server is running:". $redisPing ();?>execute script with output as: Connection to server Sucessfullyserver isRunning:pongredis PHP String (string) instance<?PHP//Connect to a local Redis service$redis =NewRedis (); $redis->connect ('127.0.0.1',6379); Echo"Connection to server sucessfully"; //setting up Redis string Data$redisSet("Tutorial-name","Redis Tutorial"); //get the stored data and outputEcho"Stored string in Redis::". $redisGet("Tutorial-name");?>execute script with output as: Connection to server sucessfullystoredstring inchRedis:: Redis tutorialredis PHP list (list) instance<?PHP//Connect to a local Redis service$redis =NewRedis (); $redis->connect ('127.0.0.1',6379); Echo"Connection to server sucessfully"; //storing data in a list$redis->lpush ("tutorial-list","Redis"); $redis->lpush ("tutorial-list","Mongodb"); $redis->lpush ("tutorial-list","Mysql"); //get the stored data and output$arList = $redis->lrange ("tutorial-list",0,5); Echo"Stored string in Redis::"Print_r ($arList);?>execute script with output as: Connection to server sucessfullystoredstring inchRedis::redismongodbmysqlredis PHP Keys instance<?PHP//Connect to a local Redis service$redis =NewRedis (); $redis->connect ('127.0.0.1',6379); Echo"Connection to server sucessfully"; //get the data and output$arList = $redis->keys ("*"); Echo"Stored keys in Redis::"Print_r ($arList);?>execute script with output as: Connection to server sucessfullystoredstring inchredis::tutorial-nametutorial-list

Using Redis with PHP

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.