exit 0
启动redis:service redis start
2、安装httpd
# yum -y install httpd 3、安装php
# yum -y install php 4、安装php-devel
# yum -y install php-devel 5、安装php-redis
#安装前,安装phpsize,phpsize是php的程序,在你php的安装目录的bin目录下,执行即可
# phpsize
# ./configure [--enable-redis-igbinary]
# make && make install
---安装完成----
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/lib64/php/modules/
---------------
添加redis模块:vim php.ini
extension=redis.so
重启apache服务器
service httpd restart
测试:cd /var/www/html
vim redis.php
打开浏览器:
------------
name is:xcroom
xcroom
------------
测试成功 php操作redis的相关函数:
1、实例化redis类
$redis = new Redis();
2、open,connect
host: string. can be a host, or the path to a unix domain socket(主机)
port: int, optional(端口)
timeout: float, value in seconds (optional, default is 0 meaning unlimited)(连接超时断开的时间)
实例:
$redis->connect('127.0.0.1', 6379);
$redis->connect('127.0.0.1'); // port 6379 by default
$redis->connect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout.
$redis->connect('/tmp/redis.sock'); // unix domain socket.
$redis->connect('127.0.0.1', 6379, 1, NULL, 100); // 1 sec timeout, 100ms delay between reconnection attempts.
3、pconnect, popen,长连接
4、auth
$redis->auth('foobared');
5、select,切换数据库
$redis->select(0); // switch to DB 0
6、close
7、setOption 设置redis模式 ,Set client option.
8、getOption 查看redis设置的模式
9、ping #Check the current connection status