Skip to content
This repository was archived by the owner on Apr 20, 2020. It is now read-only.

Commit cf410d7

Browse files
committed
fix review comments
1 parent ea87266 commit cf410d7

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[macro_use]
22
extern crate redismodule;
33

4-
use redismodule::{Context, RedisResult, NextArg, RedisValue};
4+
use redismodule::{Context, RedisResult, NextArg};
55
use redismodule::native_types::RedisType;
66

77
mod redisjson;
@@ -55,7 +55,7 @@ fn json_strlen(ctx: &Context, args: Vec<String>) -> RedisResult {
5555
let key = ctx.open_key_writable(&key);
5656

5757
let length = match key.get_value::<RedisJSON>(&REDIS_JSON_TYPE)? {
58-
Some(doc) => RedisValue::Integer(doc.str_len(&path)? as i64),
58+
Some(doc) => doc.str_len(&path)?.into(),
5959
None => ().into()
6060
};
6161

src/redisjson.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,7 @@ impl RedisJSON {
6262

6363
pub fn str_len(&self, path: &str) -> Result<usize, Error> {
6464
let s = match self.get_doc(path)? {
65-
Some(doc) => {
66-
if doc.is_string() {
67-
serde_json::to_string(&doc)?.len() - 2 // removes ""
68-
} else {
69-
0 // the value is not a String
70-
}
71-
}
65+
Some(doc) => doc.as_str().map_or(0, |d| d.len()),
7266
None => 0 // path not found
7367
};
7468
Ok(s)

0 commit comments

Comments
 (0)