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