0
votes

PHP 7.3
Laravel 5.8

Until now I was using Predis for my cache in the Laravel project. Now I want to switch to PhpRedis. I've read it's really simple (just config changes), but I have a lot of problems. I don't know what to begin with, so I'll write all what I know.

  1. My hosting provider claims that PhpRedis is enabled.

  2. The code below executed in a controller (Predis is set) works fine - I receive the set value.

    $redis = new \Redis();

    $redis->connect( 'socket path', 0 );

    $redis->set('test', 'testValue');

    print_r( $redis->get('test') );

  3. However, the same code in the raw PHP file executed via SSH returns "Uncaught Error: Class 'Redis' not found in..."

Let's go to changes in config/database.php. Here is my configuration:

    'redis' => [
        'client' => env('REDIS_CLIENT', 'predis'/*'phpredis'*/),
        'cluster' => true,

        'options' => [
            'cluster' => env('REDIS_CLUSTER', 'predis'/*'redis'*/),
            'prefix' => Str::slug(env('APP_NAME'), '_').'_',
            'parameters' => ['password' => env('REDIS_PASSWORD', null)],
        ],

        'default' => [
            'scheme' => 'unix',
            'path' => env('REDIS_HOST'),
            'host' => env('REDIS_HOST'),
            'password' => env('REDIS_PASSWORD'),
            'port' => env('REDIS_PORT'),
            'database' => env('REDIS_CACHE_DB', 0)
        ],

        (...) // other
        ],
  1. When I change values to these in comments, my website shows just a blank page - any errors in the mailbox.
  2. Furthermore, when I run for example "php73 artisan config:clear" in the SSH, console returns
    "Please remove or rename the Redis facade alias in your "app" configuration file in order to avoid collision with the PHP Redis extension." in the Illuminate/Redis/Connectors/PhpRedisConnector.php.
    When I change the alias in config/app.php from "Redis" to "RedisManager" and try again it returns
    Uncaught Error: Class 'Redis' not found in /path/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php:70.

What's going on? How to set Laravel's configuration to use PhpRedis? Maybe it's my hosting provider issue? Thanks in advance for every advice.
If I missed some important code, give me a sign - I will add it.

1

1 Answers

0
votes

The PHPRedis libraries are not installed by default in a shared hosting environment, and are generally not part of a PHP installation by default. You would have to ask your host to install these libraries within their shared hosting platform.