zoukankan      html  css  js  c++  java
  • tp5实现Redis的简单使用

    方法1:

    Controller

    <?php
    namespace appindexcontroller;
    
    use thinkController;
    use thinksessiondriverRedis;
    
    class Index extends Controller
    {
        public function index()
        {
            $redis = new Redis();
            if(!$redis->has('str')){
                var_dump($redis->set('str','this is redis_str'));
            }else{
                var_dump($redis->get('str'));
            }
        }
    }

    方法2:(前方雷区!!!)

    config.php

    // +----------------------------------------------------------------------
        // | 缓存设置
        // +----------------------------------------------------------------------
    
        'cache'                  => [
            // 驱动方式
            'type'   => 'File',
            // 缓存保存目录
            'path'   => CACHE_PATH,
            // 缓存前缀
            'prefix' => '',
             //缓存有效期 0表示永久缓存
            'expire' => 0,
        ],
    
        'redis'   =>  [
            // 驱动方式
            'type'   => 'redis',
            // 服务器地址
            'host'   => '127.0.0.1',  //redis服务器ip
            'port'   => '6379',
            'password'=> "",
            'timeout' => 86400
        ],
    

    Controller  

    <?php
    namespace appindexcontroller;
    
    use thinkCache;
    use thinkController;
    
    class Index extends Controller
    {
        public function index()
        {
            if(!Cache::has('str')){
                var_dump(Cache::set('str','this is redis_str'));
            }else{
                var_dump(Cache::get('str'));
            }
        }
    } 
    let the world have no hard-to-write code ^-^
  • 相关阅读:
    Python
    Linux, Nginx
    Python
    C#图像处理(各种旋转、改变大小、柔化、锐化、雾化、底片、浮雕、黑白、滤镜效果)
    堆——神奇的优先队列(下)
    堆——神奇的优先队列(上)
    二叉树
    开启“树”之旅
    巧妙的邻接表(数组实现)
    Dijkstra最短路算法
  • 原文地址:https://www.cnblogs.com/ovim/p/11240885.html
Copyright © 2011-2022 走看看