Skip to content

feat: LINDEX, LSET, LTRIM, LINSERT, LREM, LPOS list commands#257

Merged
kacy merged 4 commits intomainfrom
feat/list-commands
Feb 24, 2026
Merged

feat: LINDEX, LSET, LTRIM, LINSERT, LREM, LPOS list commands#257
kacy merged 4 commits intomainfrom
feat/list-commands

Conversation

@kacy
Copy link
Owner

@kacy kacy commented Feb 24, 2026

summary

fills critical list command gaps with 6 new commands: LINDEX, LSET, LTRIM, LINSERT, LREM, and LPOS. this completes the list data type coverage alongside the existing LPUSH/RPUSH/LPOP/RPOP/LRANGE/LLEN/BLPOP/BRPOP.

commands added:

  • LINDEX — get an element by index (O(n) random access on VecDeque)
  • LSET — set the value at a specific index
  • LTRIM — trim a list to the specified range (auto-deletes empty keys)
  • LINSERT — insert before or after a pivot element (with memory enforcement)
  • LREM — remove elements matching a value (forward, reverse, or all)
  • LPOS — find positions of matching elements (with RANK/COUNT/MAXLEN options)

full vertical slice per command:

  • keyspace methods with comprehensive tests (30 new tests, 59 total list tests)
  • RESP3 command parsing with validation
  • shard request/response dispatch
  • AOF persistence (4 new record types: LSET, LTRIM, LINSERT, LREM)
  • AOF recovery replay
  • replication stream support
  • sharded + concurrent connection handler routing
  • cluster slot checking
  • CLI autocomplete and help entries

what was tested

  • 59 list-specific unit tests covering all methods, edge cases, and error paths
  • 406 protocol parser tests (including new command parsers)
  • 32 AOF round-trip tests (serialization, deserialization, recovery)
  • 14 recovery tests
  • 114 CLI tests (including alphabetical ordering fix)
  • full cargo build clean across all crates

design considerations

  • LPOS COUNT semantics: when COUNT is not specified, the shard fetches at most 1 match and the connection handler returns a single integer (or null). when COUNT is specified (including COUNT 0 for all matches), it returns an array. this matches Redis behavior.
  • memory tracking: LSET uses delta-based tracking (old_len vs new_len). LTRIM recomputes full value_size since the change is bulk. LINSERT uses enforce_memory_limit with a defensive re-check after possible eviction of the target key itself.
  • borrow safety: scoped blocks release entry borrows before calling self.memory.* methods, avoiding Rust borrow checker conflicts between self.entries and self.memory.
  • AOF records: read-only commands (LINDEX, LPOS) don't generate AOF records. write commands only persist on success (LINSERT when n>0, LREM when n>0).

kacy added 4 commits February 23, 2026 22:19
adds the 6 missing list commands to the keyspace layer with full
memory tracking and 30 new tests covering edge cases.

- LINDEX: element by index with negative index support
- LSET: replace element at index with memory delta tracking
- LTRIM: keep only elements in range, auto-delete if empty
- LINSERT: insert before/after a pivot element
- LREM: remove N matches from head, tail, or all
- LPOS: find element positions with rank, count, maxlen options
adds 6 command variants with their parsers. LPOS supports the full
RANK/COUNT/MAXLEN option syntax with validation (rank != 0, count >= 0,
maxlen >= 0). LINSERT parses BEFORE|AFTER direction.
- shard dispatch: 6 new ShardRequest variants + IntegerArray response
- AOF persistence: 4 new record types (LSET, LTRIM, LINSERT, LREM)
  with binary serialization, deserialization, and recovery replay
- connection handler: sharded + concurrent dispatch for all 6 commands
  with LPOS COUNT-aware response formatting (array vs single value)
- replication: AofRecord → ShardRequest conversion for new variants
- cluster: slot checking for all 6 single-key commands
also fix alphabetical ordering in generic and transactions groups.
@kacy kacy merged commit f00e15a into main Feb 24, 2026
6 of 7 checks passed
@kacy kacy deleted the feat/list-commands branch February 24, 2026 03:39
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.

1 participant