<h2 id="a1">介紹</h2>
-
Redis
是一個高性能的key-value數(shù)據(jù)庫。 -
Redis
提供了Java,C/C++,C#,PHP,JavaScript,Perl,Object-C,Python,Ruby,Erlang等客戶端。 - 下面,我們就講一下
<如何在Mac上安裝PhpRedis>
<h2 id="a2">Mac安裝步驟</h2>
<h3 id="a21">安裝Redis</h3>
下載
Redis
地址http://download.redis.io/releases/redis-3.0.3.tar.gz-
編譯并啟動(在解壓開的目錄下依次執(zhí)行以下命令)
make sudo make install redis-server
-
測試
shell$ redis-cli 127.0.0.1:6379> set name zergling OK 127.0.0.1:6379> get name "zergling"
<h3 id="a22">安裝PhpRedis</h3>
首先下載
PhpRedis
github地址: https://github.com/nicolasff/phpredis-
編譯安裝(在解壓開的目錄下依次執(zhí)行以下命令)
-
默認(rèn)php環(huán)境
phpize ./configure --with-php-config=/usr/bin/php-config sudo make sudo make install
-
xampp環(huán)境
(修改對應(yīng)的php命令路徑即可)/Applications/XAMPP/xamppfiles/bin/phpize ./configure --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config sudo make sudo make install
-
執(zhí)行
phpize
時可能會出現(xiàn)如下錯誤Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable.
解決辦法(已安裝
brew
的直接執(zhí)行第二句)ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)" brew install autoconf
-
-
修改
php.ini
/ect/php.ini
(默認(rèn)環(huán)境)
/Applications/XAMPP/xamppfiles/etc/php.ini
(xampp環(huán)境)在最后添加
extension=redis.so
重啟apache
-
驗證
php -m |grep redis /Applications/XAMPP/bin/php -m |grep redis
出現(xiàn)
redis
表示安裝成功
<h2 id="w1">Windows安裝步驟</h2>
<h3 id="w1_1">安裝Redis:</h3>
1.獲取Redis:
可以到GitHub上獲取到Windows版本的Redis。將壓縮包解壓至自定義目錄之內(nèi)。
文件介紹:
redis-benchmark.exe #基準(zhǔn)測試
redis-check-aof.exe # aof
redischeck-dump.exe # dump
redis-cli.exe # 客戶端
redis-server.exe # 服務(wù)器
redis.windows.conf # 配置文件
2.配置Redis:
windows 運行(快捷鍵:windows鍵+R鍵),輸入【cmd】命令,進入DOC操作系統(tǒng)窗口。
使用命令【redis-server.exe redis.windows.conf】,啟動redis 服務(wù)【如果您沒出現(xiàn)如下的錯誤,直接跳過】。如果您也像我一樣出現(xiàn)如下的錯誤,不用急,總有解決辦法滴!
解決辦法:
根據(jù)提示,是 maxheap 標(biāo)識有問題,打開配置文件 redis.windows.conf ,搜索 maxheap , 然后直接指定好內(nèi)容即可.
#
# maxheap <bytes>
maxheap 1024000000
然后再次啟動。
3.測試:
啟動redis服務(wù)的窗口,不用關(guān)閉,因為服務(wù)需要一直執(zhí)行,關(guān)閉服務(wù),直接關(guān)閉窗口就行。
新打開一個窗口,用自帶的客戶端工具進行測試 命令【redis-cli.exe】,詳細(xì)操作如下。
事例展示了一個基本的讀寫操作,設(shè)置set key->age,value->21,get age 得到key的值。
<h3 id="w1_2">安裝phpRedis:</h3>
1.添加phpredis擴展
首先,查看所用php編譯版本V6/V9 在phpinfo()中查看
2.下載擴展
地址:https://github.com/nicolasff/phpredis/downloads(注意所支持的php版本)
3.修改配置文件
將下載的php_redis.dll放在php擴展目錄中(ext),并修改配置文件php.ini(添加extension=php_redis.dll)
4.重新啟動服務(wù)
重新啟動服務(wù),查看phpinfo(),下面表示成功
<h2 id="a3">示例代碼</h2>
<?php
$redis = new Redis();
$redis->connect('127.0.0.1',6379);
$redis->set('name', 'zergling');
echo $redis->get('name');