Skip to content

Implement Redis-Style Transactions (MULTI/EXEC/DISCARD)#13

Merged
varunrmantri23 merged 1 commit intomainfrom
feature/transaction-support
May 21, 2025
Merged

Implement Redis-Style Transactions (MULTI/EXEC/DISCARD)#13
varunrmantri23 merged 1 commit intomainfrom
feature/transaction-support

Conversation

@varunrmantri23
Copy link
Copy Markdown
Owner

Changes

This PR introduces Redis-style transaction support to CrimsonCache, allowing clients to execute a sequence of commands atomically.

New Features

  • Transaction State: Client structures now track whether they are inside a MULTI block.
  • Command Queuing: Commands issued after MULTI are queued rather than immediately executed.
  • Atomic Execution: The EXEC command executes all queued commands in order as a single, uninterrupted operation.
  • Transaction Abort: The DISCARD command clears the queue and exits the transaction state without executing any commands.
  • Error Handling: If an error occurs while queuing commands (e.g., syntax error, out of memory), EXEC will abort the transaction.

New Commands

  • MULTI: Starts a transaction block. Subsequent commands are queued.
  • EXEC: Executes all commands queued since MULTI.
  • DISCARD: Flushes all commands queued since MULTI and exits the transaction state.

Implementation Details

  • Created transaction.h and transaction.c to manage transaction logic.
  • Modified execute_command in commands.c to check for transaction state and queue commands accordingly.
  • Ensured that the original, full command strings (including arguments) are queued and later executed.
  • Implemented proper cleanup of transaction state and queued commands after EXEC or DISCARD.

Testing

  • Manually tested MULTI/EXEC with various command sequences (SET, GET, INCR).
  • Verified that commands are queued and executed in the correct order.
  • Confirmed that DISCARD correctly aborts transactions.
  • Checked that the server returns to normal command processing after EXEC or DISCARD.
  • Ensured that errors during the MULTI phase cause EXEC to abort.

@varunrmantri23 varunrmantri23 merged commit a86d36e into main May 21, 2025
1 check passed
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