PHP: Use Redis as database in Lumen

If you try to open a Redis connection in Lumen and you get a “Fatal error: Class ‘App\Http\Controllers\Redis’ not found in” … or other errors that indicate that Redis is not available this tip maybe will help you:

Redis is not per default included in Lumen so you have to require it in your composer.json file. Add this two lines in the “require”-section of your composer file.

    "predis/predis": "1.1.*@dev",
    "illuminate/redis": "5.1.*"

If it still don’t work check if you have enabled the withFacades option in bootstrap/app.php … you should uncomment the line: $app->withFacades(); … but that won’t help :P

withFacades adds some facades but not all if you want a shortcut for Redis you must add following line below the withFacades-call in app.php:

class_alias('Illuminate\Support\Facades\Redis', 'Redis');

This is my test controller …

namespace App\Http\Controllers;
use Redis;

class TestController extends Controller
    public function timeline()
        $redis = Redis::connection();