0

I am confused about the Predis setup (PHP client for Redis) in this case in a Laravel 5.2 project.
The documentation says you need to autoload it into composer to use it in the entire app without loading it on each page...

HOW? WHERE? WHAT? do I need to add or write to do this? I can't seem to figure it out as I know very little about installation en server configuration..

This is what I mean. This needs to go somewhere I assume

require 'Predis/Autoloader.php';

Predis\Autoloader::register();

Thx

nclsvh
  • 2,628
  • 5
  • 30
  • 52

2 Answers2

1

Another method

  1. Download predis package from https://github.com/nrk/predis
  2. Extract it
  3. Copy the contents of folder into Laravel/vendor/predis/predis. Then folder structure will be enter image description here
  4. In Controller
class WelcomeController extends Controller
{
    public function index()
    {
        $client = new \Predis\Client([
            'scheme' => 'tcp',
            'host' => '127.0.0.1',
            'port' => 6379
        ]);
        $client->set('foo', 'bar');
        return $value = $client->get('foo');
    }
}

If redis is installed in your system, it will return value of 'bar'

Haz Pro
  • 216
  • 2
  • 11
0

Please, read documentation careful:

Autoloading is handled automatically when dependencies are managed through Composer, but it is also possible to leverage its own autoloader in projects or scripts not having any autoload facility:

// Prepend a base path if Predis is not available in your "include_path".
require 'Predis/Autoloader.php';
Predis\Autoloader::register();

By default Laravel uses Composer to install dependencies, so you do not need to do anything special. Just add predis/predis as usual to your deps in composer.json. Read more using of composer here.

Community
  • 1
  • 1
Nick Bondarenko
  • 6,211
  • 4
  • 35
  • 56
  • With `add predis/predis as usual to your deps in composer.json` I assume you mean the required section? Which I already did, with no success... – nclsvh Jan 11 '16 at 17:00
  • Oh will you look at that.. Going downstairs to make a cup of coffee and doing absolutely nothing to my computer the last 20 minutes solved my problem! – nclsvh Jan 11 '16 at 17:07