Adapt KEYS command to actually use the pattern to search for
Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
12
src/cmd.rs
12
src/cmd.rs
@@ -16,7 +16,7 @@ pub enum Cmd {
|
||||
SetOpts(String, String, Option<u128>, bool, bool, bool),
|
||||
MGet(Vec<String>),
|
||||
MSet(Vec<(String, String)>),
|
||||
Keys,
|
||||
Keys(String),
|
||||
DbSize,
|
||||
ConfigGet(String),
|
||||
Info(Option<String>),
|
||||
@@ -254,10 +254,10 @@ impl Cmd {
|
||||
}
|
||||
}
|
||||
"keys" => {
|
||||
if cmd.len() != 2 || cmd[1] != "*" {
|
||||
if cmd.len() != 2 {
|
||||
return Err(DBError(format!("unsupported cmd {:?}", cmd)));
|
||||
} else {
|
||||
Cmd::Keys
|
||||
Cmd::Keys(cmd[1].clone())
|
||||
}
|
||||
}
|
||||
"dbsize" => {
|
||||
@@ -1097,7 +1097,7 @@ impl Cmd {
|
||||
Cmd::Del(k) => del_cmd(server, &k).await,
|
||||
Cmd::DelMulti(keys) => del_multi_cmd(server, &keys).await,
|
||||
Cmd::ConfigGet(name) => config_get_cmd(&name, server),
|
||||
Cmd::Keys => keys_cmd(server).await,
|
||||
Cmd::Keys(pattern) => keys_cmd(server, &pattern).await,
|
||||
Cmd::DbSize => dbsize_cmd(server).await,
|
||||
Cmd::Info(section) => info_cmd(server, §ion).await,
|
||||
Cmd::Type(k) => type_cmd(server, &k).await,
|
||||
@@ -1624,8 +1624,8 @@ fn config_get_cmd(name: &String, server: &Server) -> Result<Protocol, DBError> {
|
||||
}
|
||||
}
|
||||
|
||||
async fn keys_cmd(server: &Server) -> Result<Protocol, DBError> {
|
||||
let keys = server.current_storage()?.keys("*")?;
|
||||
async fn keys_cmd(server: &Server, pattern: &str) -> Result<Protocol, DBError> {
|
||||
let keys = server.current_storage()?.keys(pattern)?;
|
||||
Ok(Protocol::Array(
|
||||
keys.into_iter().map(Protocol::BulkString).collect(),
|
||||
))
|
||||
|
Reference in New Issue
Block a user