gpt4 book ai didi

php - 我如何在 controller.php 中将 redis 更改为 mysql

转载 作者:可可西里 更新时间:2023-11-01 11:27:51 24 4
gpt4 key购买 nike

如何将其更改为不使用 redis。在 .env 中,我没有将 redis 作为 DB_CONNECTION。 idk 我怎么能删除这个 redis,因为没有 ingerence 我无法启动我的网站...非常感谢帮助和任何答案。

这是我的 controller.php,其中 31-33 有错误

<?php

namespace App\Http\Controllers;

use Auth;
use LRedis;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;

abstract class Controller extends BaseController
{
use DispatchesJobs, ValidatesRequests;

public $user;
public $redis;
public $title;

public function __construct()
{
$this->setTitle('Title not stated');
if(Auth::check())
{
$this->user = Auth::user();
view()->share('u', $this->user);
}
$this->redis = LRedis::connection();
view()->share('steam_status', $this->getSteamStatus());
}

public function __destruct()
{
$this->redis->disconnect();
}

public function setTitle($title)
{
$this->title = $title;
view()->share('title', $this->title);
}

public function getSteamStatus()
{
$inventoryStatus = $this->redis->get('steam.inventory.status');
$communityStatus = $this->redis->get('steam.community.status');

if($inventoryStatus == 'normal' && $communityStatus == 'normal') return 'good';
if($inventoryStatus == 'normal' && $communityStatus == 'delayed') return 'normal';
if($inventoryStatus == 'critical' || $communityStatus == 'critical') return 'bad';
return 'good';
}

}

这是我的.env

APP_NAME=Laravel
APP_ENV=local
APP_KEY=l2ggh1imVxJ7Oj6BotPUWinAIDgJfBYw
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=csgo
DB_USERNAME=root
DB_PASSWORD=secret

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=localhost
REDIS_PASSWORD=null
REDIS_PORT=4563

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=

pplssss 帮助我!

最佳答案

你可以像这样访问你的数据库表
首先,您需要在文件顶部添加此代码

use Illuminate\Support\Facades\DB;

然后

$steamDetail= DB::table('steam')->get();//This will return all the data from steam table
$steamStatusArray=DB::table('steam')->pluck('status');//This will return only the status column from steam table

Reference- Laravel Query Builder
注意:你必须删除所有与LRedis

相关的代码如果你不知道从哪里开始试试这个 tutorial 。它可能会给您灵感。

关于php - 我如何在 controller.php 中将 redis 更改为 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44133149/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com