作者: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
1
2
3
4
5
|
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
|
tcl安装成功之后安装redis服务
1
2
3
4
5
6
|
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
|
安装成功~
启动redis服务:
1
2
3
4
|
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
|
使用 redis-cli 连接,当然也可以使用telnet
测试:
1
2
3
4
5
6
|
[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>
|
关闭 可以使用命令redis-cli 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
1
2
3
|
git clone https:
//github
.com
/ErikDubbelboer/phpRedisAdmin
.git
cd
phpRedisAdmin
git clone https:
//github
.com
/nrk/predis
.git vendor
|
移至一个可以访问的目录就可以管理了!
二、php扩展redis.so安装
1
2
3
4
5
6
|
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
|
将extension=redis.so 加入php.ini文件
重启httpd
查看phpinfo 可以看到redis扩展已经成功加载
三、使用php操作redis
1
2
3
4
5
6
|
<?php
$redis
=
new
Redis();
$redis
->connect(
'192.168.1.103'
,6379);
$redis
->set(
"name"
,
"silenceper"
);
echo
$redis
->get(
'name'
);
?>
|
使用redis 无法直接存储数组 对象 可以考虑使用序列化/反序列化 进行存取。
网上找了个php-redis手册 : http://pan.baidu.com/s/1gNSh6