How do I install Predis on XAMPP windows?

两盒软妹~` 提交于 2019-12-11 04:39:02

问题


I installed Predis on XAMPP windows machine using pearhub (pear install pearhub/predis). It installed without any error messages. But when I do the following

<?php
require "Predis.php";
$redis = new Predis/Client();
$redis->set('library', 'predis');
$value = $redis->get('library');
?>

It says Predis class not found. Any ideas how to properly install this on windows?


回答1:


You need to install Redis first, and then Predis will work. Predis is only an interface for Redis.

Because you are on windows, you can find information in the executable here: https://github.com/dmajkic/redis/downloads

Also, I noticed in your code, you have this:

$redis = new Predis/Client();

It should be this:

$redis = new Predis_Client();



回答2:


You need to start redis-server.exe from C:/redis folder, then paste following code in your php file.

<?php 
    require "predis/autoloader.php";
    Predis\Autoloader::register();
    $redis = new Predis\Client();
    $redis = new Predis\Client(array(
      "scheme" => "tcp",
      "host" => "127.0.0.1",
      "port" => 6379));
    if($redis)
    {
         echo "Redis connected succesfully";
    }
    else
    {
         echo "Redis Not connected";
    }
?>


来源:https://stackoverflow.com/questions/5862855/how-do-i-install-predis-on-xampp-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!