Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 8 Sail Redis not assuming the default cache driver #120

Closed
adellinocasas opened this issue Apr 30, 2021 · 4 comments
Closed

Laravel 8 Sail Redis not assuming the default cache driver #120

adellinocasas opened this issue Apr 30, 2021 · 4 comments

Comments

@adellinocasas
Copy link

  • Laravel Version: 8.38.0
  • PHP Version: 8.0.3
  • Database Driver & Version: N/A
  • Environment: Sail (Docker)

Description:

Laravel 8 and the dev environment is Sail - including Redis. The .env file:

CACHE_DRIVER=redis .. REDIS_HOST=redis REDIS_PASSWORD=null REDIS_PORT=6379

Using the Redis facade functions, like

Redis::set( 'bar', 'The hole of the moon' );

using redis-cli is possible to find the value stored in cache

but using

Cache::put('bar2', 'baz', 100);
or even

Cache::store('redis')->put('bar3', 'Awesome', 100);

the values cannot be seen using the redis console.

Please note:
dd(env('CACHE_DRIVER'));
shows "redis" .

Steps To Reproduce:

In terminal

docker exec -it laravel_sail-app_redis_1 redis-cli

(after: sail up)
This machine has no local Redis installation, not even MySQL, only PHP- this is a fresh Ubuntu installation . The app is served by Sail / Docker.

Everything stored with Redis facade - replicants of Redis commands - works well.

@driesvints driesvints transferred this issue from laravel/framework Apr 30, 2021
@driesvints
Copy link
Member

Works fine for me. Please try a support channel:

Thanks.

@adellinocasas
Copy link
Author

Thanks @driesvints good to know: there is no bug!!
It will be worth trying with a fresh app.
I've already post on Laracasts Forum and StackOverflow...

@piterog
Copy link

piterog commented Jul 27, 2021

I have the same issue

@finagin
Copy link
Contributor

finagin commented Jul 28, 2021

@adellinocasas, @piterog

  • First, laravel uses different bases for Redis and Cache facades.
    See config/database.php redis.default and redis.cache
    Снимок экрана 2021-07-28 в 14 04 43
  • Second, Laravel uses a prefix for Redis keys.
    See config/database.php redis.options.prefix
  • Thirdly, the Cache facade uses a prefix for the key. Concatenate database.redis.options.prefix and cache.prefix
    See config/cache.php prefix

Finally

To view cache values change database and find keys:

127.0.0.1:6379[1]> SELECT 1;
127.0.0.1:6379[1]> KEYS *bar*
1) "laravel_database_laravel_cache:bar2"
2) "laravel_database_laravel_cache:bar3"
  • laravel_database_ is database.redis.options.prefix
  • laravel_cache: is cache.prefix
  • bar2 your key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants