Search code examples
laraveldockerredisdocker-composeredis-cli

redis-cli from docker-compose redis container doesn't catch any keys set up through Laravel


So when I enter the redis container with: docker-compose exec redis bash, I then type: redis-cli to start redis-cli. Then, when I try to get the key (visits) I set up through Laravel app with: GET visits, it shows nil.

This is how I set up the key 'visits':

Route::get('/', function () {
    $visits = Redis::incr('visits');
    return $visits;
});

However, redis works fine in Laravel. Here's my .env:

BROADCAST_DRIVER=log
CACHE_DRIVER=redis
QUEUE_CONNECTION=database
SESSION_DRIVER=redis
SESSION_LIFETIME=120

REDIS_URL=redis
REDIS_HOST=redis #172.17.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
REDIS_CLIENT=phpredis
REDIS_CACHE_DB=0

Solution

  • Okay, I got it. It was persisted like this when I tried all keys:

    127.0.0.1:6379> keys *
    1) "laravel_database_laravel_cache:aEznTaRttAEmGlOd90xQX1jtvbkVEqW7bYGFhzCR"
    2) "laravel_database_visits"
    

    It's because Laravel adds a prefix from database config file.