|
|
@ -25,7 +25,6 @@
|
|
|
|
use crate::coredb::CoreDB;
|
|
|
|
use crate::coredb::CoreDB;
|
|
|
|
use crate::protocol::{responses, ActionGroup, Connection};
|
|
|
|
use crate::protocol::{responses, ActionGroup, Connection};
|
|
|
|
use crate::resp::GroupBegin;
|
|
|
|
use crate::resp::GroupBegin;
|
|
|
|
use libtdb::terrapipe::RespCodes;
|
|
|
|
|
|
|
|
use libtdb::TResult;
|
|
|
|
use libtdb::TResult;
|
|
|
|
|
|
|
|
|
|
|
|
/// Run an `EXISTS` query
|
|
|
|
/// Run an `EXISTS` query
|
|
|
@ -34,22 +33,18 @@ pub async fn exists(handle: &CoreDB, con: &mut Connection, act: ActionGroup) ->
|
|
|
|
if howmany == 0 {
|
|
|
|
if howmany == 0 {
|
|
|
|
return con.write_response(responses::ACTION_ERR.to_owned()).await;
|
|
|
|
return con.write_response(responses::ACTION_ERR.to_owned()).await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Write #<m>\n#<n>\n&<howmany>\n to the stream
|
|
|
|
// Write #<m>\n#<n>\n&1\n to the stream
|
|
|
|
con.write_response(GroupBegin(howmany)).await?;
|
|
|
|
con.write_response(GroupBegin(1)).await?;
|
|
|
|
let mut keys = act.into_iter();
|
|
|
|
let mut how_many_of_them_exist = 0usize;
|
|
|
|
// HACK(@ohsayan): Figure out what to do here
|
|
|
|
{
|
|
|
|
while let Some(key) = keys.next() {
|
|
|
|
|
|
|
|
let has_key = {
|
|
|
|
|
|
|
|
let rhandle = handle.acquire_read();
|
|
|
|
let rhandle = handle.acquire_read();
|
|
|
|
rhandle.contains_key(&key)
|
|
|
|
act.into_iter().for_each(|key| {
|
|
|
|
};
|
|
|
|
if rhandle.contains_key(&key) {
|
|
|
|
if has_key {
|
|
|
|
how_many_of_them_exist += 1;
|
|
|
|
con.write_response(RespCodes::Okay).await?
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
con.write_response(RespCodes::NotFound).await?
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
drop(rhandle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
drop(handle);
|
|
|
|
con.write_response(how_many_of_them_exist).await?;
|
|
|
|
// We're done here
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|