-1

my framework is codeigniter.

I want to use redis. I'm using predis.

https://packagist.org/packages/predis/predis

but I got this error:

An uncaught Exception was encountered

Type: Predis\Connection\ConnectionException

Message: No connection could be made because the target machine actively refused it. [tcp://127.0.0.1:6379]

Filename: C:\xampp\htdocs\****\application\vendor\predis\predis\src\Connection\AbstractConnection.php

Line Number: 155

my codes:

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

$client = new \Predis\Client();

$client->set('foo', 'bar');
$value = $client->get('foo');

echo $value;
return ;

my url to test my code is :

http://localhost:8085/...... 
Suneel Kumar
  • 1,650
  • 2
  • 21
  • 31
S.M_Emamian
  • 17,005
  • 37
  • 135
  • 254
  • do you have redis up and running and can successfully connect to it manually: `telnet 127.0.0.1 6379` ? – Alex Blex Jul 19 '17 at 12:06
  • `do you have redis up and running `. I don't know. but I have not any error. – S.M_Emamian Jul 19 '17 at 12:19
  • in my cmd : telnet 127.0.0.1 6379 I got `could not open connection to the host. on port 6379: connect failed.` – S.M_Emamian Jul 19 '17 at 12:20
  • Well, you need to find it out. Predis is just a driver to connect to redis server. You need to run it and ensure no firewall blocks local 6379. When redis server is set up, it responds to the telnet command. – Alex Blex Jul 19 '17 at 12:55
  • its not firewall. I dont know of any firewall that blocks source address localhost (127.0.0.1). – Tuncay Göncüoğlu Jul 19 '17 at 14:13

1 Answers1

2

1. Installing Redis

Firstly you need to understand, that you've to install Redis as a serparate Service. You can't simply install a Redis Client like PRedis without a Redis Server.

Since it was supported by the MSOpentechGroup there are several Windows Forks on Github out there, but unfortunately nobody maintains this forks anymore. You can see a conversation about this topic here.

Anway, you find the download of the latest build here.

2. Installing the client

You can choose PRedis as a standalone PHP Library which is much slower compared to PHPRedis.

The official Codeigniter documentation recommends PHPRedis because its caching driver depends on it. You can find more information here.

Installing PHPRedis on Windows depends on your PHP Version. If you tell me your PHP Version i'm certainly willing to help you to find the correct driver.

3. Using it with Codeigniter

Since CI has an out of the box Driver for that you simple have to study this page here.

Atural
  • 5,389
  • 5
  • 18
  • 35