国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

ThinkPHP6.0+ 使用Redis 原始用法

這篇具有很好參考價值的文章主要介紹了ThinkPHP6.0+ 使用Redis 原始用法。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報違法"按鈕提交疑問。

composer 安裝 predis/predis 依賴,或者安裝php_redis.dll的擴(kuò)展。

我這里選擇的是predis/predis 依賴。

composer require predis/predis

進(jìn)入config/cache.php 配置添加redis緩存支持
示例:

ThinkPHP6.0+ 使用Redis 原始用法,redis,bootstrap,數(shù)據(jù)庫,php

<?php

// +----------------------------------------------------------------------
// | 緩存設(shè)置
// +----------------------------------------------------------------------

return [
    // 默認(rèn)緩存驅(qū)動
    'default' => env('cache.driver', 'file'),

    // 緩存連接方式配置
    'stores'  => [
        'file' => [
            // 驅(qū)動方式
            'type'       => 'File',
            // 緩存保存目錄
            'path'       => '',
            // 緩存前綴
            'prefix'     => '',
            // 緩存有效期 0表示永久緩存
            'expire'     => 0,
            // 緩存標(biāo)簽前綴
            'tag_prefix' => 'tag:',
            // 序列化機(jī)制 例如 ['serialize', 'unserialize']
            'serialize'  => [],
        ],
        // 更多的緩存連接
    ],
    // redis緩存
    'redis' =>  [
        'type'  =>  'redis',
        'host'  =>  '127.0.0.1',
        'timeout'=> 3600
    ],
    
    
];

ThinkPHP6.0+ 使用Redis 原始用法,redis,bootstrap,數(shù)據(jù)庫,php

頁面測試代碼

ThinkPHP6.0+ 使用Redis 原始用法,redis,bootstrap,數(shù)據(jù)庫,php

<?php
namespace app\controller;

use app\BaseController;
use think\facade\Cache;

class Index extends BaseController
{
    public function index()
    {
        //Cache::set('name', [1,2,3]);
        //(Cache::get('name'));
        Cache::store('redis')->set('name', [1,2,3]);
        dump(Cache::store('redis')->get('name'));
    }
}

ThinkPHP6.0+ 使用Redis 原始用法,redis,bootstrap,數(shù)據(jù)庫,php

效果

ThinkPHP6.0+ 使用Redis 原始用法,redis,bootstrap,數(shù)據(jù)庫,php

redis 高級用法

在php 原生中redis 的使用是

ThinkPHP6.0+ 使用Redis 原始用法,redis,bootstrap,數(shù)據(jù)庫,php

        //加載擴(kuò)展
        $redis = new \Redis();
        //連接擴(kuò)展
        $redis->connect("127.0.0.1","6379");
  
        //判斷是否過期
        $redis_status = $redis->exists("info");
        if($redis_status==false){
            //緩存失效,重新存入
            //查詢數(shù)據(jù)
            $Info = db("user")->where('id', $userId)->find();
            //轉(zhuǎn)換成字符串,有利于存儲
            $redisInfo = serialize($Info);
            //存入緩存
            $redis->set("info",$redisInfo);
            //設(shè)置緩存周期,60秒
            $redis->expire("info",60);
            var_dump("新存入的值");
        }
        //獲取緩存
        $result = unserialize($redis->get("info"));
  
        //當(dāng)前時間
        var_dump(date("Y-m-d H:i:s",time()));
        var_dump($result);

ThinkPHP6.0+ 使用Redis 原始用法,redis,bootstrap,數(shù)據(jù)庫,php

thinkephp 中要使用php redis 的擴(kuò)展方法。則需使用handler();
代碼示例

$redis = Cache::store('redis')->handler(); // 這條代碼等于  $redis = new \Redis();

$redis->set("info",'hello world');   // 設(shè)置字段
$redis->expire("info",10);  // 設(shè)置過期時間
var_dump($result); //1 沒過期,2 為過期;

根據(jù)菜鳥教程,試一下列表存儲:

ThinkPHP6.0+ 使用Redis 原始用法,redis,bootstrap,數(shù)據(jù)庫,php

?代碼:

ThinkPHP6.0+ 使用Redis 原始用法,redis,bootstrap,數(shù)據(jù)庫,php

$redis = Cache::store('redis') -> handler();
        $redis->lpush("tutorial-list", "Redis");
        $redis->lpush("tutorial-list", "Mongodb");
        $redis->lpush("tutorial-list", "Mysql");
        // 獲取存儲的數(shù)據(jù)并輸出
        $arList = $redis->lrange("tutorial-list", 0 ,5);
        echo "Stored string in redis";
        print_r($arList);

ThinkPHP6.0+ 使用Redis 原始用法,redis,bootstrap,數(shù)據(jù)庫,php

成功!文章來源地址http://www.zghlxwxcb.cn/news/detail-654761.html

