When you say 'Lumen is giving me a hard time' - do you have the same code working ok in the main Laravel app? If so you might want to post to their github issues page :-) I've never tried to change the config dynamically in lumen so can't be much help apart from that I'm afraid :-/
Can't manage redis connections dynamically
I'm working on a system where speed is the number one priority (milliseconds count). Since DB size is obviously inversely proportional to speed a while ago we decided to put a few bigger clients on their own databases, both mysql and redis and we decide which db to use, based on the url they're accessing through.
Now I'm building a microservice that needs to be able to access any client/db, but Lumen is giving me a hard time changing the redis database on runtime. Here's a sample that shows the problem:
var_dump(config('database.redis.default.database')); //Output -> 0
app('cache')->put('lumen_rd_0','val',1); // Gets set in db0
config(['database.redis.default.database' => 3]);
var_dump(config('database.redis.default.database')); //Output -> 3
app('cache')->put('lumen_rd_3','val',1); // Should get set in db 3, but also goes in db 0
Any thoughts?
Hi @elena have you tried the select( database# ) command? e.g.
Redis::command('select', 2);
The (laravel) RedisServiceProvider creates a singleton passing the settings ($app['config']['database.redis']).
As it's in a closure it won't actually be created till it's first use. Hence the behavior you are seeing. Once the PRedis client is created, I doubt that changing the config will make any difference.
Please or to participate in this conversation.