PHP—Redis

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

  致命错误: Class 'app\home\controller\Redis' not found

thinkPHP5.0redis

use think\cache\driver\Redis;

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;

 

PHPapp

 

$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方法另一位博主写了 连接ui

 

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

相关文章
相关标签/搜索