GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: handle key prefixes and glob metacharacters when clearing Redis queues by gr8man · Pull Request #105 · codeigniter4/queue

Conversation

@gr8man

@gr8man gr8man commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Description

RedisHandler::clear() and PredisHandler::clear() were unreliable in two ways.

  1. Key prefixes prevented deletion. Both KEYS and SCAN-less key listing return fully qualified key names, including the client key prefix. DEL is then processed by the client, which prepends the prefix again to every key it receives (phpredis Redis::OPT_PREFIX, Predis prefix option). With a prefix configured, the resulting names did not exist, no key was deleted, and clear() returned false — while queue:clear still printed a success message and exited with EXIT_SUCCESS.
  2. Queue names were interpolated into a KEYS glob. A queue name such as * or products* expanded the pattern far beyond the requested queue and could delete unrelated queues. Queue names are validated on push(), so clear() should validate them as well.

Changes

  • src/Handlers/RedisHandler.php
    • Validate the queue name with the existing validateQueue() before building the queues:{queue}:* pattern (invalid names are rejected, the error is logged, and false is returned).
    • Read Redis::OPT_PREFIX, strip it from every key returned by KEYS before passing the keys to DEL.
    • Check the return values of KEYS and DEL; log an error and return false when they fail.
    • Catch Throwable from the client, log it and return false instead of failing the surrounding command.
    • Emit queueCleared only when the clear actually succeeded.
  • src/Handlers/PredisHandler.php
    • Same behaviour, using KeyPrefixProcessor from the Predis options to obtain the prefix.
  • src/Commands/QueueClear.php
    • Return EXIT_ERROR and print an error message when clear() reports a failure, instead of always reporting success.

Testing

  • tests/RedisHandlerTest.php and tests/PredisHandlerTest.php
    • testClearWithPrefix() — keys are deleted exactly once and the prefix is not applied twice.
    • testClearWithInvalidQueueNameReturnsFalse() — glob metacharacters in the queue name are rejected.
  • tests/Commands/QueueClearTest.php
    • testRunFailedWhenClearReturnsFalse() — the command exits with EXIT_ERROR and reports the failure.

Verified locally on PHP 8.5 with PHPUnit 11.5:

phpunit ....... OK (235 tests, 669 assertions, 27 skipped)
phpstan ....... [OK] No errors
psalm ......... No errors found
php-cs-fixer .. 0 of 75 files would be fixed

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
gr8man added 2 commits November 10, 2026 21:38
@gr8man
fix: handle key prefixes and validate queue names when clearing Redis…
68097ec
… queues
@gr8man
test: add tests for clear with prefix, invalid queue names, and faile…
f33999b
…d clear command

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@gr8man
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.