Laravel-redis处理

栏目: 编程语言 · PHP · 发布时间: 6年前

内容简介:在Laravel版本5.3之前是存在隐式控制器的处理的,但是在其之后被移除了,详情可以这里我们使用的PHP版本为7.3,而要安装的Laravel版本为5.3。首先是配置数据源,以便解决依赖问题:之后我们创建1个blog的项目:

Laravel 版本5.3之前是存在隐式控制器的处理的,但是在其之后被移除了,详情可以 参考

这里我们使用的 PHP 版本为7.3,而要安装的Laravel版本为5.3。首先是配置数据源,以便解决依赖问题:

composer config repo.packagist composer https://packagist.phpcomposer.com

之后我们创建1个blog的项目:

composer create-project --prefer-dist laravel/laravel blog "5.3.*"

这里我们指定其版本为 5.3.x ,具体版本视数据源而定。

为了避免出现类似如下的异常:

The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.

我们需要运行运行的命令生成秘钥:

php artisan key:generate

之后我们添加predis以便进行 redis 的操作:

composer require predis/predis

接下来我们创建1个控制器:

php artisan make:controller IndexController  
Controller created successfully.

app/Http/Controllers 目录下对 IndexController.php 进行如下的修改:

<?php  

namespace App\Http\Controllers;  

use Illuminate\Http\Request;  
use Illuminate\Support\Facades\Redis;  

class IndexController extends Controller  
{  
    public function index($name){  
        echo Redis::get($name);  
        return '<br>1111</br>';  
    }  
}

我们引入Redis类,之后就可以调用其一些方法进行操作。

最后是路由的配置,对 routes/web.php 文件进行如下的修改:

Route::get("hello/{name}","IndexController@index");

这样当我们访问 hello/xxx ,就会把xxx作为redis的键传入。


以上所述就是小编给大家介绍的《Laravel-redis处理》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Nginx Essentials

Nginx Essentials

Valery Kholodkov / Packt Publishing / 2015-7-1 / USD 34.99

About This Book Learn how to set up, configure, and operate an Nginx installation for day-to-day useExplore the vast features of Nginx to manage it like a pro, and use them successfully to run your......一起来看看 《Nginx Essentials》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

html转js在线工具
html转js在线工具

html转js在线工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试