redis教程:redis的安裝與php擴充套件配置
Redis的安裝
cd /usr/local
wget http://download.redis.io/redis-stable.tar.gz
tar zxvf redis-stable.tar.gz
cd redis-stable //進入解壓目錄
make //編譯安裝
make install //將可執行程式賦值到/usr/local/bin目錄中,當執行程式中就不要輸入完整的路徑
make test //測試redis是否編譯正確
現在,Redis PHP安裝完成!
設定Redis PHP驅動程式
從github庫下載phpredis
http://github.com/nicolasff/phpredis
當下載它之後,
git checkout 4.1.1
切換到最新版本
cd phpredis
sudo phpize
sudo ./configure
sudo make
sudo make install
如果出現error:
error: Cannot find php-config. Please use --with-php-config=PATH
加上php-config的路徑
# sudo ./configure --with-php-config=/usr/local/php/bin/php-config
現在,將“modules
php.ini
中新增以下行。
extension = redis.so
現在,Redis PHP安裝完成!
重啟 php-fpm
開啟redis服務
進入 src 目錄
執行 ./redis-server &
& 表示後臺啟動
/redis-cli
進入客戶端
使用連線到Redis伺服器
<?php //Connecting to Redis server on localhost $redis = new Redis(); $redis->connect('127.0.0.1', 6379); echo "Connection to server sucessfully"; //check whether server is running or not echo "Server is running: ".$redis->ping(); ?>
當程式執行時,將產生以下結果。
Connection to server sucessfully
Server is running: PONG
教程手冊
phpredis 中文手冊 : http://www.cnblogs.com/zcy_soft/archive/2012/09/21/2697006.html
手冊: http://www.cnblogs.com/weafer/archive/2011/09/21/2184059.html
redis教程: http://www.yiibai.com/redis/redis_quick_guide.html