diff --git a/Cargo.lock b/Cargo.lock index 1964957..9a1e42a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,15 +17,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi 0.3.9", -] - [[package]] name = "atty" version = "0.2.14" @@ -70,12 +61,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" -[[package]] -name = "build_const" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4ae4235e6dac0694637c763029ecea1a2ec9e4e06ec2729bd21ba4d9c863eb7" - [[package]] name = "bytes" version = "0.5.6" @@ -102,17 +87,26 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "2.34.0" +version = "3.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ - "ansi_term", "atty", "bitflags 1.3.2", + "clap_lex", + "indexmap 1.9.3", "strsim", + "termcolor", "textwrap", - "unicode-width", - "vec_map", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", ] [[package]] @@ -126,19 +120,31 @@ dependencies = [ [[package]] name = "crc" -version = "1.8.1" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb" +checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe" dependencies = [ - "build_const", + "crc-catalog", ] +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + [[package]] name = "either" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "errno" version = "0.3.8" @@ -257,6 +263,18 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -281,6 +299,26 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", +] + +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown 0.14.3", +] + [[package]] name = "iovec" version = "0.1.4" @@ -496,6 +534,12 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "os_str_bytes" +version = "6.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" + [[package]] name = "pin-project-lite" version = "0.1.12" @@ -604,6 +648,15 @@ dependencies = [ "syn 2.0.55", ] +[[package]] +name = "serde_spanned" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +dependencies = [ + "serde", +] + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -624,9 +677,9 @@ dependencies = [ [[package]] name = "strsim" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" @@ -675,14 +728,20 @@ dependencies = [ ] [[package]] -name = "textwrap" -version = "0.11.0" +name = "termcolor" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" dependencies = [ - "unicode-width", + "winapi-util", ] +[[package]] +name = "textwrap" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" + [[package]] name = "tokio" version = "0.2.25" @@ -734,24 +793,43 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.11" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" dependencies = [ "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "toml_datetime" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e40bb779c5187258fd7aad0eb68cb8706a0a81fa712fbea808ab43c4b8374c4" +dependencies = [ + "indexmap 2.2.6", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] [[package]] -name = "unicode-width" -version = "0.1.11" +name = "unicode-ident" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-xid" @@ -759,12 +837,6 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "void" version = "1.0.2" @@ -811,6 +883,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi 0.3.9", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -883,6 +964,15 @@ version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" +[[package]] +name = "winnow" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8" +dependencies = [ + "memchr", +] + [[package]] name = "ws2_32-sys" version = "0.2.1" diff --git a/memds-cli/Cargo.toml b/memds-cli/Cargo.toml index 90138a4..45d584d 100644 --- a/memds-cli/Cargo.toml +++ b/memds-cli/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" [dependencies] memds-proto = { path = "../memds-proto" } -clap = "2.33" +clap = "3" futures = "0.1" grpcio = { version = "0.4", features = ["openssl"] } protobuf = "~2" diff --git a/memds-cli/src/keys.rs b/memds-cli/src/keys.rs index e839174..17ee25e 100644 --- a/memds-cli/src/keys.rs +++ b/memds-cli/src/keys.rs @@ -192,7 +192,7 @@ pub fn restore(client: &MemdsClient, key: Option<&str>, restore_fn: &str) -> io: pub mod args { use clap::{App, Arg, SubCommand}; - pub fn del() -> App<'static, 'static> { + pub fn del() -> App<'static> { SubCommand::with_name("del") .about("Keys.Del: Delete listed keys") .arg( @@ -203,13 +203,13 @@ pub mod args { ) } - pub fn dump() -> App<'static, 'static> { + pub fn dump() -> App<'static> { SubCommand::with_name("dump") .about("Keys.Dump: Dump listed key") .arg(Arg::with_name("key").help("Key to dump").required(true)) } - pub fn exists() -> App<'static, 'static> { + pub fn exists() -> App<'static> { SubCommand::with_name("exists") .about("Keys.Exists: Count existing listed keys") .arg( @@ -220,7 +220,7 @@ pub mod args { ) } - pub fn rename() -> App<'static, 'static> { + pub fn rename() -> App<'static> { SubCommand::with_name("rename") .about("Keys.Rename: Rename item key") .arg( @@ -235,7 +235,7 @@ pub mod args { ) } - pub fn renamenx() -> App<'static, 'static> { + pub fn renamenx() -> App<'static> { SubCommand::with_name("renamenx") .about("Keys.RenameNX: Rename item key, iff new key does not exist") .arg( @@ -250,7 +250,7 @@ pub mod args { ) } - pub fn restore() -> App<'static, 'static> { + pub fn restore() -> App<'static> { SubCommand::with_name("restore") .about("Keys.Restore: Restore item from dumpfile") .arg( @@ -261,13 +261,13 @@ pub mod args { .arg( Arg::with_name("key") .help("Key of item to query") - .short("k") + .short('k') .long("key") .value_name("string"), ) } - pub fn typ() -> App<'static, 'static> { + pub fn typ() -> App<'static> { SubCommand::with_name("type") .about("Keys.Type: Query item data type") .arg( diff --git a/memds-cli/src/list.rs b/memds-cli/src/list.rs index 89ff32d..85bb226 100644 --- a/memds-cli/src/list.rs +++ b/memds-cli/src/list.rs @@ -161,7 +161,7 @@ pub fn push( pub mod args { use clap::{App, Arg, SubCommand}; - pub fn lindex() -> App<'static, 'static> { + pub fn lindex() -> App<'static> { SubCommand::with_name("lindex") .about("List.Index: Query item at given index") .arg( @@ -176,7 +176,7 @@ pub mod args { ) } - pub fn rpop() -> App<'static, 'static> { + pub fn rpop() -> App<'static> { SubCommand::with_name("rpop") .about("List.RPop: Remove and return list end") .arg( @@ -186,7 +186,7 @@ pub mod args { ) } - pub fn lpop() -> App<'static, 'static> { + pub fn lpop() -> App<'static> { SubCommand::with_name("lpop") .about("List.LPop: Remove and return list head") .arg( @@ -196,7 +196,7 @@ pub mod args { ) } - pub fn llen() -> App<'static, 'static> { + pub fn llen() -> App<'static> { SubCommand::with_name("llen") .about("List.Length: List metadata: length") .arg( @@ -206,7 +206,7 @@ pub mod args { ) } - pub fn lpush() -> App<'static, 'static> { + pub fn lpush() -> App<'static> { SubCommand::with_name("lpush") .about("List.LPush: Store item at list head") .arg( @@ -222,7 +222,7 @@ pub mod args { ) } - pub fn lpushx() -> App<'static, 'static> { + pub fn lpushx() -> App<'static> { SubCommand::with_name("lpushx") .about("List.LPushX: Store item at list head, iff list exists") .arg( @@ -238,7 +238,7 @@ pub mod args { ) } - pub fn rpush() -> App<'static, 'static> { + pub fn rpush() -> App<'static> { SubCommand::with_name("rpush") .about("List.RPush: Store item at list end") .arg( @@ -254,7 +254,7 @@ pub mod args { ) } - pub fn rpushx() -> App<'static, 'static> { + pub fn rpushx() -> App<'static> { SubCommand::with_name("rpushx") .about("List.RPushX: Store item at list end, iff list exists") .arg( diff --git a/memds-cli/src/main.rs b/memds-cli/src/main.rs index ae7ff21..078459f 100644 --- a/memds-cli/src/main.rs +++ b/memds-cli/src/main.rs @@ -76,206 +76,205 @@ fn main() -> io::Result<()> { let client = MemdsClient::new(channel); match cli_matches.subcommand() { - ("append", Some(matches)) => { + Some(("append", matches)) => { let key = matches.value_of("key").unwrap(); let value = matches.value_of("value").unwrap(); string::set(&client, key, value, false, true, false) } - ("bgsave", Some(_matches)) => server::bgsave(&client), - ("dbsize", Some(_matches)) => server::dbsize(&client), - ("decr", Some(matches)) => { + Some(("bgsave", _matches)) => server::bgsave(&client), + Some(("dbsize", _matches)) => server::dbsize(&client), + Some(("decr", matches)) => { let key = matches.value_of("key").unwrap(); string::incrdecr(&client, OpType::STR_DECR, key, 1) } - ("decrby", Some(matches)) => { + Some(("decrby", matches)) => { let key = matches.value_of("key").unwrap(); let n = value_t!(matches, "n", i64).unwrap_or(1); string::incrdecr(&client, OpType::STR_DECRBY, key, n) } - ("del", Some(matches)) => { + Some(("del", matches)) => { let keys: Vec<_> = matches.values_of("key").unwrap().collect(); keys::del_exist(&client, &keys, true) } - ("dump", Some(matches)) => { + Some(("dump", matches)) => { let key = matches.value_of("key").unwrap(); keys::dump(&client, key) } - ("exists", Some(matches)) => { + Some(("exists", matches)) => { let keys: Vec<_> = matches.values_of("key").unwrap().collect(); keys::del_exist(&client, &keys, false) } - ("flushall", Some(_matches)) => server::flush(&client, true), - ("flushdb", Some(_matches)) => server::flush(&client, false), - ("incr", Some(matches)) => { + Some(("flushall", _matches)) => server::flush(&client, true), + Some(("flushdb", _matches)) => server::flush(&client, false), + Some(("incr", matches)) => { let key = matches.value_of("key").unwrap(); string::incrdecr(&client, OpType::STR_INCR, key, 1) } - ("incrby", Some(matches)) => { + Some(("incrby", matches)) => { let key = matches.value_of("key").unwrap(); let n = value_t!(matches, "n", i64).unwrap_or(1); string::incrdecr(&client, OpType::STR_INCRBY, key, n) } - ("get", Some(matches)) => { + Some(("get", matches)) => { let key = matches.value_of("key").unwrap(); string::get(&client, key) } - ("getrange", Some(matches)) => { + Some(("getrange", matches)) => { let key = matches.value_of("key").unwrap(); let start = value_t!(matches, "start", i32).unwrap_or(0); let end = value_t!(matches, "end", i32).unwrap_or(0); string::getrange(&client, key, start, end) } - ("getset", Some(matches)) => { + Some(("getset", matches)) => { let key = matches.value_of("key").unwrap(); let value = matches.value_of("value").unwrap(); string::set(&client, key, value, true, false, false) } - ("lindex", Some(matches)) => { + Some(("lindex", matches)) => { let key = matches.value_of("key").unwrap(); let n = value_t!(matches, "index", i32).unwrap(); list::lindex(&client, key, n) } - ("llen", Some(matches)) => { + Some(("llen", matches)) => { let key = matches.value_of("key").unwrap(); list::llen(&client, key) } - ("lpop", Some(matches)) => { + Some(("lpop", matches)) => { let key = matches.value_of("key").unwrap(); list::pop(&client, key, true) } - ("lpush", Some(matches)) => { + Some(("lpush", matches)) => { let key = matches.value_of("key").unwrap(); let elems: Vec<_> = matches.values_of("element").unwrap().collect(); list::push(&client, key, &elems, true, false) } - ("lpushx", Some(matches)) => { + Some(("lpushx", matches)) => { let key = matches.value_of("key").unwrap(); let elems: Vec<_> = matches.values_of("element").unwrap().collect(); list::push(&client, key, &elems, true, true) } - ("rename", Some(matches)) => { + Some(("rename", matches)) => { let old_key = matches.value_of("old_key").unwrap(); let new_key = matches.value_of("new_key").unwrap(); keys::rename(&client, old_key, new_key, false) } - ("renamenx", Some(matches)) => { + Some(("renamenx", matches)) => { let old_key = matches.value_of("old_key").unwrap(); let new_key = matches.value_of("new_key").unwrap(); keys::rename(&client, old_key, new_key, true) } - ("restore", Some(matches)) => { + Some(("restore", matches)) => { let key = matches.value_of("key"); let restore_fn = matches.value_of("file").unwrap(); keys::restore(&client, key, restore_fn) } - ("rpop", Some(matches)) => { + Some(("rpop", matches)) => { let key = matches.value_of("key").unwrap(); list::pop(&client, key, false) } - ("rpush", Some(matches)) => { + Some(("rpush", matches)) => { let key = matches.value_of("key").unwrap(); let elems: Vec<_> = matches.values_of("element").unwrap().collect(); list::push(&client, key, &elems, false, false) } - ("rpushx", Some(matches)) => { + Some(("rpushx", matches)) => { let key = matches.value_of("key").unwrap(); let elems: Vec<_> = matches.values_of("element").unwrap().collect(); list::push(&client, key, &elems, false, true) } - ("sadd", Some(matches)) => { + Some(("sadd", matches)) => { let key = matches.value_of("key").unwrap(); let elems: Vec<_> = matches.values_of("element").unwrap().collect(); set::add_del(&client, key, &elems, false) } - ("scard", Some(matches)) => { + Some(("scard", matches)) => { let key = matches.value_of("key").unwrap(); set::info(&client, key) } - ("sdiff", Some(matches)) => { + Some(("sdiff", matches)) => { let key1 = matches.value_of("key1").unwrap(); let mut keys: Vec<_> = matches.values_of("keys").unwrap().collect(); keys.insert(0, key1); let empty = String::from(""); set::cmpstore(&client, &keys, &empty, OpType::SET_DIFF) } - ("sdiffstore", Some(matches)) => { + Some(("sdiffstore", matches)) => { let store_key = matches.value_of("destination").unwrap(); let key1 = matches.value_of("key1").unwrap(); let mut keys: Vec<_> = matches.values_of("keys").unwrap().collect(); keys.insert(0, key1); set::cmpstore(&client, &keys, &store_key, OpType::SET_DIFF) } - ("sinter", Some(matches)) => { + Some(("sinter", matches)) => { let key1 = matches.value_of("key1").unwrap(); let mut keys: Vec<_> = matches.values_of("keys").unwrap().collect(); keys.insert(0, key1); let empty = String::from(""); set::cmpstore(&client, &keys, &empty, OpType::SET_INTERSECT) } - ("sinterstore", Some(matches)) => { + Some(("sinterstore", matches)) => { let store_key = matches.value_of("destination").unwrap(); let key1 = matches.value_of("key1").unwrap(); let mut keys: Vec<_> = matches.values_of("keys").unwrap().collect(); keys.insert(0, key1); set::cmpstore(&client, &keys, &store_key, OpType::SET_INTERSECT) } - ("sismember", Some(matches)) => { + Some(("sismember", matches)) => { let key = matches.value_of("key").unwrap(); let elems: Vec<_> = matches.values_of("element").unwrap().collect(); set::is_member(&client, key, &elems) } - ("smembers", Some(matches)) => { + Some(("smembers", matches)) => { let key = matches.value_of("key").unwrap(); set::members(&client, key) } - ("srem", Some(matches)) => { + Some(("srem", matches)) => { let key = matches.value_of("key").unwrap(); let elems: Vec<_> = matches.values_of("element").unwrap().collect(); set::add_del(&client, key, &elems, true) } - ("set", Some(matches)) => { + Some(("set", matches)) => { let key = matches.value_of("key").unwrap(); let value = matches.value_of("value").unwrap(); string::set(&client, key, value, false, false, false) } - ("setnx", Some(matches)) => { + Some(("setnx", matches)) => { let key = matches.value_of("key").unwrap(); let value = matches.value_of("value").unwrap(); string::set(&client, key, value, false, false, true) } - ("smove", Some(matches)) => { + Some(("smove", matches)) => { let src_key = matches.value_of("src_key").unwrap(); let dest_key = matches.value_of("dest_key").unwrap(); let member = matches.value_of("member").unwrap(); set::mov(&client, src_key, dest_key, member) } - ("strlen", Some(matches)) => { + Some(("strlen", matches)) => { let key = matches.value_of("key").unwrap(); string::strlen(&client, key) } - ("sunion", Some(matches)) => { + Some(("sunion", matches)) => { let key1 = matches.value_of("key1").unwrap(); let mut keys: Vec<_> = matches.values_of("keys").unwrap().collect(); keys.insert(0, key1); let empty = String::from(""); set::cmpstore(&client, &keys, &empty, OpType::SET_UNION) } - ("sunionstore", Some(matches)) => { + Some(("sunionstore", matches)) => { let store_key = matches.value_of("destination").unwrap(); let key1 = matches.value_of("key1").unwrap(); let mut keys: Vec<_> = matches.values_of("keys").unwrap().collect(); keys.insert(0, key1); set::cmpstore(&client, &keys, &store_key, OpType::SET_UNION) } - ("time", Some(_matches)) => server::time(&client), - ("type", Some(matches)) => { + Some(("time", _matches)) => server::time(&client), + Some(("type", matches)) => { let key = matches.value_of("key").unwrap(); keys::typ(&client, key) } - ("", None) => { + Some((_, _)) | None => { println!("No subcommand specified. Run with --help for help."); Ok(()) } - _ => unreachable!(), } } diff --git a/memds-cli/src/server.rs b/memds-cli/src/server.rs index a3b72e3..1d6fd91 100644 --- a/memds-cli/src/server.rs +++ b/memds-cli/src/server.rs @@ -121,24 +121,24 @@ pub fn time(client: &MemdsClient) -> io::Result<()> { pub mod args { use clap::{App, SubCommand}; - pub fn bgsave() -> App<'static, 'static> { + pub fn bgsave() -> App<'static> { SubCommand::with_name("bgsave").about("Server.BGSave: Dump entire database to filesystem") } - pub fn dbsize() -> App<'static, 'static> { + pub fn dbsize() -> App<'static> { SubCommand::with_name("dbsize") .about("Server.DBSize: Retrieve item count of current database") } - pub fn flushdb() -> App<'static, 'static> { + pub fn flushdb() -> App<'static> { SubCommand::with_name("flushdb").about("Server.FlushDB: Empty current database") } - pub fn flushall() -> App<'static, 'static> { + pub fn flushall() -> App<'static> { SubCommand::with_name("flushall").about("Server.FlushAll: Empty all databases") } - pub fn time() -> App<'static, 'static> { + pub fn time() -> App<'static> { SubCommand::with_name("time").about("Server.Time: Retrieve server time") } } diff --git a/memds-cli/src/set.rs b/memds-cli/src/set.rs index dd6066a..ef8df94 100644 --- a/memds-cli/src/set.rs +++ b/memds-cli/src/set.rs @@ -244,7 +244,7 @@ pub fn mov(client: &MemdsClient, src_key: &str, dest_key: &str, member: &str) -> pub mod args { use clap::{App, Arg, SubCommand}; - pub fn sadd() -> App<'static, 'static> { + pub fn sadd() -> App<'static> { SubCommand::with_name("sadd") .about("Set.Add: Store items in set") .arg( @@ -260,7 +260,7 @@ pub mod args { ) } - pub fn scard() -> App<'static, 'static> { + pub fn scard() -> App<'static> { SubCommand::with_name("scard") .about("Set.Card: Set metadata") .arg( @@ -270,7 +270,7 @@ pub mod args { ) } - pub fn sdiff() -> App<'static, 'static> { + pub fn sdiff() -> App<'static> { SubCommand::with_name("sdiff") .about("Set.Diff: Diff sets") .arg( @@ -285,7 +285,7 @@ pub mod args { ) } - pub fn sdiffstore() -> App<'static, 'static> { + pub fn sdiffstore() -> App<'static> { SubCommand::with_name("sdiffstore") .about("Set.DiffStore: Diff sets, and store result") .arg( @@ -305,7 +305,7 @@ pub mod args { ) } - pub fn sinter() -> App<'static, 'static> { + pub fn sinter() -> App<'static> { SubCommand::with_name("sinter") .about("Set.Intersect: Intersect sets") .arg( @@ -320,7 +320,7 @@ pub mod args { ) } - pub fn sinterstore() -> App<'static, 'static> { + pub fn sinterstore() -> App<'static> { SubCommand::with_name("sinterstore") .about("Set.IntersectStore: Intersect sets, and store result") .arg( @@ -340,7 +340,7 @@ pub mod args { ) } - pub fn sismember() -> App<'static, 'static> { + pub fn sismember() -> App<'static> { SubCommand::with_name("sismember") .about("Set.IsMember: Test existence of items in a set") .arg( @@ -356,7 +356,7 @@ pub mod args { ) } - pub fn smembers() -> App<'static, 'static> { + pub fn smembers() -> App<'static> { SubCommand::with_name("smembers") .about("Set.Members: Query all Set members") .arg( @@ -366,7 +366,7 @@ pub mod args { ) } - pub fn smove() -> App<'static, 'static> { + pub fn smove() -> App<'static> { SubCommand::with_name("smove") .about("Set.Move: Move member between sets") .arg(Arg::with_name("src_key").help("Source set").required(true)) @@ -382,7 +382,7 @@ pub mod args { ) } - pub fn srem() -> App<'static, 'static> { + pub fn srem() -> App<'static> { SubCommand::with_name("srem") .about("Set.Remove: Remove items from set") .arg( @@ -398,7 +398,7 @@ pub mod args { ) } - pub fn sunion() -> App<'static, 'static> { + pub fn sunion() -> App<'static> { SubCommand::with_name("sunion") .about("Set.Union: Union sets") .arg( @@ -413,7 +413,7 @@ pub mod args { ) } - pub fn sunionstore() -> App<'static, 'static> { + pub fn sunionstore() -> App<'static> { SubCommand::with_name("sunionstore") .about("Set.UnionStore: Union sets, and store result") .arg( diff --git a/memds-cli/src/string.rs b/memds-cli/src/string.rs index 6032094..b5901d0 100644 --- a/memds-cli/src/string.rs +++ b/memds-cli/src/string.rs @@ -194,7 +194,7 @@ pub fn strlen(client: &MemdsClient, key: &str) -> io::Result<()> { pub mod args { use clap::{App, Arg, SubCommand}; - pub fn append() -> App<'static, 'static> { + pub fn append() -> App<'static> { SubCommand::with_name("append") .about("String.Append: Append to item") .arg( @@ -209,7 +209,7 @@ pub mod args { ) } - pub fn decr() -> App<'static, 'static> { + pub fn decr() -> App<'static> { SubCommand::with_name("decr") .about("String.Decr: Decrement numeric item by 1") .arg( @@ -219,7 +219,7 @@ pub mod args { ) } - pub fn decrby() -> App<'static, 'static> { + pub fn decrby() -> App<'static> { SubCommand::with_name("decrby") .about("String.DecrBy: Decrement numeric item") .arg( @@ -234,7 +234,7 @@ pub mod args { ) } - pub fn get() -> App<'static, 'static> { + pub fn get() -> App<'static> { SubCommand::with_name("get") .about("String.Get: Retrieve item") .arg( @@ -244,7 +244,7 @@ pub mod args { ) } - pub fn getrange() -> App<'static, 'static> { + pub fn getrange() -> App<'static> { SubCommand::with_name("getrange") .about("String.GetRange: Retrieve subset of item") .arg( @@ -264,7 +264,7 @@ pub mod args { ) } - pub fn getset() -> App<'static, 'static> { + pub fn getset() -> App<'static> { SubCommand::with_name("getset") .about("String.GetSet: Store item, return old value") .arg( @@ -279,7 +279,7 @@ pub mod args { ) } - pub fn incr() -> App<'static, 'static> { + pub fn incr() -> App<'static> { SubCommand::with_name("incr") .about("String.Incr: Increment numeric item by 1") .arg( @@ -289,7 +289,7 @@ pub mod args { ) } - pub fn incrby() -> App<'static, 'static> { + pub fn incrby() -> App<'static> { SubCommand::with_name("incrby") .about("String.IncrBy: Increment numeric item") .arg( @@ -304,7 +304,7 @@ pub mod args { ) } - pub fn set() -> App<'static, 'static> { + pub fn set() -> App<'static> { SubCommand::with_name("set") .about("String.Set: Store item") .arg( @@ -319,7 +319,7 @@ pub mod args { ) } - pub fn setnx() -> App<'static, 'static> { + pub fn setnx() -> App<'static> { SubCommand::with_name("setnx") .about("String.SetNX: Store item, if key does not exist") .arg( @@ -334,7 +334,7 @@ pub mod args { ) } - pub fn strlen() -> App<'static, 'static> { + pub fn strlen() -> App<'static> { SubCommand::with_name("strlen") .about("String.Strlen: Retrieve item length") .arg( diff --git a/memds-proto/Cargo.toml b/memds-proto/Cargo.toml index 79b0b9e..f609783 100644 --- a/memds-proto/Cargo.toml +++ b/memds-proto/Cargo.toml @@ -13,8 +13,11 @@ protobuf = "~2" tokio = { version = "0.2", features = ["full"] } tokio-util = { version = "0.2", features = ["full"] } bytes = "0.5" -crc = "1.8" +crc = "3" [build-dependencies] protoc-grpcio = "1.0.2" +[lib] +doctest = false + diff --git a/memds-proto/src/codec.rs b/memds-proto/src/codec.rs index fb39c0a..feed8af 100644 --- a/memds-proto/src/codec.rs +++ b/memds-proto/src/codec.rs @@ -14,8 +14,7 @@ // use bytes::{Buf, BufMut, BytesMut}; -use crc::{crc32, Hasher32}; -use protobuf::parse_from_bytes; +use crc::{Crc, CRC_32_ISCSI}; use protobuf::Message; use std::io::Cursor; use tokio_util::codec::{Decoder, Encoder}; @@ -110,11 +109,12 @@ impl MemdsCodec { let crc_buf = self.last_dec_crc.to_be_bytes(); // build CRC for current frame - let mut digest = crc32::Digest::new(crc32::IEEE); - digest.write(&crc_buf); - digest.write(&self.hdr_buf); - digest.write(&data); - self.last_dec_crc = digest.sum32(); + let crcer = Crc::::new(&CRC_32_ISCSI); + let mut digest = crcer.digest(); + digest.update(&crc_buf); + digest.update(&self.hdr_buf); + digest.update(&data); + self.last_dec_crc = digest.finalize(); // verify CRC matches expected if self.last_dec_crc != self.expect_crc { @@ -122,7 +122,7 @@ impl MemdsCodec { } // execute protobuf decode of full frame - match parse_from_bytes::(&data) { + match MemdsMessage::parse_from_bytes(&data) { Err(_e) => Err(MemdsError::ProtobufDecode), Ok(req) => { self.state = DecodeState::Head; @@ -180,11 +180,12 @@ impl Encoder for MemdsCodec { let crc_buf = self.last_enc_crc.to_be_bytes(); // build CRC of current frame - let mut digest = crc32::Digest::new(crc32::IEEE); - digest.write(&crc_buf); - digest.write(&hdr_buf); - digest.write(&msg_bytes); - self.last_enc_crc = digest.sum32(); + let crcer = Crc::::new(&CRC_32_ISCSI); + let mut digest = crcer.digest(); + digest.update(&crc_buf); + digest.update(&hdr_buf); + digest.update(&msg_bytes); + self.last_enc_crc = digest.finalize(); // assemble frame parts in linear buffer dst.reserve(HDR_SIZE + 4 + msg_len as usize); diff --git a/memds-proto/src/lib.rs b/memds-proto/src/lib.rs index d26f3b5..babb851 100644 --- a/memds-proto/src/lib.rs +++ b/memds-proto/src/lib.rs @@ -12,9 +12,9 @@ pub enum Atom { Set(HashSet>), } -pub mod util; pub mod memds_api; pub mod memds_api_grpc; +pub mod util; pub use codec::MemdsCodec; pub use error::MemdsError; diff --git a/memds-server/Cargo.toml b/memds-server/Cargo.toml index abd6676..c3c4966 100644 --- a/memds-server/Cargo.toml +++ b/memds-server/Cargo.toml @@ -12,11 +12,11 @@ futures = "0.1" grpcio = { version = "0.4", features = ["openssl"] } protobuf = "~2" log = "0.4" -clap = "2.33" +clap = "3" tokio = { version = "0.2", features = ["full"] } tokio-util = { version = "0.2", features = ["full"] } bytes = "0.5" nix = "0.17" serde = "1.0" serde_derive = "1.0" -toml = "0.5" +toml = "0.8" diff --git a/memds-server/src/config.rs b/memds-server/src/config.rs index 8a28787..2bc5365 100644 --- a/memds-server/src/config.rs +++ b/memds-server/src/config.rs @@ -42,37 +42,34 @@ pub struct FsConfig { pub fn get() -> Config { // parse command line + let bind_addr_help = format!("socket bind address (default: {})", DEF_BIND_ADDR); + let port_help = format!("socket bind port (default: {})", memds_proto::DEF_PORT); + let config_fn_help = format!("Read configuration file (default: {})", DEF_CONFIG_FN); let cli_matches = clap::App::new(APPNAME) .version(VERSION) .about("Memory Database Service") .arg( clap::Arg::with_name("bind-addr") - .short("a") + .short('a') .long("bind-addr") .value_name("IP-ADDRESS") - .help(&format!("socket bind address (default: {})", DEF_BIND_ADDR)) + .help(&*bind_addr_help) .takes_value(true), ) .arg( clap::Arg::with_name("bind-port") - .short("p") + .short('p') .long("bind-port") .value_name("PORT") - .help(&format!( - "socket bind port (default: {})", - memds_proto::DEF_PORT - )) + .help(&*port_help) .takes_value(true), ) .arg( clap::Arg::with_name("config") - .short("c") + .short('c') .long("config") .value_name("TOML-FILE") - .help(&format!( - "Read configuration file (default: {})", - DEF_CONFIG_FN - )) + .help(&*config_fn_help) .takes_value(true), ) .arg( @@ -113,13 +110,13 @@ pub fn get() -> Config { f_cfg.fs = Some(TomlFsConfig { import: None }); } - let mut f_fs_cfg = f_cfg.fs.as_mut().unwrap(); + let f_fs_cfg = f_cfg.fs.as_mut().unwrap(); if cli_matches.is_present("import") { f_fs_cfg.import = Some(cli_matches.value_of("import").unwrap().to_string()); } - let mut f_net_cfg = f_cfg.network.as_mut().unwrap(); + let f_net_cfg = f_cfg.network.as_mut().unwrap(); // CLI arg overrides config file value; else if missing, provide def. if cli_matches.is_present("bind-addr") {