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 ^-^
  • 相关阅读:
    spicy及remote-viewer登录方法
    1000: 恶意IP 课程作业
    一种快速找数的方法
    基数排序c++实现
    二叉排序树的实现
    sicily 数据结构 1014. Translation
    堆排序实现
    插入排序实现--直接实现,二分插入实现
    希尔排序--改进的插入排序
    归并排序--较快的算法之一
  • 原文地址:https://www.cnblogs.com/ovim/p/11240885.html
Copyright © 2011-2022 走看看