Add outline for `jget`

next
Sayan Nandan 4 years ago
parent 6ad417e7ce
commit 3163b6a0e8
No known key found for this signature in database
GPG Key ID: C31EFD7DDA12AEE0

43
Cargo.lock generated

@ -127,6 +127,12 @@ dependencies = [
"libc",
]
[[package]]
name = "itoa"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
[[package]]
name = "kernel32-sys"
version = "0.2.2"
@ -388,6 +394,12 @@ version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8"
[[package]]
name = "ryu"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
[[package]]
name = "scopeguard"
version = "1.1.0"
@ -396,9 +408,34 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "serde"
version = "1.0.114"
version = "1.0.115"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3"
checksum = "e54c9a88f2da7238af84b5101443f0c0d0a3bbdc455e34a5c9497b1903ed55d5"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.115"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "164eacbdb13512ec2745fb09d51fd5b22b0d65ed294a1dcf7285a360c80a675c"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "signal-hook-registry"
@ -454,6 +491,8 @@ dependencies = [
"lazy_static",
"libtdb",
"parking_lot",
"serde",
"serde_json",
"tokio",
]

@ -13,5 +13,7 @@ libtdb = {path ="../libtdb"}
bincode = "1.3.1"
parking_lot = "0.11.0"
lazy_static = "1.4.0"
serde = {version= "1.0.115", features=["derive"]}
serde_json = "1.0.57"
[dev-dependencies]
tokio = { version = "0.2", features = ["test-util"] }

@ -0,0 +1,67 @@
/*
* Created on Mon Aug 31 2020
*
* This file is a part of TerrabaseDB
* Copyright (c) 2020, Sayan Nandan <ohsayan at outlook dot 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/>.
*
*/
//! #`JGET` queries
//! Functions for handling `JGET` queries
use crate::coredb::CoreDB;
use crate::protocol::{responses, ActionGroup, Connection};
use crate::resp::{BytesWrapper, GroupBegin};
use bytes::Bytes;
use libtdb::TResult;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
/// A key/value pair
/// When we write JSON to the stream in `JGET`, it looks something like:
/// ```json
/// {
/// "keythatexists" : "value",
/// "nilkey": null,
/// }
/// ```
#[derive(Serialize, Deserialize)]
pub struct KVPair(HashMap<String, Option<String>>);
impl KVPair {
pub fn with_capacity(size: usize) -> Self {
KVPair(HashMap::with_capacity(size))
}
}
/// Run a `JGET` query
/// This returns a JSON key/value pair of keys and values
/// We need to write something like
/// ```json
/// &1\n
/// $15\n
/// {"key":"value"}\n
/// ```
///
pub async fn jget(handle: &CoreDB, con: &mut Connection, act: ActionGroup) -> TResult<()> {
let howmany = act.howmany();
if howmany != 1 {
return con
.write_response(responses::fresp::R_ACTION_ERR.to_owned())
.await;
}
todo!()
}

@ -28,7 +28,6 @@ use libtdb::TResult;
/// Run an `MGET` query
///
/// **This is currently an experimental query**
pub async fn mget(handle: &CoreDB, con: &mut Connection, act: ActionGroup) -> TResult<()> {
let howmany = act.howmany();
if howmany == 0 {

@ -26,6 +26,7 @@
pub mod del;
pub mod exists;
pub mod get;
pub mod jget;
pub mod mget;
pub mod mset;
pub mod mupdate;

@ -26,8 +26,6 @@ use libtdb::TResult;
use std::collections::hash_map::Entry;
/// Run an `MSET` query
///
/// **This is currently an experimental query**
pub async fn mset(handle: &CoreDB, con: &mut Connection, act: ActionGroup) -> TResult<()> {
let howmany = act.howmany();
if howmany & 1 == 1 {

@ -25,7 +25,7 @@ use crate::resp::GroupBegin;
use libtdb::TResult;
use std::collections::hash_map::Entry;
// Run an `MUPDATE` query
/// Run an `MUPDATE` query
pub async fn mupdate(handle: &CoreDB, con: &mut Connection, act: ActionGroup) -> TResult<()> {
let howmany = act.howmany();
if howmany & 1 == 1 {

Loading…
Cancel
Save