在安装predis扩展之前先安装composer,安装教程在https://getcomposer.org/download/:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('SHA384', 'composer-setup.php') === 'c32408bcd017c577ce80605420e5987ce947a5609e8443dd72cd3867cc3a0cf442e5bf4edddbcbe72246a953a6c48e21') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php');"
接着把composer设置全局环境变量:
mv composer.phar /bin/composer
把composer镜像地址改为国内的会快很多,教程地址:http://pkg.phpcomposer.com/
composer config -g repo.packagist composer https://packagist.phpcomposer.com
然后开启php-pear,php-devel和php-redis扩展,我是直接用CentOS 的yum包来安装扩展:
yum -y install php70w-devel.x86_64 yum install php70w-pear.noarch yum -y install php70w-pecl-redis.x86_64
安装完成后切换到你的网站根目录下,成功后如图所示:
composer require predis/predis Using version ^1.1 for predis/predis ./composer.json has been updated > php artisan clear-compiled Loading composer repositories with package information Updating dependencies (including require-dev) - Installing predis/predis (v1.1.1) Downloading: 100% predis/predis suggests installing ext-phpiredis (Allows faster serialization and deserialization of the Redis protocol) Writing lock file Generating autoload files > php artisan optimize
接着就可以在你的Controller中使用 use Redis 来各种操作了。