Implement lskeys

next
Sayan Nandan 3 years ago
parent c764459d2d
commit ea7891fba7

@ -0,0 +1,69 @@
/*
* Created on Thu May 13 2021
*
* This file is a part of Skytable
* Skytable (formerly known as TerrabaseDB or Skybase) is a free and open-source
* NoSQL database written by Sayan Nandan ("the Author") with the
* vision to provide flexibility in data modelling without compromising
* on performance, queryability or scalability.
*
* Copyright (c) 2021, Sayan Nandan <ohsayan@outlook.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
use crate::dbnet::connection::prelude::*;
use crate::protocol::responses;
use crate::resp::BytesWrapper;
use bytes::Bytes;
/// Run an `LSKEYS` query
pub async fn lskeys<T, Strm>(
handle: &crate::coredb::CoreDB,
con: &mut T,
act: Vec<String>,
) -> std::io::Result<()>
where
T: ProtocolConnectionExt<Strm>,
Strm: AsyncReadExt + AsyncWriteExt + Unpin + Send + Sync,
{
crate::err_if_len_is!(act, con, > 1);
let item_count = if let Some(cnt) = act.get(1) {
if let Ok(cnt) = cnt.parse::<usize>() {
cnt
} else {
return con
.write_response(&**responses::groups::WRONGTYPE_ERR)
.await;
}
} else {
10
};
let items: Vec<Bytes>;
{
let rhandle = handle.acquire_read();
let reader = rhandle.get_ref();
items = reader
.keys()
.map(|key| key.get_blob().clone())
.take(item_count)
.collect();
}
con.write_flat_array_length(items.len()).await?;
for item in items {
con.write_response(BytesWrapper(item)).await?;
}
Ok(())
}

@ -35,6 +35,7 @@ pub mod flushdb;
pub mod get; pub mod get;
pub mod jget; pub mod jget;
pub mod keylen; pub mod keylen;
pub mod lskeys;
pub mod mget; pub mod mget;
pub mod mset; pub mod mset;
pub mod mupdate; pub mod mupdate;

@ -70,6 +70,8 @@ mod tags {
pub const TAG_KEYLEN: &'static str = "KEYLEN"; pub const TAG_KEYLEN: &'static str = "KEYLEN";
/// `MKSNAP` action tag /// `MKSNAP` action tag
pub const TAG_MKSNAP: &'static str = "MKSNAP"; pub const TAG_MKSNAP: &'static str = "MKSNAP";
/// `LSKEYS` action tag
pub const TAG_LSKEYS: &str = "LSKEYS";
} }
/// Execute a simple(*) query /// Execute a simple(*) query
@ -103,7 +105,8 @@ where
tags::TAG_FLUSHDB => kvengine::flushdb::flushdb, tags::TAG_FLUSHDB => kvengine::flushdb::flushdb,
tags::TAG_USET => kvengine::uset::uset, tags::TAG_USET => kvengine::uset::uset,
tags::TAG_KEYLEN => kvengine::keylen::keylen, tags::TAG_KEYLEN => kvengine::keylen::keylen,
tags::TAG_MKSNAP => admin::mksnap::mksnap tags::TAG_MKSNAP => admin::mksnap::mksnap,
tags::TAG_LSKEYS => kvengine::lskeys::lskeys
); );
Ok(()) Ok(())
} }

Loading…
Cancel
Save