Command Line Interface (CLI)
Relevant source files
The following files were used as context for generating this wiki page:
The Command Line Interface (CLI) for sidekiq-unique-jobs provides developers and administrators with a set of tools to interact directly with unique job digests stored in Redis. It facilitates administrative tasks such as listing active locks, deleting specific sets of digests based on patterns, and entering an interactive console for debugging and manual manipulation of the uniqueness store.
Built on the Thor framework, the CLI serves as a bridge between the terminal and the underlying SidekiqUniqueJobs::Digests API. It is particularly useful for clearing orphaned locks or auditing the current state of unique constraints without requiring a full Web UI setup.
Sources: lib/sidekiq_unique_jobs/cli.rb, spec/sidekiq_unique_jobs/cli_spec.rb:18-25
Core Commands
The CLI implements three primary functional commands: list, del, and console. These commands target the management of Redis digests, which are the unique identifiers generated to prevent duplicate job processing.
Digest Management (list & del)
The list and del commands utilize a PATTERN argument to filter digests. The default behavior often assumes a count limit (defaulting to 1000) to prevent overwhelming the Redis connection or the terminal output.
- List: Scans Redis for digests matching a glob pattern and displays them along with their expiry times.
- Del: Removes digests matching a pattern. It includes a safety mechanism via the
--dry-runflag, which is enabled by default to prevent accidental deletion.
The diagram shows the logic flow from user input through pattern matching and safety checks to Redis execution.
Sources: lib/sidekiq_unique_jobs/cli.rb:37-65, spec/sidekiq_unique_jobs/cli_spec.rb:48-93
Interactive Console
The console command drops the user into a REPL (Read-Eval-Print Loop). It attempts to load Pry if available, falling back to IRB. This environment is pre-configured with helper methods for easy access to the digest store.
- Helper Methods provided in console:
list(pattern, count): Interactive shortcut for the list command.del(pattern, count, dry_run): Interactive shortcut for the deletion command.
Sources: lib/sidekiq_unique_jobs/cli.rb:15-32, spec/sidekiq_unique_jobs/cli_spec.rb:95-125
Command Summary and Options
The following table details the available commands and their specific configuration options as defined in the Thor implementation.
| Command | Argument | Options | Description |
|---|---|---|---|
list | PATTERN | --count (Integer) | Lists digests and expiry times. Default count: 1000. |
del | PATTERN | --dry-run (Boolean), --count (Integer) | Deletes digests. --dry-run defaults to true. |
console | N/A | N/A | Starts a Pry or IRB session with helper methods. |
help | [COMMAND] | N/A | Displays usage instructions for specific commands. |
Sources: lib/sidekiq_unique_jobs/cli.rb:10-74, spec/sidekiq_unique_jobs/cli_spec.rb:20-46
Internal Integration
The CLI acts as a wrapper for the SidekiqUniqueJobs::Digests class. While the CLI handles terminal input/output and formatting, the actual Redis operations (scanning and deleting) are delegated to the core library.
Dependency Relationship
The diagram illustrates how the CLI relies on internal Web Helpers to access the underlying Digest management logic.
Sources: lib/sidekiq_unique_jobs/cli.rb:86-93, lib/sidekiq_unique_jobs/web/helpers.rb:46-52
Performance Scripts
Beyond the primary SidekiqUniqueJobs::Cli, the repository includes specialized benchmarking scripts that function as CLI tools for performance analysis.
- bin/benchmark: Full suite testing lock acquisition and contention.
- bin/bench: Specifically targets the Orphan Reaper (Ruby vs. Lua implementations).
- bin/compare_performance: A tool for comparing performance metrics across different git branches.
Sources: BENCHMARKING.md:10-38, CLAUDE.md:21-30
Conclusion
The CLI is a critical administrative component of sidekiq-unique-jobs, providing an essential interface for manual lock management and debugging. By leveraging Thor for structured commands and integrating with the core Digests API, it offers a safe and efficient way to maintain the integrity of the uniqueness store in Redis.
Sources: lib/sidekiq_unique_jobs/cli.rb, lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb:39-42