use crate::protocol::resp::RespValue;
use bytes::Bytes;
pub struct CommandDef {
pub name: &'static str,
pub arity: i64,
pub flags: &'static [&'static str],
pub first_key: i64,
pub last_key: i64,
pub step: i64,
pub acl_categories: &'static [&'static str],
}
impl CommandDef {
pub fn to_resp_array(&self) -> Vec<RespValue> {
vec![
RespValue::BulkString(Some(Bytes::from(self.name))),
RespValue::Integer(self.arity),
RespValue::Array(Some(
self.flags
.iter()
.map(|&f| RespValue::BulkString(Some(Bytes::from(f))))
.collect(),
)),
RespValue::Integer(self.first_key),
RespValue::Integer(self.last_key),
RespValue::Integer(self.step),
RespValue::Array(Some(
self.acl_categories
.iter()
.map(|&cat| RespValue::BulkString(Some(Bytes::from(cat))))
.collect(),
)),
RespValue::Array(Some(vec![])),
RespValue::Array(Some(vec![])),
RespValue::Array(Some(vec![])),
]
}
pub fn find(name: &str) -> Option<&'static CommandDef> {
COMMAND_TABLE
.iter()
.find(|cmd| cmd.name.eq_ignore_ascii_case(name))
}
}
pub static COMMAND_TABLE: &[CommandDef] = &[
CommandDef {
name: "get",
arity: 2,
flags: &["readonly", "fast"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@read", "@string", "@fast"],
},
CommandDef {
name: "set",
arity: -3,
flags: &["write", "denyoom"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@write", "@string", "@slow"],
},
CommandDef {
name: "del",
arity: -2,
flags: &["write"],
first_key: 1,
last_key: -1,
step: 1,
acl_categories: &["@keyspace", "@write", "@slow"],
},
CommandDef {
name: "exists",
arity: -2,
flags: &["readonly", "fast"],
first_key: 1,
last_key: -1,
step: 1,
acl_categories: &["@keyspace", "@read", "@fast"],
},
CommandDef {
name: "incr",
arity: 2,
flags: &["write", "denyoom", "fast"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@write", "@string", "@fast"],
},
CommandDef {
name: "incrby",
arity: 3,
flags: &["write", "denyoom", "fast"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@write", "@string", "@fast"],
},
CommandDef {
name: "decr",
arity: 2,
flags: &["write", "denyoom", "fast"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@write", "@string", "@fast"],
},
CommandDef {
name: "decrby",
arity: 3,
flags: &["write", "denyoom", "fast"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@write", "@string", "@fast"],
},
CommandDef {
name: "expire",
arity: 3,
flags: &["write", "fast"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@keyspace", "@write", "@fast"],
},
CommandDef {
name: "pexpire",
arity: 3,
flags: &["write", "fast"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@keyspace", "@write", "@fast"],
},
CommandDef {
name: "ttl",
arity: 2,
flags: &["readonly", "fast"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@keyspace", "@read", "@fast"],
},
CommandDef {
name: "pttl",
arity: 2,
flags: &["readonly", "fast"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@keyspace", "@read", "@fast"],
},
CommandDef {
name: "persist",
arity: 2,
flags: &["write", "fast"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@keyspace", "@write", "@fast"],
},
CommandDef {
name: "mget",
arity: -2,
flags: &["readonly", "fast"],
first_key: 1,
last_key: -1,
step: 1,
acl_categories: &["@read", "@string", "@fast"],
},
CommandDef {
name: "mset",
arity: -3,
flags: &["write", "denyoom"],
first_key: 1,
last_key: -1,
step: 2,
acl_categories: &["@write", "@string", "@slow"],
},
CommandDef {
name: "ping",
arity: -1,
flags: &["fast"],
first_key: 0,
last_key: 0,
step: 0,
acl_categories: &["@fast", "@connection"],
},
CommandDef {
name: "echo",
arity: 2,
flags: &["fast"],
first_key: 0,
last_key: 0,
step: 0,
acl_categories: &["@fast", "@connection"],
},
CommandDef {
name: "info",
arity: -1,
flags: &["loading", "stale"],
first_key: 0,
last_key: 0,
step: 0,
acl_categories: &["@slow", "@dangerous"],
},
CommandDef {
name: "config",
arity: -2,
flags: &["admin", "noscript", "loading", "stale"],
first_key: 0,
last_key: 0,
step: 0,
acl_categories: &["@admin", "@slow", "@dangerous"],
},
CommandDef {
name: "command",
arity: -1,
flags: &["loading", "stale"],
first_key: 0,
last_key: 0,
step: 0,
acl_categories: &["@slow", "@connection"],
},
CommandDef {
name: "quit",
arity: 1,
flags: &["noscript", "loading", "stale", "fast"],
first_key: 0,
last_key: 0,
step: 0,
acl_categories: &["@fast", "@connection"],
},
CommandDef {
name: "flushdb",
arity: -1,
flags: &["write"],
first_key: 0,
last_key: 0,
step: 0,
acl_categories: &["@keyspace", "@write", "@slow", "@dangerous"],
},
CommandDef {
name: "keys",
arity: 2,
flags: &["readonly"],
first_key: 0,
last_key: 0,
step: 0,
acl_categories: &["@keyspace", "@read", "@slow", "@dangerous"],
},
CommandDef {
name: "scan",
arity: -2,
flags: &["readonly"],
first_key: 0,
last_key: 0,
step: 0,
acl_categories: &["@keyspace", "@read", "@slow"],
},
CommandDef {
name: "lpush",
arity: -3,
flags: &["write", "denyoom", "fast"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@write", "@list", "@fast"],
},
CommandDef {
name: "rpush",
arity: -3,
flags: &["write", "denyoom", "fast"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@write", "@list", "@fast"],
},
CommandDef {
name: "lpop",
arity: -2,
flags: &["write", "fast"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@write", "@list", "@fast"],
},
CommandDef {
name: "rpop",
arity: -2,
flags: &["write", "fast"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@write", "@list", "@fast"],
},
CommandDef {
name: "llen",
arity: 2,
flags: &["readonly", "fast"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@read", "@list", "@fast"],
},
CommandDef {
name: "lrange",
arity: 4,
flags: &["readonly"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@read", "@list", "@slow"],
},
CommandDef {
name: "lindex",
arity: 3,
flags: &["readonly"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@read", "@list", "@slow"],
},
CommandDef {
name: "hset",
arity: -4,
flags: &["write", "denyoom", "fast"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@write", "@hash", "@fast"],
},
CommandDef {
name: "hget",
arity: 3,
flags: &["readonly", "fast"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@read", "@hash", "@fast"],
},
CommandDef {
name: "hmget",
arity: -3,
flags: &["readonly", "fast"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@read", "@hash", "@fast"],
},
CommandDef {
name: "hdel",
arity: -3,
flags: &["write", "fast"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@write", "@hash", "@fast"],
},
CommandDef {
name: "hexists",
arity: 3,
flags: &["readonly", "fast"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@read", "@hash", "@fast"],
},
CommandDef {
name: "hgetall",
arity: 2,
flags: &["readonly"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@read", "@hash", "@slow"],
},
CommandDef {
name: "hlen",
arity: 2,
flags: &["readonly", "fast"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@read", "@hash", "@fast"],
},
CommandDef {
name: "hkeys",
arity: 2,
flags: &["readonly"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@read", "@hash", "@slow"],
},
CommandDef {
name: "hvals",
arity: 2,
flags: &["readonly"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@read", "@hash", "@slow"],
},
CommandDef {
name: "hincrby",
arity: 4,
flags: &["write", "denyoom", "fast"],
first_key: 1,
last_key: 1,
step: 1,
acl_categories: &["@write", "@hash", "@fast"],
},
CommandDef {
name: "auth",
arity: 2,
flags: &["noscript", "loading", "stale", "fast", "no_auth"],
first_key: 0,
last_key: 0,
step: 0,
acl_categories: &["@fast", "@connection"],
},
CommandDef {
name: "subscribe",
arity: -2,
flags: &["pubsub", "noscript", "loading", "stale"],
first_key: 0,
last_key: 0,
step: 0,
acl_categories: &["@pubsub", "@slow"],
},
CommandDef {
name: "unsubscribe",
arity: -1,
flags: &["pubsub", "noscript", "loading", "stale"],
first_key: 0,
last_key: 0,
step: 0,
acl_categories: &["@pubsub", "@slow"],
},
CommandDef {
name: "psubscribe",
arity: -2,
flags: &["pubsub", "noscript", "loading", "stale"],
first_key: 0,
last_key: 0,
step: 0,
acl_categories: &["@pubsub", "@slow"],
},
CommandDef {
name: "punsubscribe",
arity: -1,
flags: &["pubsub", "noscript", "loading", "stale"],
first_key: 0,
last_key: 0,
step: 0,
acl_categories: &["@pubsub", "@slow"],
},
CommandDef {
name: "publish",
arity: 3,
flags: &["pubsub", "loading", "stale", "fast"],
first_key: 0,
last_key: 0,
step: 0,
acl_categories: &["@pubsub", "@fast"],
},
CommandDef {
name: "pubsub",
arity: -2,
flags: &["pubsub", "loading", "stale"],
first_key: 0,
last_key: 0,
step: 0,
acl_categories: &["@pubsub", "@slow"],
},
CommandDef {
name: "client",
arity: -2,
flags: &["admin", "noscript", "loading", "stale"],
first_key: 0,
last_key: 0,
step: 0,
acl_categories: &["@admin", "@slow", "@connection"],
},
CommandDef {
name: "multi",
arity: 1,
flags: &["noscript", "loading", "stale", "fast"],
first_key: 0,
last_key: 0,
step: 0,
acl_categories: &["@fast", "@transaction"],
},
CommandDef {
name: "exec",
arity: 1,
flags: &["noscript", "loading", "stale", "slow"],
first_key: 0,
last_key: 0,
step: 0,
acl_categories: &["@slow", "@transaction"],
},
CommandDef {
name: "discard",
arity: 1,
flags: &["noscript", "loading", "stale", "fast"],
first_key: 0,
last_key: 0,
step: 0,
acl_categories: &["@fast", "@transaction"],
},
CommandDef {
name: "watch",
arity: -2,
flags: &["noscript", "loading", "stale", "fast"],
first_key: 1,
last_key: -1,
step: 1,
acl_categories: &["@fast", "@transaction"],
},
CommandDef {
name: "unwatch",
arity: 1,
flags: &["noscript", "loading", "stale", "fast"],
first_key: 0,
last_key: 0,
step: 0,
acl_categories: &["@fast", "@transaction"],
},
];