I've set up a fresh installation of Laravel in Homestead and I've installed PhpRedis as recommended in the Laravel docs https://laravel.com/docs/7.x/redis#phpredis.
I followed this guide for installing PhpRedis https://webstoked.com/install-phpredis-laravel-ubuntu/
In both the Laravel docs, and the guide I've linked for installing PhpRedis, I'm instructed to rename the Redis alias in config/app.php.
If you plan to use PhpRedis extension along with the Redis Facade alias, you should rename it to something else, like RedisManager, to avoid a collision with the Redis class. You can do that in the aliases section of your app.php config file.
- Laravel Docs
To further add to my confusion, the Laravel docs then go on to say that you should remove the alias entirely.
To avoid class naming collisions with the Redis PHP extension itself, you will need to delete or rename the Illuminate\Support\Facades\Redis facade alias from your app configuration file's aliases array. Generally, you should remove this alias entirely and only reference the facade by its fully qualified class name while using the Redis PHP extension.
- Laravel Docs
My main questions are:
There are two different configurations/ways to use redis
in a laravel project.
predis
and it is in your vendor
folder. This one is "Flexible and feature-complete Redis client for PHP and HHVM" located here. It is a package/library written in php
.PhpRedis
, it is an extension written in C
and located here.protected function connector()
{
switch ($this->driver) {
case 'predis':
return new Connectors\PredisConnector;
case 'phpredis':
return new Connectors\PhpRedisConnector;
}
}
What does, "If you plan to use PhpRedis extension along with the Redis Facade alias", mean?
In the framework there is a check. While creating the
PhpRedis client
of Redis, it is checking whether thenew Redis
instance is Facade because PhpRedis is also usingRedis
name is you can see from here. So if you want to use PhpRedis in your laravel framework you better rename your facade because it will cause collision.
When should I rename the alias, remove it, or leave it as-is?
If you are going to use
predis
as client, then you can leave it as-is. If you are going to usePhpRedis
as client, then you need to rename alias.
Depending on if I rename or remove the alias, how will this affect using Redis?
You will use
RedisManager::someMethod()
if you choose PhpRedis. You will useRedis::someMethod()
if you use predis.