Skip to content

Latest commit

 

History

History
69 lines (57 loc) · 2.37 KB

File metadata and controls

69 lines (57 loc) · 2.37 KB

Changes Overview

1. src/resp/value.rs

This is where the fundamental change begins:

  • Changed to_command() method's return type from Option<(String, Vec<String>)> to Option<(String, Vec<Value>)>
  • Instead of converting all arguments to strings, we're now preserving their original data types
  • Added better type handling for numeric values, allowing integers to remain as Value::Integer instead of converting them to strings
  • This change enables type-preserving command processing throughout the system

2. src/commands/executor.rs

This file was modified to accommodate the type preservation:

  • Changed the execute() method signature to accept Vec<Value> instead of Vec<String>
  • Added a conversion step that maps different Value types to strings for backward compatibility:
    let string_args: Vec<String> = args
      .iter()
      .map(|v| match v {
        Value::SimpleString(s) => s.clone(),
        Value::BulkString(s) => s.clone(),
        Value::Integer(i) => i.to_string(),
        Value::Boolean(b) => b.to_string(),
        _ => "".to_string(),
      })
      .collect();
  • Updated command calls to pass both the string arguments (for backward compatibility) and the original Value objects
  • Now passes the original Value objects to the SET command, allowing it to preserve data types

3. src/commands/general/set.rs

This file implements the SET command and was updated to handle typed values:

  • Added a new parameter orig_args: Vec<Value> to receive the original typed values
  • Changed how values are extracted and stored to preserve their original type:
    let value = if orig_args.len() > 1 {
      orig_args[1].clone()
    } else {
      Value::SimpleString(args[1].clone())
    };
  • Updated the argument parsing logic to use indexes rather than removing elements
  • Improved value display in debug logs to show appropriate string representation based on type
  • Now the SET command can store integers, booleans, and strings with their original types preserved

4. src/commands/acl/whoami.rs

Only had a minor change in the order of imports (rearranging the anyhow imports).

The overall improvement is significant: your database system now preserves data types throughout the command execution pipeline, instead of converting everything to strings. This makes your system more robust and provides better data integrity when retrieving values later.