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方法另外一位博主写了 链接

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

  • 相关阅读:
    【架构】如何设计支持多租户的数据库?
    maven的仓库:本地和远程
    maven私服
    MSA(微服务简介)
    json数据的格式
    shiro的原理理解
    异构的概念?大数据量的异构处理?
    面试之多线程通信
    面试之并发的解决方案
    进程与线程的简单理解
  • 原文地址:https://www.cnblogs.com/TuWenHao/p/9158851.html
Copyright © 2011-2022 走看看