laravelredispredis

What is the difference between this Redis facade and predis?Laravel


What is the difference between this Redis(facade) and predis? I don’t know the difference between them.


Solution

  • predis is a redis client for PHP. If you want to connect to redis using any language, you need a client to do it.

    redis facade is a redis wrapper for laravel framework that you can use predis and also other client like phpredis.

    Facades provide a "static" interface to classes that are available in the application's service container. Laravel ships with many facades which provide access to almost all of Laravel's features. Laravel facades serve as "static proxies" to underlying classes in the service container, providing the benefit of a terse, expressive syntax while maintaining more testability and flexibility than traditional static methods.

    You can connect to redis without facade but you need to define config every call(or need to create own helper). but using facade you just set the config on the laravel config or .env

    example using Predis without facade:

    $client = new Predis\Client([
        'scheme' => 'tcp',
        'host'   => '10.0.0.1',
        'port'   => 6379,
    ]);
    $responses = $client->transaction()->set('foo', 'bar')->execute();
    

    Using facade:

    $responses = Redis::set('foo','bar');