问题
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