后端開發用到php操作redis,在此將安裝測試過程中遇到的問題匯總記錄下來,以便以后參考?。ㄏ到y為ubuntu)1.redis安裝下載地址:http://download.redis.io/releases/ 解壓安裝: 復制代碼 代碼如下: tar -xvf redis-2.8.17.tar.gz make sudo make install 為方便使用,在/usr目錄下創建redis目錄,講如下幾個文件拷貝到/usr/redis/目錄下: 復制代碼 代碼如下: /yourdir/redis-2.8.17/redis.conf /yourdir/redis-2.8.17/src/redis-benchmark /yourdir/redis-2.8.17/src/redis-server /yourdir/redis-2.8.17/src/redis-cli 當然,你也可以通過軟連接的方式達到方便使用的目的。此外,你也可以將redis-server加入開機啟動,此處從略。2.redis測試1)先開啟redis服務端程序 為方便測試,我們將redis.conf配置文件中的loglevel和logfile的值,修改后如下: loglevel debug logfile “/tmp/redis.log” jay13@ubuntu:/usr/redis$ redis-server redis.conf 2)開啟redi客戶端,通過客戶端向redis數據庫中進行增刪改查操作。整個操作過程中生成的日志可以到/tmp/redis.log中查看。 以最簡單的key操作為例,實例如下:復制代碼 代碼如下: jay13@ubuntu:/usr/redis$ redis-cli 127.0.0.1:6379 set jay13 phpstudy.net OK 127.0.0.1:6379 set jay hello,world OK 127.0.0.1:6379 get jay "hello,world" 127.0.0.1:6379 get jay13 "phpstudy.net" 127.0.0.1:6379 del jay (integer) 1 127.0.0.1:6379 get jay (nil) 127.0.0.1:6379 set jay13 www.phpstudy.net OK 127.0.0.1:6379 get jay13 "www.phpstudy.net" 3.安裝phpredis擴展在使用sudo apt-get install php5安裝php時,默認是沒有安裝phpize的,我們安裝phpredis時,需要用到phpize,因此,需要先安裝phpize。 1)我們通過安裝php開發者工具來獲取phpize。執行如下命令即可: 復制代碼 代碼如下: sudo apt-get install php5-dev 2)獲取phpredis源文件 最新的phpRedis地址:https://github.com/nicolasff/phpredis 按照GitHub上的說明進行如下安裝時,復制代碼 代碼如下: phpize ./configure --enable-redis-igbinary make && make install 可能會出現如下出錯說明: 復制代碼 代碼如下: checking for igbinary includes... configure: error: Cannot find igbinary.h 這個是因為我們沒有igbinary擴展,這是phpredis依賴的一個東西。 好吧,怎么安裝igbinary呢?使用apt-get沒有無法安裝完成,我們通過下載安裝文件進行安裝。復制代碼 代碼如下: wget a http://pecl.php.net/get/igbinary-1.1.1.tgz /a