[minor] Add Redis scan_keys iterator API #34

Merged
brian merged 1 commits from cursor/redis-scan-keys into main 2026-07-08 21:14:25 +02:00
Owner

Summary

Adds a production-safe scan_keys(pattern, *, count=None) -> Iterator[str] API for Redis key discovery.

  • JsonRepositoryInterface gets a default scan_keys() implementation that delegates to list_keys().
  • RedisAdapter overrides it to use Redis SCAN via scan_iter, avoiding blocking KEYS lookups on large datasets.
  • Shared pattern validation is extracted into _validate_pattern() and reused by list_keys() and scan_keys().
  • list_keys() is unchanged in behavior; its docstring now notes that it uses KEYS and may block.
  • README documents when to prefer scan_keys() over list_keys().

Test plan

  • Unit tests for default interface fallback
  • Unit tests for mocked scan_iter, count forwarding, validation, and connection errors
  • Integration tests mirroring list_keys coverage for scan_keys
  • Pre-commit hooks passed (ruff, mypy, pyupgrade, prettier)
## Summary Adds a production-safe `scan_keys(pattern, *, count=None) -> Iterator[str]` API for Redis key discovery. - `JsonRepositoryInterface` gets a default `scan_keys()` implementation that delegates to `list_keys()`. - `RedisAdapter` overrides it to use Redis `SCAN` via `scan_iter`, avoiding blocking `KEYS` lookups on large datasets. - Shared pattern validation is extracted into `_validate_pattern()` and reused by `list_keys()` and `scan_keys()`. - `list_keys()` is unchanged in behavior; its docstring now notes that it uses `KEYS` and may block. - README documents when to prefer `scan_keys()` over `list_keys()`. ## Test plan - [x] Unit tests for default interface fallback - [x] Unit tests for mocked `scan_iter`, `count` forwarding, validation, and connection errors - [x] Integration tests mirroring `list_keys` coverage for `scan_keys` - [x] Pre-commit hooks passed (`ruff`, `mypy`, `pyupgrade`, `prettier`)
brian added 1 commit 2026-07-08 21:07:56 +02:00
Add Redis scan_keys iterator API.
Test Python Package / unit-tests (pull_request) Successful in 14s
Code Quality Pipeline / code-quality (pull_request) Successful in 32s
Test Python Package / coverage-report (pull_request) Successful in 16s
PR Title Check / check-title (pull_request) Successful in 6s
Test Python Package / integration-tests (pull_request) Successful in 1m3s
50444af982
Provide a SCAN-based key iterator for Redis adapters so callers can enumerate large keyspaces without relying on blocking KEYS lookups.

Co-authored-by: Cursor <cursoragent@cursor.com>
Member

Test Coverage Report:

Name                                                            Stmts   Miss    Cover   Missing
-----------------------------------------------------------------------------------------------
python_repositories/__init__.py                                    12      0  100.00%
python_repositories/adapters/__init__.py                           13      0  100.00%
python_repositories/adapters/connection_aware_adapter.py           45      0  100.00%
python_repositories/adapters/minio_adapter.py                     121      0  100.00%
python_repositories/adapters/redis_adapter.py                     111      0  100.00%
python_repositories/config/__init__.py                              4      0  100.00%
python_repositories/config/dotenv_loader.py                         7      0  100.00%
python_repositories/config/minio_config.py                         31      0  100.00%
python_repositories/config/redis_config.py                         14      0  100.00%
python_repositories/examples/__init__.py                            0      0  100.00%
python_repositories/examples/artifact_object_repository.py          9      0  100.00%
python_repositories/examples/user_json_repository.py               10      0  100.00%
python_repositories/interfaces/__init__.py                          5      0  100.00%
python_repositories/interfaces/connection_aware_interface.py        8      0  100.00%
python_repositories/interfaces/context_aware_interface.py           8      0  100.00%
python_repositories/interfaces/json_repository_interface.py        14      0  100.00%
python_repositories/interfaces/object_repository_interface.py      11      0  100.00%
-----------------------------------------------------------------------------------------------
TOTAL                                                             423      0  100.00%

**Test Coverage Report:** ``` Name Stmts Miss Cover Missing ----------------------------------------------------------------------------------------------- python_repositories/__init__.py 12 0 100.00% python_repositories/adapters/__init__.py 13 0 100.00% python_repositories/adapters/connection_aware_adapter.py 45 0 100.00% python_repositories/adapters/minio_adapter.py 121 0 100.00% python_repositories/adapters/redis_adapter.py 111 0 100.00% python_repositories/config/__init__.py 4 0 100.00% python_repositories/config/dotenv_loader.py 7 0 100.00% python_repositories/config/minio_config.py 31 0 100.00% python_repositories/config/redis_config.py 14 0 100.00% python_repositories/examples/__init__.py 0 0 100.00% python_repositories/examples/artifact_object_repository.py 9 0 100.00% python_repositories/examples/user_json_repository.py 10 0 100.00% python_repositories/interfaces/__init__.py 5 0 100.00% python_repositories/interfaces/connection_aware_interface.py 8 0 100.00% python_repositories/interfaces/context_aware_interface.py 8 0 100.00% python_repositories/interfaces/json_repository_interface.py 14 0 100.00% python_repositories/interfaces/object_repository_interface.py 11 0 100.00% ----------------------------------------------------------------------------------------------- TOTAL 423 0 100.00% ```
brian merged commit 5b9573d499 into main 2026-07-08 21:14:25 +02:00
brian deleted branch cursor/redis-scan-keys 2026-07-08 21:14:26 +02:00
Sign in to join this conversation.
No Reviewers
No labels
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: lille-vemmelund/python-repositories#34