From 7037e958c8470bd4b087b4e718177d5798c49d11 Mon Sep 17 00:00:00 2001 From: Guy Korland Date: Mon, 18 Feb 2019 23:43:20 +0200 Subject: [PATCH] rename to RedisJSON --- Cargo.lock | 2 +- Cargo.toml | 2 +- LICENSE | 2 +- README.md | 2 +- src/lib.rs | 29 +++++++++++++++-------------- src/{redisdoc.rs => redisjson.rs} | 6 +++--- 6 files changed, 22 insertions(+), 21 deletions(-) rename src/{redisdoc.rs => redisjson.rs} (95%) diff --git a/Cargo.lock b/Cargo.lock index 95f496d..3ca4c71 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -270,7 +270,7 @@ dependencies = [ ] [[package]] -name = "redisdoc" +name = "redisjson" version = "0.1.0" dependencies = [ "libc 0.2.47 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 7b749f9..5fe5c2b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "redisdoc" +name = "redisjson" version = "0.1.0" authors = ["Gavrie Philipson "] edition = "2018" diff --git a/LICENSE b/LICENSE index 1d4b62a..6be613f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ - RedisDoc Licensing + RedisJSON Licensing Copyright 2018-2019 Redis Labs Ltd. and Contributors. Licensed under the Apache License, Version 2.0 (the "License") modified with Commons Clause diff --git a/README.md b/README.md index 4a4ecf2..4c335ce 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# RedisDoc \ No newline at end of file +# RedisJSON \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 802f75d..74a8fa7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,40 +4,41 @@ extern crate redismodule; use redismodule::{Context, RedisResult, NextArg}; use redismodule::native_types::RedisType; -mod redisdoc; +mod redisjson; -use crate::redisdoc::RedisDoc; +use crate::redisjson::RedisJSON; -static DOC_REDIS_TYPE: RedisType = RedisType::new("RedisDoc1"); +static REDIS_JSON_TYPE: RedisType = RedisType::new("RedisJSON"); + +fn json_set(ctx: &Context, args: Vec) -> RedisResult { -fn doc_set(ctx: &Context, args: Vec) -> RedisResult { let mut args = args.into_iter().skip(1); let key = args.next_string()?; - let value = args.next_string()?; + let value = args.next_string()?; let key = ctx.open_key_writable(&key); - match key.get_value::(&DOC_REDIS_TYPE)? { + match key.get_value::(&REDIS_JSON_TYPE)? { Some(doc) => { doc.set_value(&value)?; } None => { - let doc = RedisDoc::from_str(&value)?; - key.set_value(&DOC_REDIS_TYPE, doc)?; + let doc = RedisJSON::from_str(&value)?; + key.set_value(&REDIS_JSON_TYPE, doc)?; } } Ok(().into()) } -fn doc_get(ctx: &Context, args: Vec) -> RedisResult { +fn json_get(ctx: &Context, args: Vec) -> RedisResult { let mut args = args.into_iter().skip(1); let key = args.next_string()?; let key = ctx.open_key_writable(&key); - let value = match key.get_value::(&DOC_REDIS_TYPE)? { + let value = match key.get_value::(&REDIS_JSON_TYPE)? { Some(doc) => { doc.to_string()?.into() } None => ().into() }; @@ -48,13 +49,13 @@ fn doc_get(ctx: &Context, args: Vec) -> RedisResult { ////////////////////////////////////////////////////// redis_module! { - name: "redisdoc", + name: "redisjson", version: 1, data_types: [ - DOC_REDIS_TYPE, + REDIS_JSON_TYPE, ], commands: [ - ["doc.set", doc_set, "write"], - ["doc.get", doc_get, ""], + ["json.set", json_set, "write"], + ["json.get", json_get, ""], ], } diff --git a/src/redisdoc.rs b/src/redisjson.rs similarity index 95% rename from src/redisdoc.rs rename to src/redisjson.rs index 679d7e6..d6e2d9b 100644 --- a/src/redisdoc.rs +++ b/src/redisjson.rs @@ -1,4 +1,4 @@ -// ReDoc Redis module. +// RedisJSON Redis module. // // Translate between JSON and tree of Redis objects: // User-provided JSON is converted to a tree. This tree is stored transparently in Redis. @@ -23,11 +23,11 @@ impl From for redismodule::RedisError { } #[derive(Debug)] -pub struct RedisDoc { +pub struct RedisJSON { data: Value, } -impl RedisDoc { +impl RedisJSON { pub fn from_str(data: &str) -> Result { eprintln!("Parsing JSON from input '{}'", data);