php安装redis扩展后,使用keys方法返回NULL

使用phpredis 的 keys 方法,获取不到keys列表,一直返回为null。

确认redis中有多个key,也确认在服务器上redis-cli下能够获取到key列表。

起初考虑是redis配置问题,各种查找没解决问题。

后来发现本地远程连接redis可以获取到key列表,但是上传到服务器上后就不可以了。

猜测是线上环境问题,phpinfo查看本地和线上的redis的信息,发现本地的版本高于线上,那应该是版本问题。

上github上下载最新版本phpredis扩展

git clone https://github.com/phpredis/phpredis.git

进入phpredis文件夹

cd phpredis

生成configure文件

/usr/local/php/bin/phpize

指定配置

./configure –with-php-config=/usr/local/php/bin/php-config

编译安装

make && make install

重启php-fpm(因为不是首次安装,只是替换升级,不需要再修改php.ini文件了)

/etc/init.d/php-fpm restart

完成后,在使用keys方法,能够成功获得keys结果了

作者: 二皮

Hackers please go away