到了這里,關(guān)于ThinkPHP6.0+ 使用Redis 原始用法的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • thinkphp6 入門教程合集(更新中) thinkphp6 入門(1)--安裝、路由規(guī)則、多應(yīng)用模式

    thinkphp6 入門(1)--安裝、路由規(guī)則、多應(yīng)用模式_軟件工程小施同學(xué)的博客-CSDN博客 thinkphp6 入門(2)--視圖、渲染html頁面、賦值_軟件工程小施同學(xué)的博客-CSDN博客 thinkphp6 入門(3)--獲取GET、POST請求的參數(shù)值_thinkphp獲取get傳值_軟件工程小施同學(xué)的博客-CSDN博客 thinkphp6 入門(

    2024年02月09日
    瀏覽(52)
  • thinkphp6和thinkphp5有什么區(qū)別

    Thinkphp6.0完全開發(fā)手冊 采用PHP7強(qiáng)類型(嚴(yán)格模式) tp5 環(huán)境要求PHP = 5.4.0 ThinkPHP6.0的環(huán)境要求 PHP = 7.2.5 6.0版本開始,必須通過Composer方式安裝和更新,所以你無法通過Git下載安裝。 支持更多的PSR規(guī)范 V6.0.10版本開始 支持 psr7 response 多應(yīng)用支持 tp5默認(rèn)使用多應(yīng)用模式部署 tp6 安

    2024年02月06日
    瀏覽(21)
  • thinkPHP6接入workman

    thinkPHP6接入workman

    上篇介紹了workman實(shí)現(xiàn)websocket功能(鏈接:https://blog.csdn.net/weixin_38155824/article/details/128952037) 后傳:解決workman部署到Linux環(huán)境無法啟動和連接的問題(https://blog.csdn.net/weixin_38155824/article/details/129004050) 這篇就介紹如何在thinkPHP6項(xiàng)目中接入workman。 查看TP6手冊:命令行=自定義命

    2024年02月15日
    瀏覽(34)
  • thinkphp6-配置設(shè)置與獲取,Thinkphp6自定義配置文件以及調(diào)用(config文件夾下的配置)

    thinkphp6-配置設(shè)置與獲取,Thinkphp6自定義配置文件以及調(diào)用(config文件夾下的配置)

    環(huán)境變量 設(shè)置環(huán)境變量 /.env [DATABASE] USERNAME = root PASSWORD = 123456 獲取環(huán)境變量 app/controller/Index.php 訪問測試 http://codeit.org.cn/index {“username”:“root”,“password”:“123456”} 1.在thinkphpconfig下新建一個test.php配置文件 .test.php文件內(nèi)容 調(diào)用test.php配置文件 配置 配置設(shè)置 config/app.

    2024年02月13日
    瀏覽(34)
  • Thinkphp6 如何 生成二維碼

    來自:https://www.is5.me/notes/php/633.html

    2024年02月11日
    瀏覽(19)
  • thinkphp6 動態(tài)開啟debug模式

    1、找到config/app.php?? 2、自定義開啟debug參數(shù)名稱:示例參數(shù)為debug,可以根據(jù)自己項(xiàng)目情況自定義? 3、必須同時設(shè)置App::debug 和 Env::set(\\\'APP_DEBUG\\\')

    2024年02月07日
    瀏覽(21)
  • ThinkPHP6.0 鏈?zhǔn)絊QL語句

    查詢單個數(shù)據(jù) 查詢結(jié)果集(查詢結(jié)果返回多條數(shù)據(jù)的意思) ? 查詢一個字段 ? 查詢一列 添加數(shù)據(jù) 修改數(shù)據(jù) 刪除數(shù)據(jù) 根據(jù)主鍵刪除 ? 條件刪除 ? 查詢數(shù)據(jù) 格式 where(\\\'字段名\\\',\\\'查詢表達(dá)式\\\',\\\'查詢條件\\\'); 模糊查詢 區(qū)間查詢 IN查詢 Not Null Null 鏈?zhǔn)讲僮魇纠?field操作(輸出選擇

    2024年02月11日
    瀏覽(29)
  • ThinkPHP6企業(yè)OA辦公系統(tǒng)

    ThinkPHP6企業(yè)OA辦公系統(tǒng)

    有需要請加文章底部Q哦 可遠(yuǎn)程調(diào)試 ThinkPHP6企業(yè)OA辦公系統(tǒng) 勾股OA基于ThinkPHP6開發(fā),前端Layui,數(shù)據(jù)庫mysql,是一款實(shí)用的企業(yè)辦公系統(tǒng)。可多角色登錄,集成了系統(tǒng)設(shè)置、人事管理、消息管理、審批管理、日常辦公、客戶管理、合同管理、項(xiàng)目管理、財務(wù)管理等模塊。系統(tǒng)簡

    2024年02月13日
    瀏覽(26)
  • thinkphp6入門(23)-- 如何導(dǎo)入excel

    thinkphp6入門(23)-- 如何導(dǎo)入excel

    1. 安裝phpexcel 2. 前端 3.?后端 注:現(xiàn)在主要使用phpoffice/phpspreadsheet庫,phpoffice/phpexcel已經(jīng)不再維護(hù),但本文由于環(huán)境無法更新,所以就安裝了phpoffice/phpexcel?;静僮饕粯印?參考:https://www.tpxhm.com/fdetail/725.html 注: 一、在ubuntu環(huán)境下提示?Class \\\'ZipArchive\\\' not found ?查看對應(yīng)的

    2024年04月14日
    瀏覽(24)
  • ThinkPHP6之?dāng)?shù)據(jù)庫操作上

    ThinkPHP6之?dāng)?shù)據(jù)庫操作上

    注意,tp6在進(jìn)行語法學(xué)習(xí)的時候都是在app/index.php中寫代碼的,代碼寫在index函數(shù)下面,而且 tp6自帶的文件都是由自動加載器的,不需要包含autoload.php文件 要對數(shù)據(jù)庫進(jìn)行操作,要修改兩個地方,一個數(shù).env文件,一個是config/database.php文件 config/database.php connections里面的一個子

    2024年02月01日
    瀏覽(16)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包