http://www.w3cschool.cc/redis/redis-php.html Installation
Before we start using Redis in PHP, we need to make sure that we have the Redis service and the PHP Redis driver 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 the 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-FPM or Apache after the installation is complete. View the phpinfo information to see the Redis extension.
Connect to the Redis service
<?php //Connect the local Redis service $redis = new Redis (); $redis->connect (' 127.0.0.1 ', 6379); echo "Connection to Server sucessfully"; See if the service is running echo "Server is running:" + $redis->ping ();? >
Execute the script with the output as:
Connection to server Sucessfullyserver is Running:pong
Redis Java String (string) instance
<?php //Connect the local Redis service $redis = new Redis (); $redis->connect (' 127.0.0.1 ', 6379); echo "Connection to Server sucessfully"; Set up Redis string data $redis->set ("Tutorial-name", "Redis Tutorial"); Get the stored data and output echo "Stored string in Redis::" + jedis.get ("Tutorial-name"); >
Execute the script with the output as:
Connection to server sucessfullystored string in Redis:: Redis Tutorial
Redis Java list (list) instance
<?php //Connect the local Redis service $redis = new Redis (); $redis->connect (' 127.0.0.1 ', 6379); echo "Connection to Server sucessfully"; Store data into the 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 the script with the output as:
Connection to server sucessfullystored string in Redis::redismongodbmysql
Redis Java Keys Instance
<?php //Connect the local Redis service $redis = new Redis (); $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 the script with the output as:
Connection to server sucessfullystored string in Redis::tutorial-nametutorial-list
**php using Redis