feox_server/protocol/command/
mod.rs

1use crate::protocol::resp::RespValue;
2use bytes::Bytes;
3
4mod executor;
5mod parser;
6
7pub use executor::CommandExecutor;
8
9#[derive(Debug, Clone)]
10pub enum Command {
11    // Basic commands
12    Get(Vec<u8>),
13    Set {
14        key: Vec<u8>,
15        value: Bytes,
16        ex: Option<u64>,
17        px: Option<u64>,
18    },
19    Del(Vec<Vec<u8>>),
20    Exists(Vec<Vec<u8>>),
21
22    // Atomic operations
23    Incr(Vec<u8>),
24    IncrBy {
25        key: Vec<u8>,
26        delta: i64,
27    },
28    Decr(Vec<u8>),
29    DecrBy {
30        key: Vec<u8>,
31        delta: i64,
32    },
33
34    // TTL commands
35    Expire {
36        key: Vec<u8>,
37        seconds: u64,
38    },
39    PExpire {
40        key: Vec<u8>,
41        milliseconds: u64,
42    },
43    Ttl(Vec<u8>),
44    PTtl(Vec<u8>),
45    Persist(Vec<u8>),
46
47    // Bulk operations
48    MGet(Vec<Vec<u8>>),
49    MSet(Vec<(Vec<u8>, Bytes)>),
50
51    // Server commands
52    Ping(Option<Bytes>),
53    Echo(Bytes),
54    Info(Option<String>),
55    Config {
56        action: String,
57        args: Vec<Bytes>,
58    },
59    Command,
60    Quit,
61    FlushDb,
62
63    // Key scanning
64    Keys(String), // Pattern
65    Scan {
66        cursor: Vec<u8>,
67        count: usize,
68        pattern: Option<String>,
69    },
70
71    // FeOx-specific
72    JsonPatch {
73        key: Vec<u8>,
74        patch: Bytes,
75    },
76    Cas {
77        key: Vec<u8>,
78        expected: Bytes,
79        new_value: Bytes,
80    },
81}
82
83impl Command {
84    /// Parse command from RESP array
85    #[inline(always)]
86    pub fn from_resp(value: RespValue) -> Result<Self, String> {
87        parser::parse_command(value)
88    }
89}