zoukankan      html  css  js  c++  java
  • PHP—Redis

      在PHP源码中redis是可以直接new redis的,但是在thinkPHP5中直接new的话会直接报致命的错误,错误的信息说没有引用名空间。以下是简单的调用redis的代码

      致命错误: Class 'apphomecontrollerRedis' not found

    thinkPHP5.0

    use thinkcachedriverRedis;
    
    class Index extends LoginController
    {
    
        public function index(){
        $config = [
          'host' => '127.0.0.1',
          'port' => 6379,
          'password' => '',
          'select' => 0,
          'timeout' => 0,
          'expire' => 0,
          'persistent' => false,
          'prefix' => '',
        ];
    
        $redis = new Redis($config);//调用thinkPHP->redis
    
        $redis->set("name1","aaaaa");//添加str类型的数据
        
        die;

    PHP

    $redis = new redis();
    $redis -> connect('127.0.0.1',6379);
    $redis -> flushAll();

    // This first case: hash 值不存在 $redis -> hSet('myhash','favorite_fruit','cherry'); var_dump($redis -> hGet('myhash','favorite_fruit')); // string 'cherry' // This second case: hash 值存在, 替换 if($redis -> exists('myhash')){   $redis -> hSet('myhash','favorite_fruit','pineapple');   var_dump($redis -> hGet('myhash','favorite_fruit')); // string 'pineapple' }

     更多PHP调用Redis方法另外一位博主写了 链接

    经验很浅提供仅提供参考!

  • 相关阅读:
    C#读物
    那些健康手环真的值得买么?
    书籍推荐系列之一 -- 《凤凰项目:一个IT运维的传奇故事》
    测试
    HDU-2024 C语言合法标识符
    HDU-4548 美素数
    求最大流dinic算法模板
    最小费用最大流模板理解
    网络流初步——增广路代码的分析
    最短路的另外两种算法
  • 原文地址:https://www.cnblogs.com/TuWenHao/p/9158851.html
Copyright © 2011-2022 走看看