use indexmap::IndexMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::sync::Arc;
use tokio::sync::RwLock;
pub type Db = Arc<RwLock<IndexMap<String, DbValue>>>;
#[derive(Debug, Clone)]
pub struct Command {
pub command_type: CommandType,
pub args: CommandArgs,
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum CommandType {
DOCS,
PONG,
GET,
SET,
DEL,
FLUSHDB,
KEYS,
EXISTS,
EXPIRE,
TTL,
INCR,
DECR,
INCRBY,
LPUSH,
LRANGE,
RPUSH,
LPOP,
RPOP,
HSET,
HGET,
HGETALL,
HDEL,
CLIENT,
SADD,
SMEMBERS,
SREM,
}
#[derive(Debug, Clone)]
pub enum CommandArgs {
NoArgs, SingleKey(String), MultipleKeys(Vec<String>), KeyWithValue {
key: String,
value: String,
}, KeyWithValues {
key: String,
values: Vec<String>,
},
HashFields {
key: String,
fields: IndexMap<String, String>,
}, }
#[derive(Debug, Clone, Default)]
pub struct KeyBase<T> {
pub name: String,
pub data: T,
pub expires_at: Option<i64>,
}
pub type Key = KeyBase<Option<String>>;
pub type KeyList = KeyBase<VecDeque<String>>;
pub type KeySet = KeyBase<HashSet<String>>;
pub type KeyHash = KeyBase<IndexMap<String, String>>;
#[derive(Debug, Clone)]
pub enum DbValue {
StringKey(Key),
ListKey(KeyList),
SetKey(KeySet),
HashKey(KeyHash),
}
#[derive(Debug, Clone, Copy)]
pub enum ListPushType {
LPUSH,
RPUSH,
}
#[derive(Debug, Clone, Copy)]
pub enum PopType {
LPOP,
RPOP,
}