redis/php redis擴展 安裝
作者:silenceper
日期:2013-10-03
原文地址: http://silenceper.com/archives/952.html
我是在CentOS 6.3 中進行的。
使用到的軟件:
redis 2.6.16 :http://download.redis.io/releases/redis-2.6.16.tar.gz
tcl : http://prdownloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
php redis 擴展:https://github.com/nicolasff/phpredis
phpRedisAdmin(redis管理工具): https://github.com/ErikDubbelboer/phpRedisAdmin
一、安裝redis
首頁安裝tcl
[shell]
wget -c http://prdownloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
tar -zxvf tcl8.6.1-src.tar.gz
cd tcl8.6.1/unix
./configure
make && make install
[/shell]
tcl安裝成功之后安裝redis服務
[shell]
wget -c http://download.redis.io/releases/redis-2.6.16.tar.gz
tar -zxvf redis-2.6.16.tar.gz
cd redis-2.6.16
make
make test
make install
[/shell]
安裝成功~
啟動redis服務:
[shell]
vim /usr/local/src/redis-2.6.16/redis.conf //將daemonize 設置為yes
/usr/local/bin/redis-server /usr/local/src/redis-2.6.16/redis.conf
ps aux|grep redis
root 24823 0.2 0.3 31764 1596 ? Ssl 17:20 0:00 redis-server redis.conf
[/shell]
使用 redis-cli 連接,當然也可以使用telnet
測試:
[shell]
[root@localhost redis-2.6.16]# redis-cli
redis 127.0.0.1:6379> set name silenceper
OK
redis 127.0.0.1:6379> get name
"silenceper"
redis 127.0.0.1:6379>
[/shell]
關閉 可以使用命令redis-cli shutdown (推薦),它完成的操作包括:
- 停止所有客戶端
- 如果有至少一個保存點在等待,執行 SAVE 命令
- 如果 AOF 選項被打開,更新 AOF 文件
- 關閉 redis 服務器(server)
如果持久化被打開的話, SHUTDOWN 命令會保證服務器正常關閉而不丟失任何數據。
使用redis-cli --help 查看更多選項
關于redis 2.4 配置文件中文說明說明:
https://github.com/silenceper/my/blob/master/config/redis2.4.chinese
redis 命令手冊:
http://redis.readthedocs.org/cn/latest/index.html
使用phpRedisAdmin 管理redis
[shell]
git clone https://github.com/ErikDubbelboer/phpRedisAdmin.git
cd phpRedisAdmin
git clone https://github.com/nrk/predis.git vendor
[/shell]
移至一個可以訪問的目錄就可以管理了!(如果出錯看看是否關閉了selinux )
二、php擴展redis.so安裝
[shell]
wget -c http://pecl.php.net/get/redis-2.2.4.tgz
tar -zxvf redis-2.2.4.tgz
cd redis-2.2.4
phpize
./configure --with-php-config=/usr/bin/php-config
make && make install
[/shell]
將extension=redis.so 加入php.ini文件
重啟httpd
查看phpinfo 可以看到redis擴展已經成功加載
三、使用php操作redis
[php]
<?php
$redis=new Redis();
$redis->connect('192.168.1.103',6379);
$redis->set("name","silenceper");
echo $redis->get('name');
?>
[/php]
使用redis 無法直接存儲數組 對象 可以考慮使用序列化/反序列化 進行存取。
網上找了個php-redis手冊 : http://pan.baidu.com/s/1gNSh6
浙公網安備 33010602011771號