Skip to content

Add SCAN incremental cursor iteration feature - #347

Merged
fcostaoliveira merged 4 commits into
masterfrom
scan.iterator
Feb 25, 2026
Merged

fcostaoliveira merged 4 commits into
masterfrom
scan.iterator

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Feb 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Add --scan-incremental-iteration and --scan-incremental-max-iterations CLI options for automatic SCAN cursor following
  • When enabled with --command "SCAN 0 [MATCH pattern] [COUNT count] [TYPE type]", the tool extracts the cursor from each SCAN response and sends continuation commands until the cursor returns to 0 (or max iterations reached)
  • Statistics tracked separately for "SCAN 0" (initial) and "SCAN " (continuation) in both stdout and JSON output
  • All command counts (initial + continuation) are counted toward the total request count

Test plan

  • 15 integration tests in tests/test_scan.py covering:
    • All SCAN option combinations: bare, MATCH only, COUNT only, TYPE only, MATCH+COUNT, TYPE+COUNT, MATCH+COUNT+TYPE
    • Error validation: missing --command, non-SCAN command, pipeline > 1
    • Request count correctness with JSON output validation
    • Large keyspace (10K keys preloaded via memtier) with COUNT 100, COUNT 1000, and TYPE filter
    • JSON output confirms separate "Scan 0s" and "Scan s" entries with correct counts
  • make format-check passes on all modified C++ files
  • Run: TEST=test_scan.py OSS_STANDALONE=1 ./tests/run_tests.sh — all 15 tests pass

🤖 Generated with Claude Code


Note

Medium Risk
Touches core request generation/response parsing and arbitrary-command formatting to add SCAN stateful iteration; while guarded by strict option validation and extensive tests, bugs could affect benchmark correctness for arbitrary-command runs.

Overview
Adds an incremental SCAN cursor iteration mode for arbitrary commands via --scan-incremental-iteration plus an optional --scan-incremental-max-iterations cap. When enabled, memtier automatically alternates between an initial SCAN 0 ... and continuation SCAN <cursor> ... requests by extracting the cursor from each response, resetting on errors or when the cursor/max-iteration threshold completes a cycle, and reporting stats separately for initial vs continuation SCANs.

This introduces a new __scan_cursor__ placeholder/arg type for formatting and sending continuation commands, enforces runtime validation (pipeline must be 1, exactly one SCAN command, not cluster mode), updates bash completion and man page, and adds a comprehensive tests/test_scan.py integration suite validating stdout/JSON stats and error cases. Documentation in AGENTS.md is also expanded with stricter CLI-option checklist and test/JSON validation guidance.

Written by Cursor Bugbot for commit 61efe3d. This will update automatically on new commits. Configure here.

Add --scan-incremental-iteration and --scan-incremental-max-iterations
options that enable automatic cursor following for SCAN commands. When
enabled, the tool sends the initial SCAN 0 command, extracts the cursor
from each response, and sends continuation SCAN <cursor> commands until
the cursor returns to 0 or max iterations is reached. Statistics are
tracked separately for "SCAN 0" (initial) and "SCAN <cursor>"
(continuation) commands in both stdout and JSON output.

Includes 15 integration tests covering all SCAN option combinations
(bare, MATCH, COUNT, TYPE, and combinations), error validation, request
counting, and large keyspace (10K keys) scenarios.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@jit-ci

jit-ci Bot commented Feb 25, 2026 •

Copy link
Copy Markdown

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

cursor review

SCAN incremental iteration is a single-endpoint feature (cluster mode
is explicitly disallowed), so all tests should skip when running in
cluster mode.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Comment thread client.cpp Resolved
The iteration counter was incremented for every SCAN response including
the initial SCAN 0, but max-iterations is documented as the maximum
number of *continuation* SCANs. Now only continuation responses
(ar->index == 1) increment the counter, so max-iterations=N yields
exactly N continuations per cycle.

Updated test_scan_incremental_max_iterations to assert exact counts:
with max_iterations=3 and 40 requests, expect 10 initials + 30
continuations.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

cursor review

Comment thread memtier_benchmark.cpp Resolved
Comment thread memtier_benchmark.cpp Resolved
…mand

Other call sites check the return value and handle failure. Without the
check, a parse failure would leave the continuation command with zero
args, causing malformed RESP commands on every continuation attempt.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

cursor review.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Comment thread client.cpp Resolved
@fcostaoliveira
fcostaoliveira merged commit 0d1feab into master Feb 25, 2026
46 checks passed
@fcostaoliveira
fcostaoliveira deleted the scan.iterator branch February 25, 2026 15:27
@fcostaoliveira fcostaoliveira mentioned this pull request Feb 26, 2026
2 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants