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

Unable to select which REDIS configuration is used #72

Open
SlyDave opened this issue Jul 10, 2019 · 4 comments
Open

Unable to select which REDIS configuration is used #72

SlyDave opened this issue Jul 10, 2019 · 4 comments

Comments

@SlyDave
Copy link

SlyDave commented Jul 10, 2019

Note that since Laravel 5.7

php artisan cache:clear will not clear the default REDIS connection that lada-cache is configured to use (and doesn't appear to have any way to change)

This means that currently lada-cache is using the 'database' configuration of REDIS in Laravel (called 'default') (for things like sessions) and not the 'cache' configuration (called 'cache') .

The only work around I can see at the moment, is to change the redis cache configuration in Laravel (/app/config/cache.php) to have it's connection set to the 'default' and not 'cache'.

This of course undoes the reason it was changed in the first place, doing php artisan cache:clear will also delete anything placed in the REDIS 'database' configuration (i.e. sessions and the like)

@SlyDave
Copy link
Author

SlyDave commented Jul 10, 2019

I should note this is necessary because of the inability to use the lada-cache:clear command in a Cluster, which is now also the default configuration in Laravel. See #62

@SlyDave
Copy link
Author

SlyDave commented Jul 10, 2019

By default lada-cache should use the 'cache' configuration for REDIS. but adding an option to define that would be better.

Currently it doesn't define a connection, so uses 'default'

'redis' => [

        'client' => 'predis',

        'options' => [
            'cluster' => 'redis',
        ],

        'clusters' => [
            'default' => [
                [
                    'host' => env('REDIS_HOST', '127.0.0.1'),
                    'password' => env('REDIS_PASSWORD', null),
                    'port' => env('REDIS_PORT', 6379),
                    'database' => env('REDIS_DB', 0),
                ],

                'cache' => [
                    'host' => env('REDIS_HOST', '127.0.0.1'),
                    'password' => env('REDIS_PASSWORD', null),
                    'port' => env('REDIS_PORT', 6379),
                    'database' => env('REDIS_CACHE_DB', 1),
                ],
            ],
        ],
    ],

Another workaround is so to set REDIS_DB to the value of REDIS_CACHE_DB, this encounters the same problem with the cache clear command of course.

@spiritix
Copy link
Owner

Thanks for reporting, will have a look at this ASAP. However, please note that Lada Cache is not built on top of the Laravel Cache, but directly on top of Laravel Redis. Therefore, the php artisan cache:clear command does intentionally only clear Lada Cache if the same Redis database is configured as Laravel Cache.

@SlyDave
Copy link
Author

SlyDave commented Jul 10, 2019

Indeed, that is workaround I'm using.

And because Lada Cache is built directly on top of Laravel Redis, it's using the 'default' configuration from /app/config/database.php but because it's a cache and not a semi-persistent storage I feel it should either:

A. be using the 'cache' configuration for Redis from /app/config/database.php (nothing to do with Laravel Cache - just so happens that Laravel Cache's Redis configuration uses the 'cache' configuration as defined in /app/config/cache.php) - this means that a php artisan cache:clear command should in theory work for Lada Cache too... (the work around I'm using)

B. allow the ability to tell Lada Cache which Redis configuration to use and fix the ability to actually flush the Lada Cache

Ideally both. with the 'cache' configuration being the default, but allow changing it via Lada Cache's own configuration, and also fix the ability to flush the Lada Cache

(pretty much just need a way to tell Lada to FLUSHALL on the Redis 'database' that is configured for it, as it can't do KEYS on a cluster)

e.g.:

/app/config/database.php

'redis' => [
        'client' => 'predis',

        'options' => [
            'cluster' => 'redis',
        ],

        'clusters' => [
            'default' => [
                [
                    'host' => env('REDIS_HOST', '127.0.0.1'),
                    'password' => env('REDIS_PASSWORD', null),
                    'port' => env('REDIS_PORT', 6379),
                    'database' => env('REDIS_DB', 0),
                ],

                'cache' => [
                    'host' => env('REDIS_HOST', '127.0.0.1'),
                    'password' => env('REDIS_PASSWORD', null),
                    'port' => env('REDIS_PORT', 6379),
                    'database' => env('REDIS_CACHE_DB', 1),
                ],

                'lada-cache' => [
                    'host' => env('REDIS_HOST', '127.0.0.1'),
                    'password' => env('REDIS_PASSWORD', null),
                    'port' => env('REDIS_PORT', 6379),
                    'database' => env('REDIS_LADA_CACHE_DB', 2),
                ],
            ],
        ],
    ],

/app/config/lada-cache.php
default:
'config' => env('LADA_CACHE_REDIS_CONFIG', default');

configured to match /app/config/database.php as above:
export LADA_CACHE_REDIS_CONFIG = lada-cache;

Hope that helps in any way! And thanks for your hard work :)

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

No branches or pull requests

2 participants