redis客户端介绍及php客户端的下载安装

一、PHP客户端
1、官方提供了几款PHP客户端,包括amphp/redis、phpredis、Predis、Rediska。推荐使用官方推荐的两款客户端,phpredis、Predis
2、phpredis是一个二进制版本的PHP客户端,效率要比Predis高。这个版本支持作为Session的Handler。这个扩展的优点在于无需加载任何外部文件,使用比较方便。
3、Predis是一个灵活和特性完备(PHP>5.3)的支持Redis的PHP客户端。优点就是无须安装PHP扩展包,直接加载使用即可,在保证PHP版本在5.3版本之上的情况下,即使迁移服务器也不受影响。
4、缺点就是性能相较于phpredis较差。

二、phpredis客户端的安装
1、phpredis的github地址:https://github.com/phpredis/phpredis
直接git clone https://github.com/phpredis/phpredis.git
2、cd phpredis
3、phpize
./configure [--enable-redis-igbinary] [--enable-redis-msgpack] [--enable-redis-lzf [--with-liblzf[=DIR]]]
make && make install

官方对configure几个参数的说明
If you would like phpredis to serialize your data using the igbinary library, run configure with --enable-redis-igbinary. If you would like to use the msgpack serializer, run configure with --enable-redis-msgpack (note: Requires php-msgpack >= 2.0.3) The extension also may compress data before sending it to Redis server, if you run configure with --enable-redis-lzf. If you want to use lzf library pre-installed into your system use --with-liblzf configuration option to specify the path where to search files. make install copies redis.so to an appropriate location, but you still need to enable the module in the PHP config file. To do so, either edit your php.ini or add a redis.ini file in /etc/php5/conf.d with the following contents: extension=redis.so.

如果不使用参数可以直接./configure
执行以后会报一个configure: error: Cannot find php-config. Please use --with-php-config=PATH错误,没有找到php-config
所以需要使用./configure --with-php-config=PATH,其中PATH是你php-config命令所在的目录

4、看到如下图所示信息说明扩展包文件已经搭好,并且放在/usr/local/php/lib/php/extensions/no-debug-non-zts-20180731/目录下

 

5、需要将redis.so加载到php.ini中
vim /usr/local/php/etc/php.ini

6、重启php-fpm和nginx
lnmp php-fpm restart
lnmp nginx restart
7、使用php -m命令查看

 说明安装成功

8、打开phpinfo

 9、测试写入数据

1)新建redisdemo.php
2)写入如下代码

$redis = new Redis();

$a = $redis->connect("主机IP",6379);

var_dump($a);
//打印结果:bool(true) 说明链接成功
$redis->set("test","test");

执行以后查看服务器

原文地址:https://www.cnblogs.com/lxhyty/p/11526982.html