PHP通过redis扩展使用redis

PHP通过redis扩展使用redis

一、下载phpredis:

百度分享: http://pan.baidu.com/s/1kVfZ0nP 

或者:https://github.com/nicolasff/phpredis.git

二、安装

[[email protected] ~]# cd /data/software/
[[email protected] software]# git clone https://github.com/nicolasff/phpredis.git phpredis
[[email protected] software]# cd phpredis/
[[email protected] phpredis]# which phpize
报错:
/usr/bin/which: no phpize in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)    
yum install -y php-devel 然后就会安装上phpize

[[email protected] phpredis]# phpize
[[email protected] phpredis]# ./configure
[[email protected] phpredis]# make && make install
[[email protected] phpredis]# make test
+-----------------------------------------------------------+
|                       ! ERROR !                           |
| The test-suite requires that proc_open() is available.    |
| Please check if you disabled it in php.ini.               |
+-----------------------------------------------------------+

如果顺利,将得到类似如下提示:

Installing shared extensions:     /usr/lib64/php/modules/
或者
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/ 

三、修改php.ini配置文件

加载redis.so
在php.ini 文件中,添加配置:

[redis]
extension=redis.so

重启web服务,echo phpinfo() 看是否有redis关键字。

测试

新建test.php

<?php
ini_set("display_errors", "On");
$redis = new Redis();
$conn = $redis->connect('192.168.1.4', 6379);
$auth = $redis->auth('123456'); //设置密码
//var_dump($auth);
$redis->set('name1', "1111111");
$redis->set('name2', "222222");

var_dump($redis->get("name1"));
var_dump($redis->get("name2"));

访问url,再验证

[[email protected] ~]# redis-cli -h 192.168.1.4 -p 6379 -a 123456
192.168.1.4:6379> get name1
"1111111"
192.168.1.4:6379> get name2
"222222"

参考:

#####PHP通过redis扩展使用redis
http://blog.csdn.net/love__coder/article/details/8691679

未经允许不得转载:好玩吧 » PHP通过redis扩展使用redis