MisterCat
MisterCat

Reputation: 1641

Laravel redis works, but list still empty

i'm currently using redis in laravel everything works fine, unless i can't check my redis's keys like normally

I went to "redis-cli " and type "keys *" it shows -empty list or set-

But my cache worked. I tested it with laravel debugbar.

i'm not sure, where and how to check all my redis's keys via command line,

here is my config/database for redis

'redis' => [

    'client' => env('REDIS_CLIENT', 'predis'),

    'options' => [
        'cluster' => env('REDIS_CLUSTER', 'redis'),
        'prefix' => env('REDIS_PREFIX', 'helper_'),
    ],

thanks

...

Upvotes: 1

Views: 2550

Answers (2)

Kevin Osborn
Kevin Osborn

Reputation: 41

Assuming you are using default configuration, and have CACHE_DRIVER set as redis, then you are in fact writing to Redis. However you are by default writing to the database with index 1

You can see these entries by calling SELECT 1 followed by KEYS * in redis-cli.

You can specify which database to write to in a connection in config/database.php. You can then select which connection to use by default in config/cache.php.

This is why changing to default works in Nazmus Shakib's answer, because the default connection outlined in config/database.php uses database 0 rather than database 1. Alternatively, you could change REDIS_CACHE_DB to 0 in .env. Or, you could just use database 1.

Upvotes: 4

Nazmus Shakib
Nazmus Shakib

Reputation: 832

Need to modify the file: config/cache.php

Change the stores > redis > connection

'redis' => [
        'driver' => 'redis',
        'connection' => 'cache',
    ],

to

'redis' => [
        'driver' => 'redis',
        'connection' => 'default',
    ],

And make sure your .env file has CACHE_DRIVER=redis

Upvotes: 3

Related Questions