Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
RedisHandler::clear()andPredisHandler::clear()were unreliable in two ways.KEYSandSCAN-less key listing return fully qualified key names, including the client key prefix.DELis then processed by the client, which prepends the prefix again to every key it receives (phpredisRedis::OPT_PREFIX, Predisprefixoption). With a prefix configured, the resulting names did not exist, no key was deleted, andclear()returnedfalse— whilequeue:clearstill printed a success message and exited withEXIT_SUCCESS.KEYSglob. A queue name such as*orproducts*expanded the pattern far beyond the requested queue and could delete unrelated queues. Queue names are validated onpush(), soclear()should validate them as well.Changes
src/Handlers/RedisHandler.phpvalidateQueue()before building thequeues:{queue}:*pattern (invalid names are rejected, the error is logged, andfalseis returned).Redis::OPT_PREFIX, strip it from every key returned byKEYSbefore passing the keys toDEL.KEYSandDEL; log an error and returnfalsewhen they fail.Throwablefrom the client, log it and returnfalseinstead of failing the surrounding command.queueClearedonly when the clear actually succeeded.src/Handlers/PredisHandler.phpKeyPrefixProcessorfrom the Predis options to obtain the prefix.src/Commands/QueueClear.phpEXIT_ERRORand print an error message whenclear()reports a failure, instead of always reporting success.Testing
tests/RedisHandlerTest.phpandtests/PredisHandlerTest.phptestClearWithPrefix()— keys are deleted exactly once and the prefix is not applied twice.testClearWithInvalidQueueNameReturnsFalse()— glob metacharacters in the queue name are rejected.tests/Commands/QueueClearTest.phptestRunFailedWhenClearReturnsFalse()— the command exits withEXIT_ERRORand reports the failure.Verified locally on PHP 8.5 with PHPUnit 11.5: