php-resque icon indicating copy to clipboard operation
php-resque copied to clipboard

fix(auth): selecting database before auth caused error

Open jasverix opened this issue 1 year ago • 4 comments

jasverix avatar Nov 25 '24 10:11 jasverix

@jasverix Hi! Thank you for the fix!

However, without an explanation what error case this is fixing, I'm left guessing a little bit.

The general assumption here is that if an object is passed to the constructor, you can just call auth() before passing it to the constructor. All internal instantiations are handled in the code that's already there, except the case where we instantiate Redis_Cluster, but that would also make sure it's connected to a database in it's __call() method before calling auth().

pprkut avatar Mar 04 '25 18:03 pprkut

It's a long time since I did this PR, but I am pretty sure it's the $this->driver->select($database); which is directly below the code I added. I cannot run ->select() before ->auth(), because ->select() requires a valid connection.

Alternative approach is that, in Redis.php, we don't pass self::$redisDatabase to the constructur, but run ->select(self::$redisDatabase) after if (!empty(self::$auth)) { block.

jasverix avatar Mar 05 '25 09:03 jasverix

@danhunsaker You merged https://github.com/chrisboulton/php-resque/pull/328 that introduced the $auth. Looking at the code, the way it's implemented i think it actually hurts more than it adds. I'm tempted to just remove it completely again. What do you think? Is there a use case that $auth covers that wouldn't be supported by a DSN string?

pprkut avatar Mar 07 '25 18:03 pprkut

Ultimately, I'd like to rip Credis out and support multiple back ends by making users instantiate their own Redis connection.

For now? I'm ok with a rollback.

danhunsaker avatar Mar 08 '25 06:03 danhunsaker