数据库
首页 > 数据库> > 麻烦在php网站上加载predis

麻烦在php网站上加载predis

作者:互联网

回答:
我不得不将PREDIS_BASE_PATH的路径更改为predis / lib /.

我想在PHP文件中加载predis,但我遇到了麻烦.我正在按照指南在predis github网站上加载predis(https://github.com/nrk/predis).
这是我用来加载predis的代码:

define("PREDIS_BASE_PATH", "predis/");
echo "The predis base path is: " . PREDIS_BASE_PATH . "\n";
spl_autoload_register(function($class) {
  $file = PREDIS_BASE_PATH . strtr($class, '\\', '/') . '.php';
  echo "The file variable is: " . $file . "\n";
  if (file_exists($file)) {
    require $file;
    return true;
  }
});

$redis = new Predis\Client(array(
  'host'  => 'localhost',
  'port'  => 6379,
));

这是我得到的错误:

Fatal error: Class 'Predis\Client' not found

编辑:应该导入predis目录中的哪个文件?更改文件夹权限后,我能够回显变量$file所持有的内容:“文件变量为:predis / Predis / Client.php”

根据这里列出的目录,https://github.com/nrk/predis,没有client.php文件.

解决方法:

我使用下面的代码连接php页面上的predis,它工作正常..下面是代码

<?php
        require "predis/autoloader.php";
        Predis\Autoloader::register();

        $redis = new Predis\Client(array(
         "scheme" => "tcp",
         "host" => "127.0.0.1",
         "port" => 6379));
?>

标签:php,redis,predis
来源: https://codeday.me/bug/20190713/1444795.html