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