Home >Backend Development >PHP Tutorial >laravel如何安装predis?

laravel如何安装predis?

PHPz
PHPzOriginal
2016-06-06 20:42:065322browse

laravel安装predis的方法:首先安装“redis-server”;然后服务器开启“redis-server”;接着让指定的php来进行composer下载predis插件;最后在控制器中使用即可。

laravel如何安装predis?

laravel如何安装predis?

1、服务器先安装redis-server,这是毋庸置疑的!!!

2、服务器开启redis-server,配置相关参数

3、laravel执行 : $  yourPhpPath composer.phar require predis/predis:1.0.*  ,这个命令如果服务器多个php运行,且php -v 低于5.6,可以让指定的php来进行composer下载predis插件,(如果你php -v 和phpinfo()的版本一致,且composer.phar 配置成全局/usr/local/bin/composer),那么可以直接运行 【cmoposer require predis/predis:1.0.*】安装。

4、在控制器中使用:

首先引入:

use Illuminate\Support\Facades\Redis;
 
public function sendMsg2(Request $request){
//echo dirname(__DIR__);
//echo phpinfo();
$redis = Redis::connection(); //返回redis链接实例,可以操作所有redis原生命令
$redis->set('name', 'Taylor');
$name = $redis->get('name');
var_dump($name);  //输出 ‘Taylor’;
//echo 11;
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn