abixalmon@me.com's avatar

Lumen Framework: Redis error

.env file

CACHE_DRIVER=redis
SESSION_DRIVER=redis
QUEUE_DRIVER=redis

I have enabled $app->withFacades();

When i load Cache::get('test')

I am getting this error

ReflectionException in Container.php line 776:
Class redis does not exist
--------
in Container.php line 776
at ReflectionClass->__construct('redis') in Container.php line 776
at Container->build('redis', array()) in Container.php line 656
at Container->make('redis', array()) in Application.php line 358
at Application->make('redis') in Container.php line 1231
at Container->offsetGet('redis') in CacheManager.php line 202
at CacheManager->createRedisDriver(array('driver' => 'redis', 'connection' => 'default')) in CacheManager.php line 98
at CacheManager->resolve('redis') in CacheManager.php line 74
at CacheManager->get('redis') in CacheManager.php line 52
at CacheManager->store() in CacheManager.php line 312
at CacheManager->__call('get', array('test')) in Facade.php line 210
at CacheManager->get('test') in Facade.php line 210
at Facade::__callStatic('get', array('test')) in Controller.php line 12
at Cache::get('test') in Controller.php line 12
0 likes
18 replies
bashy's avatar

Class redis does not exist

Does it?

abixalmon@me.com's avatar

nope!

but i have installed predis package as required in documentation! "require": { "laravel/lumen-framework": "5.0.*", "vlucas/phpdotenv": "1.*", "predis/predis": "1.*" },

1 like
bashy's avatar

Also, for which of the three does it fail on?

bashy's avatar

Ah yeah forgot you did Cache::get('test'). Not sure about the error, you'll have to check Redis downloaded to vendor and you do any dump auto load stuff.

cmbrownfield's avatar

I'm having a similar error with redis sessions (which uses the cache). Argument 1 of Illuminate\Cache\RedisStore is supposed to be of type Illuminate\Redis\Database, but it is of type Redis instead. I think something is supposed to be implementing an interface.

iusik's avatar

Have the same problem:

Argument 1 passed to Illuminate\Cache\RedisStore::__construct() must be an instance of Illuminate\Redis\Database, instance of Redis given, called in /home/vagrant/code/inform-service-stat/vendor/illuminate/cache/CacheManager.php on line 209 and defined

Don't understand how to fix it :(

1 like
cmbrownfield's avatar

I'm trying to run lumen on hhvm. I wonder if hhvm is more strict with interfaces. Seems like RedisStore is being instantiated with a type that doesn't explicitly implement the correct interface. How about you, iusik? Are you running on hhvm?

jonnybarnes's avatar

I’m having this issue. Manually calling the predis client in `routes.p as a test works. For example

$app->get('test', function () use ($app) {
    $client = new \Predis\Client();
    $client->put('foo', 'bar');
    return 'foo stored as ' . $client->get('foo');
});

So this is definitely an issue with Lumen.

1 like
chriswonders's avatar

It looks like the illuminate/redis package is just not included by default. You can require illuminate/redis 5.0.* and it should work.

1 like
zot24's avatar

As you can see on the Laravel/Lumen Documentation you'll need to add redis dependencies to your composer.json file, as below:

...
  "require": {
        "predis/predis": "~1.0",
        "illuminate/redis": "5.0.*",
...
compul's avatar

Am I blind or is this just not in the docs anymore?

ahmedash95's avatar

@abixalmon did you check if your phpinfo() has redis extension ? i solve it by add extension=redis.so to my php.ini file and it works fine now

mwehbe's avatar

if you are not using $app->withEloquent() in app.php you have to use at least $app->configure('database');

example:

$app->withFacades(); $app->configure('database'); // $app->withEloquent()

ymslavov's avatar

On top of everything else mentioned in this post, you also need to register the RedisServiceProvider in boostrap/app.php:

$app->register(\Illuminate\Redis\RedisServiceProvider::class);
7 likes

Please or to participate in this conversation.